1
1
import { parse } from "@conform-to/zod" ;
2
2
import { ActionFunction , json } from "@remix-run/node" ;
3
3
import { z } from "zod" ;
4
- import { redirectBackWithErrorMessage , redirectWithSuccessMessage } from "~/models/message.server" ;
4
+ import {
5
+ redirectBackWithErrorMessage ,
6
+ redirectWithErrorMessage ,
7
+ redirectWithSuccessMessage ,
8
+ } from "~/models/message.server" ;
5
9
import { ContinueRunService } from "~/services/runs/continueRun.server" ;
6
10
import { ReRunService } from "~/services/runs/reRun.server" ;
11
+ import { rootPath , runPath } from "~/utils/pathBuilder" ;
7
12
8
13
export const schema = z . object ( {
9
14
successRedirect : z . string ( ) ,
15
+ failureRedirect : z . string ( ) ,
10
16
} ) ;
11
17
12
18
const ParamSchema = z . object ( {
@@ -19,8 +25,14 @@ export const action: ActionFunction = async ({ request, params }) => {
19
25
const formData = await request . formData ( ) ;
20
26
const submission = parse ( formData , { schema } ) ;
21
27
28
+ console . log ( submission ) ;
29
+
22
30
if ( ! submission . value ) {
23
- return json ( submission ) ;
31
+ return redirectWithErrorMessage (
32
+ rootPath ( ) ,
33
+ request ,
34
+ submission . error ? JSON . stringify ( submission . error ) : "Invalid form"
35
+ ) ;
24
36
}
25
37
26
38
try {
@@ -29,7 +41,11 @@ export const action: ActionFunction = async ({ request, params }) => {
29
41
const run = await rerunService . call ( { runId } ) ;
30
42
31
43
if ( ! run ) {
32
- return redirectBackWithErrorMessage ( request , "Unable to retry run" ) ;
44
+ return redirectWithErrorMessage (
45
+ submission . value . failureRedirect ,
46
+ request ,
47
+ "Unable to retry run"
48
+ ) ;
33
49
}
34
50
35
51
return redirectWithSuccessMessage (
@@ -48,6 +64,10 @@ export const action: ActionFunction = async ({ request, params }) => {
48
64
) ;
49
65
}
50
66
} catch ( error : any ) {
51
- return json ( { errors : { body : error . message } } , { status : 400 } ) ;
67
+ return redirectWithErrorMessage (
68
+ submission . value . failureRedirect ,
69
+ request ,
70
+ error instanceof Error ? error . message : JSON . stringify ( error )
71
+ ) ;
52
72
}
53
73
} ;
0 commit comments