From d47e26ab5d87142b6d0e7feec91550df5fbfc7e2 Mon Sep 17 00:00:00 2001 From: Hassen ben amor Date: Sat, 2 Mar 2024 22:57:27 +0100 Subject: [PATCH 1/7] fix email-validation --- .../Homepage/ContactForm/ContactForm.jsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/components/Homepage/ContactForm/ContactForm.jsx b/src/components/Homepage/ContactForm/ContactForm.jsx index 030ee903..8c12982d 100644 --- a/src/components/Homepage/ContactForm/ContactForm.jsx +++ b/src/components/Homepage/ContactForm/ContactForm.jsx @@ -99,6 +99,13 @@ const ContactForm = () => { }); }; + + // Email validation function + const isValidEmail = (email) => { + const regexPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; // Simple email pattern + return regexPattern.test(email); + }; + const handleSubmit = (event) => { event.preventDefault(); setIsLoading(false); @@ -117,6 +124,13 @@ const ContactForm = () => { submissionFrom: "thecyberhub.org", }; + // Validate email + if (!isValidEmail(email)) { + setError("Please enter a valid email address"); + return; // Stop the form submission + } + + if (name.length === 0) { setError("Please add your name"); } else if (email.length === 0) { @@ -139,6 +153,7 @@ const ContactForm = () => { if (response.data.message === "Form submitted successfully") { setIsLoading(false); setIsSuccess(true); + setFormData({ name: "", email: "", From eaa48bbb3641d298b0d8c2e33096744d2402be58 Mon Sep 17 00:00:00 2001 From: Hassen ben amor Date: Mon, 4 Mar 2024 11:02:38 +0100 Subject: [PATCH 2/7] update --- .../Homepage/ContactForm/ContactForm.jsx | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/components/Homepage/ContactForm/ContactForm.jsx b/src/components/Homepage/ContactForm/ContactForm.jsx index 8c12982d..62ff550b 100644 --- a/src/components/Homepage/ContactForm/ContactForm.jsx +++ b/src/components/Homepage/ContactForm/ContactForm.jsx @@ -35,6 +35,7 @@ import apiStatus from "../../../features/apiStatus"; import { Wrapper } from "../../Dashboard/Profile/ProfileElements"; import UnderMaintenance from "../../Other/UnderMaintenance/UnderMaintenance"; import { volunteerPrograms } from "../../Opportunities/Volunteer/VolunteerData"; +import {validateEmail} from "../../../utils/validateEmail.js" const ContactForm = () => { const { isApiLoading, isApiWorking } = apiStatus(); @@ -100,12 +101,6 @@ const ContactForm = () => { }; - // Email validation function - const isValidEmail = (email) => { - const regexPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; // Simple email pattern - return regexPattern.test(email); - }; - const handleSubmit = (event) => { event.preventDefault(); setIsLoading(false); @@ -125,7 +120,7 @@ const ContactForm = () => { }; // Validate email - if (!isValidEmail(email)) { + if (!validateEmail(email)) { setError("Please enter a valid email address"); return; // Stop the form submission } @@ -153,8 +148,8 @@ const ContactForm = () => { if (response.data.message === "Form submitted successfully") { setIsLoading(false); setIsSuccess(true); - - setFormData({ + + setFormData({ name: "", email: "", reason: "", @@ -433,7 +428,7 @@ Including: Submit - ) : ( + ) : ( @@ -444,8 +439,8 @@ Including: {"Server Error - Please contact us on discord"} )} - {isSuccess && !error ? Submit Successfully : null} - + {isSuccess && !error ? Submit Successfully: null} + ); }; From 9fc90df441b4b3a75473292fee54b161c18cf7ca Mon Sep 17 00:00:00 2001 From: Hassen ben amor Date: Mon, 4 Mar 2024 11:07:33 +0100 Subject: [PATCH 3/7] add new sumbit button to reset --- .../Homepage/ContactForm/ContactForm.jsx | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/components/Homepage/ContactForm/ContactForm.jsx b/src/components/Homepage/ContactForm/ContactForm.jsx index 62ff550b..82a91687 100644 --- a/src/components/Homepage/ContactForm/ContactForm.jsx +++ b/src/components/Homepage/ContactForm/ContactForm.jsx @@ -35,7 +35,7 @@ import apiStatus from "../../../features/apiStatus"; import { Wrapper } from "../../Dashboard/Profile/ProfileElements"; import UnderMaintenance from "../../Other/UnderMaintenance/UnderMaintenance"; import { volunteerPrograms } from "../../Opportunities/Volunteer/VolunteerData"; -import {validateEmail} from "../../../utils/validateEmail.js" +import { validateEmail } from "../../../utils/validateEmail.js" const ContactForm = () => { const { isApiLoading, isApiWorking } = apiStatus(); @@ -63,6 +63,25 @@ const ContactForm = () => { const [isOpened, setIsOpened] = useState(false); const [isClosed, setIsClosed] = useState(false); + {/* */ } + + const resetForm = () => { + setFormData({ + name: "", + email: "", + reason: "", + reasonType: "", + contextHeading: "", + resume: "", + message: "", + isExperienced: "", + }); + setIsSuccess(false); + setIsLoading(false); + setError(false); + setError2(false); + }; + useEffect(() => { if (error || error2) { toast.error("Please fill all the fields"); @@ -119,11 +138,11 @@ const ContactForm = () => { submissionFrom: "thecyberhub.org", }; - // Validate email - if (!validateEmail(email)) { - setError("Please enter a valid email address"); - return; // Stop the form submission - } + // Validate email + if (!validateEmail(email)) { + setError("Please enter a valid email address"); + return; // Stop the form submission + } if (name.length === 0) { @@ -149,7 +168,7 @@ const ContactForm = () => { setIsLoading(false); setIsSuccess(true); - setFormData({ + setFormData({ name: "", email: "", reason: "", @@ -428,7 +447,7 @@ Including: Submit - ) : ( + ) : ( @@ -439,8 +458,19 @@ Including: {"Server Error - Please contact us on discord"} )} - {isSuccess && !error ? Submit Successfully: null} - + {isSuccess && !error ? + + +
+ Submit Successfully + {/* */} + +
+ + + : null} + + ); }; From a3daacfecdc7ddf6e5abbfe59e228f4f5a35214f Mon Sep 17 00:00:00 2001 From: Hassen ben amor Date: Tue, 5 Mar 2024 14:49:12 +0100 Subject: [PATCH 4/7] new toast notification added --- src/components/Homepage/ContactForm/ContactForm.jsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/Homepage/ContactForm/ContactForm.jsx b/src/components/Homepage/ContactForm/ContactForm.jsx index 82a91687..838840cc 100644 --- a/src/components/Homepage/ContactForm/ContactForm.jsx +++ b/src/components/Homepage/ContactForm/ContactForm.jsx @@ -63,7 +63,7 @@ const ContactForm = () => { const [isOpened, setIsOpened] = useState(false); const [isClosed, setIsClosed] = useState(false); - {/* */ } + {/* const resetForm = () => { setFormData({ @@ -80,7 +80,7 @@ const ContactForm = () => { setIsLoading(false); setError(false); setError2(false); - }; + };*/ } useEffect(() => { if (error || error2) { @@ -167,6 +167,10 @@ const ContactForm = () => { if (response.data.message === "Form submitted successfully") { setIsLoading(false); setIsSuccess(true); + toast.success("Form submitted successfully") + setTimeout(() => { + setIsSuccess(false); // Allow the user to submit the form again + }, 2000); // Reset after 5 seconds setFormData({ name: "", @@ -462,9 +466,7 @@ Including:
- Submit Successfully - {/* */} - + Submitted Successfully
From 819565596bca48d3e05613aea1741d8ed71e0705 Mon Sep 17 00:00:00 2001 From: Hassen ben amor Date: Wed, 6 Mar 2024 23:31:21 +0100 Subject: [PATCH 5/7] newest update --- .../Homepage/ContactForm/ContactForm.jsx | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/components/Homepage/ContactForm/ContactForm.jsx b/src/components/Homepage/ContactForm/ContactForm.jsx index 838840cc..baaa75d2 100644 --- a/src/components/Homepage/ContactForm/ContactForm.jsx +++ b/src/components/Homepage/ContactForm/ContactForm.jsx @@ -167,10 +167,12 @@ const ContactForm = () => { if (response.data.message === "Form submitted successfully") { setIsLoading(false); setIsSuccess(true); + + toast.success("Form submitted successfully") setTimeout(() => { - setIsSuccess(false); // Allow the user to submit the form again - }, 2000); // Reset after 5 seconds + setIsSuccess(false); + }, 50); // Reset after 0.005 seconds setFormData({ name: "", @@ -462,15 +464,7 @@ Including: {"Server Error - Please contact us on discord"} )} - {isSuccess && !error ? - - -
- Submitted Successfully -
- - - : null} + From 55c5cae7efc5f6bf54fec9b9002234a9899a3034 Mon Sep 17 00:00:00 2001 From: Hassen ben amor Date: Wed, 6 Mar 2024 23:36:24 +0100 Subject: [PATCH 6/7] newest updateee --- .../Homepage/ContactForm/ContactForm.jsx | 21 ++----------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/components/Homepage/ContactForm/ContactForm.jsx b/src/components/Homepage/ContactForm/ContactForm.jsx index baaa75d2..be2fa552 100644 --- a/src/components/Homepage/ContactForm/ContactForm.jsx +++ b/src/components/Homepage/ContactForm/ContactForm.jsx @@ -63,24 +63,7 @@ const ContactForm = () => { const [isOpened, setIsOpened] = useState(false); const [isClosed, setIsClosed] = useState(false); - {/* - - const resetForm = () => { - setFormData({ - name: "", - email: "", - reason: "", - reasonType: "", - contextHeading: "", - resume: "", - message: "", - isExperienced: "", - }); - setIsSuccess(false); - setIsLoading(false); - setError(false); - setError2(false); - };*/ } + useEffect(() => { if (error || error2) { @@ -168,7 +151,7 @@ const ContactForm = () => { setIsLoading(false); setIsSuccess(true); - + toast.success("Form submitted successfully") setTimeout(() => { setIsSuccess(false); From 90f15d182130c5842259d147b7a950db5ae49c2b Mon Sep 17 00:00:00 2001 From: Hassen ben amor Date: Thu, 7 Mar 2024 00:17:07 +0100 Subject: [PATCH 7/7] newest updateee --- src/components/Homepage/ContactForm/ContactForm.jsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/Homepage/ContactForm/ContactForm.jsx b/src/components/Homepage/ContactForm/ContactForm.jsx index be2fa552..ccc00190 100644 --- a/src/components/Homepage/ContactForm/ContactForm.jsx +++ b/src/components/Homepage/ContactForm/ContactForm.jsx @@ -152,6 +152,8 @@ const ContactForm = () => { setIsSuccess(true); + + toast.success("Form submitted successfully") setTimeout(() => { setIsSuccess(false);