Skip to content

Commit

Permalink
fix: resolve problem when mutation is called multiples times
Browse files Browse the repository at this point in the history
  • Loading branch information
cgarcia-lightit committed Aug 11, 2023
1 parent 08db033 commit 1a4ac0c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions apps/eo_web/src/screens/Cancer/CancerThankYou.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { useMutation } from "@tanstack/react-query";
import axios from "axios";
import { useNavigate, useSearchParams } from "react-router-dom";
Expand All @@ -25,10 +25,13 @@ export const CancerThankYou = () => {
navigate(ROUTES.cancerProfile);
}

const [callApi, setCallApi] = useState(true);

const { postCancerFormSubmission } = useElixirApi();

const { mutate } = useMutation({
mutationFn: () => postCancerFormSubmission({ submission_id }),
mutationKey: ["postCancerFormSubmission", submission_id],
onError: (result) => {
if (axios.isAxiosError(result)) {
if (result.response?.status !== 200) {
Expand All @@ -41,8 +44,15 @@ export const CancerThankYou = () => {
});

useEffect(() => {
mutate();
}, []);
if (callApi) {
setCallApi((prevState) => {
if (prevState) {
mutate();
}
return false;
});
}
}, [mutate]);

return (
<LayoutDefault>
Expand Down

0 comments on commit 1a4ac0c

Please sign in to comment.