@@ -132,7 +132,7 @@ const PassengerShowcaseForm = () => {
132132 video : location . state ?. video ?? ''
133133 } ) ;
134134 const [ error , setError ] = useState ( null ) ;
135- const [ submitted , setSubmitted ] = useState ( false ) ;
135+ const [ submitted , setSubmitted ] = useState ( 'not-submitted' ) ; // not-submitted, waiting, submitted
136136
137137 const data = useVideosWithShowcase ( ) ;
138138
@@ -158,12 +158,14 @@ const PassengerShowcaseForm = () => {
158158
159159 const onSubmit = async ( e ) => {
160160 e . preventDefault ( ) ;
161+ setSubmitted ( 'waiting' ) ;
161162
162163 // Check that everything has been filled out
163164 try {
164165 await schema . validate ( state , { strict : true } ) ;
165166 } catch ( e ) {
166167 setError ( e . toString ( ) . replace ( 'ValidationError: ' , '' ) ) ;
168+ setSubmitted ( 'not-submitted' ) ;
167169 return ;
168170 }
169171
@@ -176,6 +178,7 @@ const PassengerShowcaseForm = () => {
176178 setError (
177179 'The uploaded image is larger than 500kb. Please upload a JPG or PNG that is maximum 800 pixels wide and 500kb in size.'
178180 ) ;
181+ setSubmitted ( 'not-submitted' ) ;
179182 return ;
180183 }
181184
@@ -199,22 +202,25 @@ const PassengerShowcaseForm = () => {
199202 } ) ;
200203 const json = await response . json ( ) ;
201204 if ( response . ok ) {
202- setSubmitted ( true ) ;
205+ setSubmitted ( 'submitted' ) ;
203206 setState ( defaultState ) ;
204207 } else {
205208 setError (
206209 json . error ||
207210 'Oh no! The train broke down. Please contact help@thecodingtrain.com to report the malfunction!'
208211 ) ;
212+ setSubmitted ( 'not-submitted' ) ;
209213 }
210214 } catch ( e ) {
211215 setError (
212216 'Oh no! The train broke down. Please contact help@thecodingtrain.com to report the malfunction!'
213217 ) ;
218+ setSubmitted ( 'not-submitted' ) ;
214219 }
215220 } ;
216221 reader . onerror = function ( error ) {
217222 setError ( 'Something went wrong parsing your image.' ) ;
223+ setSubmitted ( 'not-submitted' ) ;
218224 } ;
219225 } ;
220226
@@ -419,7 +425,7 @@ const PassengerShowcaseForm = () => {
419425 </ span >
420426 </ label >
421427 { error && < div className = { css . error } > { error } </ div > }
422- { submitted && (
428+ { submitted === 'submitted' && (
423429 < div className = { css . submitted } >
424430 Thank you for submitting to the Passenger Showcase! Please refresh
425431 the page in order to upload another submission.
@@ -429,7 +435,7 @@ const PassengerShowcaseForm = () => {
429435 className = { css . submitBtn }
430436 onClick = { onSubmit }
431437 variant = "purple"
432- disabled = { submitted }
438+ disabled = { submitted !== 'not-submitted' }
433439 rainbow >
434440 Submit
435441 </ Button >
0 commit comments