Skip to content

Commit 3d107b7

Browse files
authored
Merge pull request #1605 from CodingTrain/showcase-waiting
Add waiting state to showcase form
2 parents 324b7e4 + c0d04fa commit 3d107b7

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

Diff for: src/components/Button.module.css

+10-5
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,16 @@ button.rainbow.cyan {
137137
transition: background-position 1s ease-out;
138138
}
139139

140-
.rainbow.red:hover,
141-
.rainbow.orange:hover,
142-
.rainbow.purple:hover,
143-
.rainbow.pink:hover,
144-
.rainbow.cyan:hover {
140+
.rainbow.red:hover:not([disabled]),
141+
.rainbow.orange:hover:not([disabled]),
142+
.rainbow.purple:hover:not([disabled]),
143+
.rainbow.pink:hover:not([disabled]),
144+
.rainbow.cyan:hover:not([disabled]) {
145145
background-position: left bottom;
146146
transition: background-position 4s ease-out;
147147
}
148+
149+
button[disabled] {
150+
opacity: 0.5;
151+
cursor: not-allowed;
152+
}

Diff for: src/components/PassengerShowcaseForm.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -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 [email protected] to report the malfunction!'
208211
);
212+
setSubmitted('not-submitted');
209213
}
210214
} catch (e) {
211215
setError(
212216
'Oh no! The train broke down. Please contact [email protected] 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>

Diff for: src/components/PassengerShowcaseForm.module.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@
6464
}
6565
}
6666

67-
.submitBtn:hover {
67+
.submitBtn:hover:not([disabled]) {
6868
cursor: pointer;
6969
}

0 commit comments

Comments
 (0)