diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-10-30 11:18:11 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:15:27 +0100 |
| commit | 84a679b0e48ed76eee2fa44d3caac83591aa3c8c (patch) | |
| tree | 1d418a6c514ff8a04b84ba35c98736e8450f968c /src/components/organisms/forms/contact-form/contact-form.tsx | |
| parent | 60c49f18389ff625177a57277ef8f292a31097bf (diff) | |
feat(hooks): add useBoolean and useToggle hooks
Diffstat (limited to 'src/components/organisms/forms/contact-form/contact-form.tsx')
| -rw-r--r-- | src/components/organisms/forms/contact-form/contact-form.tsx | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/components/organisms/forms/contact-form/contact-form.tsx b/src/components/organisms/forms/contact-form/contact-form.tsx index 89fd331..ed23aad 100644 --- a/src/components/organisms/forms/contact-form/contact-form.tsx +++ b/src/components/organisms/forms/contact-form/contact-form.tsx @@ -9,6 +9,7 @@ import { useMemo, } from 'react'; import { useIntl } from 'react-intl'; +import { useBoolean } from '../../../../utils/hooks'; import { Button, Form, Input, Label, Spinner, TextArea } from '../../../atoms'; import { LabelledField } from '../../../molecules'; import styles from './contact-form.module.scss'; @@ -56,15 +57,19 @@ export const ContactForm: FC<ContactFormProps> = ({ }; }, []); const [data, setData] = useState(emptyForm); - const [isSubmitting, setIsSubmitting] = useState<boolean>(false); + const { + activate: activateNotice, + deactivate: deactivateNotice, + state: isSubmitting, + } = useBoolean(false); /** * Reset all the form fields. */ const resetForm = useCallback(() => { setData(emptyForm); - setIsSubmitting(false); - }, [emptyForm]); + deactivateNotice(); + }, [deactivateNotice, emptyForm]); const updateForm = useCallback( (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => { @@ -135,10 +140,10 @@ export const ContactForm: FC<ContactFormProps> = ({ const submitHandler = useCallback( async (e: FormEvent) => { e.preventDefault(); - setIsSubmitting(true); - await sendMail(data, resetForm).then(() => setIsSubmitting(false)); + activateNotice(); + await sendMail(data, resetForm).then(() => deactivateNotice()); }, - [data, resetForm, sendMail] + [activateNotice, data, deactivateNotice, resetForm, sendMail] ); return ( |
