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" ;
1111import { SlackIcon } from "@trigger.dev/companyicons" ;
12- import { Fragment , useRef , useState } from "react" ;
12+ import { Fragment , useEffect , useRef , useState } from "react" ;
1313import { z } from "zod" ;
1414import { Button , LinkButton } from "~/components/primitives/Buttons" ;
1515import { 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