Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve problem when mutation is called multiples times #24

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/eo_web/dist/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"css": [
"assets/main-b2263767.css"
],
"file": "assets/main-82e41967.js",
"file": "assets/main-0ca378d6.js",
"isEntry": true,
"src": "src/main.tsx"
}
Expand Down
13 changes: 13 additions & 0 deletions apps/eo_web/src/hooks/useMount.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useEffect, useRef } from "react";

export const useMount = (fn: () => void) => {
const onceFlag = useRef(true);

useEffect(() => {
if (onceFlag.current) {
onceFlag.current = false;
fn();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
};
9 changes: 4 additions & 5 deletions apps/eo_web/src/screens/Cancer/CancerThankYou.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useEffect } from "react";
import { useMutation } from "@tanstack/react-query";
import axios from "axios";
import { useNavigate, useSearchParams } from "react-router-dom";
Expand All @@ -7,6 +6,7 @@ import { toast } from "react-toastify";
import { Typography } from "@eo/ui";

import { useElixirApi } from "~/api/useElixirApi";
import { useMount } from "~/hooks/useMount";
import { LayoutDefault } from "~/layouts";
import { ROUTES } from "~/router";

Expand All @@ -28,7 +28,8 @@ export const CancerThankYou = () => {
const { postCancerFormSubmission } = useElixirApi();

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

useEffect(() => {
mutate();
}, []);
useMount(() => mutate({ submission_id }));

return (
<LayoutDefault>
Expand Down