Skip to content

Commit ea3dda7

Browse files
committed
Configuring alerts better loading state and close panel when done
1 parent 9e79054 commit ea3dda7

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

apps/webapp/app/components/errors/ConfigureErrorAlerts.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {
77
LockClosedIcon,
88
XMarkIcon,
99
} from "@heroicons/react/20/solid";
10-
import { useFetcher } from "@remix-run/react";
10+
import { useFetcher, useNavigate } from "@remix-run/react";
1111
import { SlackIcon } from "@trigger.dev/companyicons";
12-
import { Fragment, useRef, useState } from "react";
12+
import { Fragment, useEffect, useRef, useState } from "react";
1313
import { z } from "zod";
1414
import { Button, LinkButton } from "~/components/primitives/Buttons";
1515
import { Callout, variantClasses } from "~/components/primitives/Callout";
@@ -55,7 +55,8 @@ export function ConfigureErrorAlerts({
5555
emailAlertsEnabled,
5656
connectToSlackHref,
5757
}: ConfigureErrorAlertsProps) {
58-
const fetcher = useFetcher();
58+
const fetcher = useFetcher<{ ok?: boolean }>();
59+
const navigate = useNavigate();
5960
const location = useOptimisticLocation();
6061
const isSubmitting = fetcher.state !== "idle";
6162

@@ -77,6 +78,12 @@ export function ConfigureErrorAlerts({
7778
return qs ? `?${qs}` : location.pathname;
7879
})();
7980

81+
useEffect(() => {
82+
if (fetcher.state === "idle" && fetcher.data?.ok) {
83+
navigate(closeHref, { replace: true });
84+
}
85+
}, [fetcher.state, fetcher.data, closeHref, navigate]);
86+
8087
const emailFieldValues = useRef<string[]>(
8188
existingEmails.length > 0 ? [...existingEmails.map((e) => e.email), ""] : [""]
8289
);
@@ -313,6 +320,7 @@ export function ConfigureErrorAlerts({
313320
type="submit"
314321
form="configure-error-alerts"
315322
disabled={isSubmitting}
323+
isLoading={isSubmitting}
316324
fullWidth
317325
>
318326
{isSubmitting ? "Saving…" : "Save"}

0 commit comments

Comments
 (0)