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/comment-form | |
| parent | 60c49f18389ff625177a57277ef8f292a31097bf (diff) | |
feat(hooks): add useBoolean and useToggle hooks
Diffstat (limited to 'src/components/organisms/forms/comment-form')
| -rw-r--r-- | src/components/organisms/forms/comment-form/comment-form.tsx | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/components/organisms/forms/comment-form/comment-form.tsx b/src/components/organisms/forms/comment-form/comment-form.tsx index b5f2d64..9059cbc 100644 --- a/src/components/organisms/forms/comment-form/comment-form.tsx +++ b/src/components/organisms/forms/comment-form/comment-form.tsx @@ -10,6 +10,7 @@ import { useId, } from 'react'; import { useIntl } from 'react-intl'; +import { useBoolean } from '../../../../utils/hooks'; import { Button, Form, @@ -77,15 +78,19 @@ export const CommentForm: FC<CommentFormProps> = ({ }; }, [parentId]); 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 nameLabel = intl.formatMessage({ defaultMessage: 'Name:', @@ -160,10 +165,10 @@ export const CommentForm: FC<CommentFormProps> = ({ const sendForm = useCallback( (e: FormEvent) => { e.preventDefault(); - setIsSubmitting(true); - saveComment(data, resetForm).then(() => setIsSubmitting(false)); + activateNotice(); + saveComment(data, resetForm).then(() => deactivateNotice()); }, - [data, resetForm, saveComment] + [activateNotice, data, deactivateNotice, resetForm, saveComment] ); return ( |
