From 84a679b0e48ed76eee2fa44d3caac83591aa3c8c Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Mon, 30 Oct 2023 11:18:11 +0100
Subject: feat(hooks): add useBoolean and useToggle hooks

---
 .../organisms/forms/comment-form/comment-form.tsx       | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

(limited to 'src/components/organisms/forms/comment-form/comment-form.tsx')

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 (
-- 
cgit v1.2.3

