Skip to content

Commit 3e328e4

Browse files
committed
prevent redirect after form submission
1 parent 6eda63a commit 3e328e4

File tree

1 file changed

+23
-7
lines changed
  • apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.errors.$fingerprint

1 file changed

+23
-7
lines changed

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.errors.$fingerprint/route.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type LoaderFunctionArgs, type ActionFunctionArgs, json } from "@remix-run/server-runtime";
2-
import { type MetaFunction, Form, useNavigation, useSubmit } from "@remix-run/react";
2+
import { type MetaFunction, useFetcher, useRevalidator } from "@remix-run/react";
33
import { BellAlertIcon } from "@heroicons/react/20/solid";
44
import { IconAlarmSnooze as IconAlarmSnoozeBase, IconCircleDotted } from "@tabler/icons-react";
55
import { parse } from "@conform-to/zod";
@@ -35,7 +35,7 @@ import {
3535
ResizablePanelGroup,
3636
} from "~/components/primitives/Resizable";
3737
import { AnimatePresence, motion } from "framer-motion";
38-
import { Suspense, useMemo, useState } from "react";
38+
import { Suspense, useEffect, useMemo, useRef, useState } from "react";
3939
import { Spinner } from "~/components/primitives/Spinner";
4040
import { Paragraph } from "~/components/primitives/Paragraph";
4141
import { Callout } from "~/components/primitives/Callout";
@@ -76,7 +76,12 @@ import { CodeBlock } from "~/components/code/CodeBlock";
7676

7777
import { Popover, PopoverArrowTrigger, PopoverContent } from "~/components/primitives/Popover";
7878
import { ErrorGroupActions } from "~/v3/services/errorGroupActions.server";
79-
import { ErrorStatusMenuItems, CustomIgnoreDialog } from "~/components/errors/ErrorStatusMenu";
79+
import {
80+
ErrorStatusMenuItems,
81+
CustomIgnoreDialog,
82+
ignoreActionToastMessage,
83+
} from "~/components/errors/ErrorStatusMenu";
84+
import { useToast } from "~/components/primitives/Toast";
8085

8186
export const meta: MetaFunction<typeof loader> = ({ data }) => {
8287
return [
@@ -729,15 +734,26 @@ function ErrorStatusDropdown({
729734
state: ErrorGroupState;
730735
taskIdentifier: string;
731736
}) {
732-
const submit = useSubmit();
733-
const navigation = useNavigation();
737+
const fetcher = useFetcher<{ ok?: boolean }>();
738+
const revalidator = useRevalidator();
734739
const [popoverOpen, setPopoverOpen] = useState(false);
735740
const [customIgnoreOpen, setCustomIgnoreOpen] = useState(false);
736-
const isSubmitting = navigation.state !== "idle";
741+
const isSubmitting = fetcher.state !== "idle";
742+
const toast = useToast();
743+
const pendingToast = useRef<string | undefined>();
744+
745+
useEffect(() => {
746+
if (fetcher.state === "idle" && fetcher.data?.ok && pendingToast.current) {
747+
toast.success(pendingToast.current);
748+
pendingToast.current = undefined;
749+
revalidator.revalidate();
750+
}
751+
}, [fetcher.state, fetcher.data, toast, revalidator]);
737752

738753
const act = (data: Record<string, string>) => {
739754
setPopoverOpen(false);
740-
submit(data, { method: "post" });
755+
pendingToast.current = ignoreActionToastMessage(data);
756+
fetcher.submit(data, { method: "post" });
741757
};
742758

743759
return (

0 commit comments

Comments
 (0)