@@ -4,10 +4,11 @@ import {
44 IconArrowBackUp as IconArrowBackUpBase ,
55 IconBugOff as IconBugOffBase ,
66} from "@tabler/icons-react" ;
7- import { useState } from "react" ;
7+ import { useEffect , useRef , useState } from "react" ;
88import { type ErrorGroupStatus } from "@trigger.dev/database" ;
9- import { Form , useNavigation , useSubmit } from "@remix-run/react" ;
9+ import { useFetcher } from "@remix-run/react" ;
1010import { Button } from "~/components/primitives/Buttons" ;
11+ import { useToast } from "~/components/primitives/Toast" ;
1112import { FormError } from "~/components/primitives/FormError" ;
1213import { Input } from "~/components/primitives/Input" ;
1314import { InputGroup } from "~/components/primitives/InputGroup" ;
@@ -31,6 +32,18 @@ const BugOffIcon = ({ className }: { className?: string }) => (
3132 < IconBugOffBase className = { className } size = { 18 } />
3233) ;
3334
35+ export function ignoreActionToastMessage ( data : Record < string , string > ) : string | undefined {
36+ if ( data . action !== "ignore" ) return undefined ;
37+
38+ const duration = data . duration ? Number ( data . duration ) : undefined ;
39+ if ( ! duration ) return "Error ignored indefinitely" ;
40+
41+ const hours = duration / ( 60 * 60 * 1000 ) ;
42+ if ( hours < 24 ) return `Error ignored for ${ hours } ${ hours === 1 ? "hour" : "hours" } ` ;
43+ const days = hours / 24 ;
44+ return `Error ignored for ${ days } ${ days === 1 ? "day" : "days" } ` ;
45+ }
46+
3447export function ErrorStatusMenuItems ( {
3548 status,
3649 taskIdentifier,
@@ -131,10 +144,19 @@ export function CustomIgnoreDialog({
131144 taskIdentifier : string ;
132145 formAction ?: string ;
133146} ) {
134- const submit = useSubmit ( ) ;
135- const navigation = useNavigation ( ) ;
136- const isSubmitting = navigation . state !== "idle" ;
147+ const fetcher = useFetcher < { ok ?: boolean } > ( ) ;
148+ const isSubmitting = fetcher . state !== "idle" ;
137149 const [ conditionError , setConditionError ] = useState < string | null > ( null ) ;
150+ const toast = useToast ( ) ;
151+ const hasHandledSuccess = useRef ( false ) ;
152+
153+ useEffect ( ( ) => {
154+ if ( fetcher . state === "idle" && fetcher . data ?. ok && ! hasHandledSuccess . current ) {
155+ hasHandledSuccess . current = true ;
156+ toast . success ( "Error ignored with custom condition" ) ;
157+ onOpenChange ( false ) ;
158+ }
159+ } , [ fetcher . state , fetcher . data , onOpenChange , toast ] ) ;
138160
139161 return (
140162 < Dialog open = { open } onOpenChange = { onOpenChange } >
@@ -145,7 +167,7 @@ export function CustomIgnoreDialog({
145167 Custom ignore condition
146168 </ DialogTitle >
147169 </ DialogHeader >
148- < Form
170+ < fetcher . Form
149171 method = "post"
150172 action = { formAction }
151173 onSubmit = { ( e ) => {
@@ -160,8 +182,8 @@ export function CustomIgnoreDialog({
160182 }
161183
162184 setConditionError ( null ) ;
163- submit ( e . currentTarget , { method : "post" , action : formAction } ) ;
164- setTimeout ( ( ) => onOpenChange ( false ) , 100 ) ;
185+ hasHandledSuccess . current = false ;
186+ fetcher . submit ( e . currentTarget , { method : "post" , action : formAction } ) ;
165187 } }
166188 >
167189 < input type = "hidden" name = "action" value = "ignore" />
@@ -214,7 +236,7 @@ export function CustomIgnoreDialog({
214236 { isSubmitting ? "Ignoring…" : "Ignore error" }
215237 </ Button >
216238 </ DialogFooter >
217- </ Form >
239+ </ fetcher . Form >
218240 </ DialogContent >
219241 </ Dialog >
220242 ) ;
0 commit comments