Skip to content

Commit

Permalink
add waiting state to form
Browse files Browse the repository at this point in the history
  • Loading branch information
dipamsen committed May 19, 2024
1 parent 9692de7 commit c0d04fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
15 changes: 10 additions & 5 deletions src/components/Button.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,16 @@ button.rainbow.cyan {
transition: background-position 1s ease-out;
}

.rainbow.red:hover,
.rainbow.orange:hover,
.rainbow.purple:hover,
.rainbow.pink:hover,
.rainbow.cyan:hover {
.rainbow.red:hover:not([disabled]),
.rainbow.orange:hover:not([disabled]),
.rainbow.purple:hover:not([disabled]),
.rainbow.pink:hover:not([disabled]),
.rainbow.cyan:hover:not([disabled]) {
background-position: left bottom;
transition: background-position 4s ease-out;
}

button[disabled] {
opacity: 0.5;
cursor: not-allowed;
}
14 changes: 10 additions & 4 deletions src/components/PassengerShowcaseForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const PassengerShowcaseForm = () => {
video: location.state?.video ?? ''
});
const [error, setError] = useState(null);
const [submitted, setSubmitted] = useState(false);
const [submitted, setSubmitted] = useState('not-submitted'); // not-submitted, waiting, submitted

const data = useVideosWithShowcase();

Expand All @@ -158,12 +158,14 @@ const PassengerShowcaseForm = () => {

const onSubmit = async (e) => {
e.preventDefault();
setSubmitted('waiting');

// Check that everything has been filled out
try {
await schema.validate(state, { strict: true });
} catch (e) {
setError(e.toString().replace('ValidationError: ', ''));
setSubmitted('not-submitted');
return;
}

Expand All @@ -176,6 +178,7 @@ const PassengerShowcaseForm = () => {
setError(
'The uploaded image is larger than 500kb. Please upload a JPG or PNG that is maximum 800 pixels wide and 500kb in size.'
);
setSubmitted('not-submitted');
return;
}

Expand All @@ -199,22 +202,25 @@ const PassengerShowcaseForm = () => {
});
const json = await response.json();
if (response.ok) {
setSubmitted(true);
setSubmitted('submitted');
setState(defaultState);
} else {
setError(
json.error ||
'Oh no! The train broke down. Please contact [email protected] to report the malfunction!'
);
setSubmitted('not-submitted');
}
} catch (e) {
setError(
'Oh no! The train broke down. Please contact [email protected] to report the malfunction!'
);
setSubmitted('not-submitted');
}
};
reader.onerror = function (error) {
setError('Something went wrong parsing your image.');
setSubmitted('not-submitted');
};
};

Expand Down Expand Up @@ -419,7 +425,7 @@ const PassengerShowcaseForm = () => {
</span>
</label>
{error && <div className={css.error}>{error}</div>}
{submitted && (
{submitted === 'submitted' && (
<div className={css.submitted}>
Thank you for submitting to the Passenger Showcase! Please refresh
the page in order to upload another submission.
Expand All @@ -429,7 +435,7 @@ const PassengerShowcaseForm = () => {
className={css.submitBtn}
onClick={onSubmit}
variant="purple"
disabled={submitted}
disabled={submitted !== 'not-submitted'}
rainbow>
Submit
</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/components/PassengerShowcaseForm.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@
}
}

.submitBtn:hover {
.submitBtn:hover:not([disabled]) {
cursor: pointer;
}

0 comments on commit c0d04fa

Please sign in to comment.