Skip to content

Commit

Permalink
refactor: add loading state while submitting birth date
Browse files Browse the repository at this point in the history
  • Loading branch information
nzambello committed Dec 22, 2023
1 parent 26617a1 commit 8c082ee
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/components/AgeVerificationModal/AgeVerificationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ const AgeVerificationModal = ({ visible = false, onClose, minAge }: Props) => {

const [birthDate, setBirthDate] = useState<DateTime>();
const [error, setError] = useState<string>();
const [submitting, setSubmitting] = useState<boolean>(false);

const onSubmit = useCallback(() => {
setSubmitting(true);

if (!birthDate) {
toast.error(t('requiredField'));
setError(t('requiredField') || 'Required field');
setSubmitting(false);
return;
}

Expand All @@ -32,6 +36,7 @@ const AgeVerificationModal = ({ visible = false, onClose, minAge }: Props) => {
t('underageTwinSession', { age: minAge }) ||
`You must be at least ${minAge} years old to interact with this Twin`
);
setSubmitting(false);
return;
}

Expand Down Expand Up @@ -76,6 +81,7 @@ const AgeVerificationModal = ({ visible = false, onClose, minAge }: Props) => {
primary
htmlType="submit"
className="age-verification-submit"
loading={submitting}
disabled={!birthDate}
>
{t('confirm')}
Expand Down

0 comments on commit 8c082ee

Please sign in to comment.