@@ -46,51 +46,50 @@ function Form({ questions = [], role = "" }) {
46
46
47
47
48
48
const handleSubmit = async ( e ) => {
49
- console . log ( "formData" , formData ) ;
50
- console . log ( "role" , role ) ;
51
- console . log ( "Is form valid?" , validateForm ( ) ) ;
52
-
53
-
54
49
e . preventDefault ( ) ;
55
50
if ( ! validateForm ( ) ) {
56
- return ;
57
- console . log ( "Is form valid?" , validateForm ( ) ) ;
51
+ return ;
52
+ }
58
53
59
- }
60
54
try {
61
- const response = await fetch ( " /api/slack" , {
62
- method : " POST" ,
55
+ const response = await fetch ( ' /api/slack' , {
56
+ method : ' POST' ,
63
57
headers : {
64
- " Content-Type" : " application/json" ,
58
+ ' Content-Type' : ' application/json' ,
65
59
} ,
66
60
body : JSON . stringify ( { formData, role } ) ,
67
61
} ) ;
68
62
69
63
if ( response . ok ) {
70
64
toast ( {
71
- title : " Success" ,
72
- description : " Successfully sent message to Slack" ,
73
- status : " success" ,
65
+ title : ' Success' ,
66
+ description : ' Successfully sent your application for review.' ,
67
+ status : ' success' ,
74
68
duration : 5000 ,
75
69
isClosable : true ,
76
70
} ) ;
77
71
setFormData ( { } ) ;
78
72
} else {
79
- const { error } = await response . json ( ) ;
73
+ let error ;
74
+ try {
75
+ error = await response . json ( ) ;
76
+ } catch ( e ) {
77
+ error = await response . text ( ) ;
78
+ }
80
79
toast ( {
81
- title : " Error" ,
80
+ title : ' Error' ,
82
81
description : error ,
83
- status : " error" ,
82
+ status : ' error' ,
84
83
duration : 5000 ,
85
84
isClosable : true ,
86
85
} ) ;
87
86
}
88
87
} catch ( error ) {
89
- console . error ( " There was an error sending the form data to Slack" , error ) ;
88
+ console . error ( ' There was an error sending the form data to Slack' , error ) ;
90
89
toast ( {
91
- title : " Error" ,
92
- description : " An error occurred while processing your request." ,
93
- status : " error" ,
90
+ title : ' Error' ,
91
+ description : ' An error occurred while processing your request.' ,
92
+ status : ' error' ,
94
93
duration : 5000 ,
95
94
isClosable : true ,
96
95
} ) ;
0 commit comments