@@ -132,7 +132,7 @@ const PassengerShowcaseForm = () => {
132
132
video : location . state ?. video ?? ''
133
133
} ) ;
134
134
const [ error , setError ] = useState ( null ) ;
135
- const [ submitted , setSubmitted ] = useState ( false ) ;
135
+ const [ submitted , setSubmitted ] = useState ( 'not-submitted' ) ; // not-submitted, waiting, submitted
136
136
137
137
const data = useVideosWithShowcase ( ) ;
138
138
@@ -158,12 +158,14 @@ const PassengerShowcaseForm = () => {
158
158
159
159
const onSubmit = async ( e ) => {
160
160
e . preventDefault ( ) ;
161
+ setSubmitted ( 'waiting' ) ;
161
162
162
163
// Check that everything has been filled out
163
164
try {
164
165
await schema . validate ( state , { strict : true } ) ;
165
166
} catch ( e ) {
166
167
setError ( e . toString ( ) . replace ( 'ValidationError: ' , '' ) ) ;
168
+ setSubmitted ( 'not-submitted' ) ;
167
169
return ;
168
170
}
169
171
@@ -176,6 +178,7 @@ const PassengerShowcaseForm = () => {
176
178
setError (
177
179
'The uploaded image is larger than 500kb. Please upload a JPG or PNG that is maximum 800 pixels wide and 500kb in size.'
178
180
) ;
181
+ setSubmitted ( 'not-submitted' ) ;
179
182
return ;
180
183
}
181
184
@@ -199,22 +202,25 @@ const PassengerShowcaseForm = () => {
199
202
} ) ;
200
203
const json = await response . json ( ) ;
201
204
if ( response . ok ) {
202
- setSubmitted ( true ) ;
205
+ setSubmitted ( 'submitted' ) ;
203
206
setState ( defaultState ) ;
204
207
} else {
205
208
setError (
206
209
json . error ||
207
210
'Oh no! The train broke down. Please contact [email protected] to report the malfunction!'
208
211
) ;
212
+ setSubmitted ( 'not-submitted' ) ;
209
213
}
210
214
} catch ( e ) {
211
215
setError (
212
216
'Oh no! The train broke down. Please contact [email protected] to report the malfunction!'
213
217
) ;
218
+ setSubmitted ( 'not-submitted' ) ;
214
219
}
215
220
} ;
216
221
reader . onerror = function ( error ) {
217
222
setError ( 'Something went wrong parsing your image.' ) ;
223
+ setSubmitted ( 'not-submitted' ) ;
218
224
} ;
219
225
} ;
220
226
@@ -419,7 +425,7 @@ const PassengerShowcaseForm = () => {
419
425
</ span >
420
426
</ label >
421
427
{ error && < div className = { css . error } > { error } </ div > }
422
- { submitted && (
428
+ { submitted === 'submitted' && (
423
429
< div className = { css . submitted } >
424
430
Thank you for submitting to the Passenger Showcase! Please refresh
425
431
the page in order to upload another submission.
@@ -429,7 +435,7 @@ const PassengerShowcaseForm = () => {
429
435
className = { css . submitBtn }
430
436
onClick = { onSubmit }
431
437
variant = "purple"
432
- disabled = { submitted }
438
+ disabled = { submitted !== 'not-submitted' }
433
439
rainbow >
434
440
Submit
435
441
</ Button >
0 commit comments