refactor: extract webhook submission logic into a useWebhookSubmit#7537
refactor: extract webhook submission logic into a useWebhookSubmit#7537Manishnemade12 wants to merge 11 commits intolayer5io:masterfrom
useWebhookSubmit#7537Conversation
There was a problem hiding this comment.
Pull request overview
This PR centralizes webhook submission logic into a new useWebhookSubmit hook and updates existing forms to await submissions in Formik’s onSubmit, preventing false-positive “success” UI transitions when requests fail.
Changes:
- Added
useWebhookSubmithook to encapsulate axios submission state + error handling. - Refactored
CommonForm,EventForm, andContactFormto submit via the hook insideonSubmit(removing prioruseEffect-triggered posts). - Added basic failure handling (alerts) and kept success scrolling behavior within the submit flow.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| src/utils/hooks/useWebhookSubmit.js | Introduces a reusable hook to submit payloads to the Make.com webhook and track submission/error state. |
| src/components/ContactForm/index.js | Switches to awaiting webhook submission in onSubmit and only transitions UI on success. |
| src/components/CommonForm/index.js | Replaces useEffect-based post with awaited submit and gates success step on confirmed submission. |
| src/components/CommonForm/events.js | Refactors event form submission to use the hook and handle failure explicitly. |
…hook and integrate it into CommonForm and ContactForm components. Signed-off-by: Manishnemade12 <mnemade140@gmail.com>
a99476c to
709d5f4
Compare
|
🚀 Preview for commit 709d5f4 at: https://69bf9360215bccffd0afcbeb--layer5.netlify.app |
|
🚀 Preview for commit c17fb1c at: https://69bfa8b06f2ab006b9de4b89--layer5.netlify.app |
|
🚀 Preview for commit aeb3e68 at: https://69c1f9b6c87786311b23e0c6--layer5.netlify.app |
|
@CodexRaunak can you please review this pr |
|
🚀 Preview for commit b1f5d72 at: https://69c230ab39fb22adc0c2d56b--layer5.netlify.app |
|
@saurabhraghuvanshii can you please review this pr |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Manish Nemade <166635137+Manishnemade12@users.noreply.github.com>
|
🚀 Preview for commit 9dede11 at: https://69c3a8772f6d231371e28811--layer5.netlify.app |
|
🚀 Preview for commit bff7508 at: https://69c3dc33a1de532588f1acdb--layer5.netlify.app |
|
@saurabhraghuvanshii can you please review this pr |
|
🚀 Preview for commit 96f097d at: https://69c4cecb8748eee6140f5f36--layer5.netlify.app |
|
🚀 Preview for commit f744db5 at: https://69c7e653c5238f112a3bf1aa--layer5.netlify.app |
Signed-off-by: Manishnemade12 <mnemade140@gmail.com>
|
@rishiraj38 i addressed your changes can you please review it now |
|
🚀 Preview for commit 185c96e at: https://69c81ea05353dd80e8a52b9b--layer5.netlify.app |
|
@saurabhraghuvanshii can you please review this pr |
|
🚀 Preview for commit 5b5f726 at: https://69cf571d9fc8b8195bffb68c--layer5.netlify.app |
rishiraj38
left a comment
There was a problem hiding this comment.
Please take a look on copilot review
|
@rishiraj38 Replaced the blocking alert() on form submission failure with an inline, accessible error message using Formik status and an aria-live region. This keeps users in context, improves accessibility, and avoids disruptive browser modals. |
Signed-off-by: Manishnemade12 <mnemade140@gmail.com>
9c1088f to
f5f5384
Compare
|
🚀 Preview for commit f5f5384 at: https://69cf8a11fa0a08bd41a76430--layer5.netlify.app |
| const submitForm = async (payload) => { | ||
| setIsSubmitting(true); | ||
| setError(null); | ||
| try { | ||
| const response = await axios.post("https://hook.us1.make.com/nficb3d7swqkclkl467st4hp4cg65u8o", payload); | ||
| return { success: true, data: response.data }; | ||
| } catch (err) { | ||
| const errorMessage = (err && err.message) || 'An error occurred during submission.'; | ||
| const errorObject = err instanceof Error ? err : new Error(errorMessage); | ||
| setError(errorObject); | ||
| return { success: false, error: errorObject, errorMessage }; | ||
| } finally { | ||
| setIsSubmitting(false); | ||
| } | ||
| }; |
There was a problem hiding this comment.
submitForm sets React state after an awaited request; if a component using this hook unmounts mid-request (route change, conditional render), React can warn about state updates on an unmounted component. Consider guarding state updates with an isMounted ref/cleanup, or use request cancellation (e.g., AbortController via axios signal) to avoid post-unmount updates.
| onSubmit={async (values) => { | ||
| const { success } = await submitForm({ memberFormOne: values }); | ||
| if (success) { | ||
| setmemberFormOne(values); | ||
| setSubmit(true); | ||
| window.scrollTo(0, 700); | ||
| } else { | ||
| alert("Submission failed. Please try again."); | ||
| } | ||
| }} |
There was a problem hiding this comment.
Using alert() for submission failures is disruptive and not as accessible/consistent as an inline, aria-live error region (as added in events.js). Prefer setting Formik status (or a local error state) and rendering the message in the form with role="alert"/aria-live, so screen readers and keyboard-only users get a predictable experience.
| onSubmit={async (values) => { | ||
| if (isValidRole(values.role) && isValidEmail(values.email)) { | ||
| setMemberFormOne(values); | ||
| setStepNumber(1); | ||
| setSubmit(true); | ||
| // window.scrollTo(0,window.scrollY - 800); | ||
| // confirmationMessageRef.current.scrollIntoView({ behavior: 'smooth' }) | ||
| scrollElementIntoView(confirmationMessageRef.current, navBarOffset); | ||
| const { success } = await submitForm({ memberFormOne: values }); | ||
| if (success) { | ||
| setMemberFormOne(values); | ||
| setStepNumber(1); | ||
| setSubmit(true); | ||
| // window.scrollTo(0,window.scrollY - 800); | ||
| // confirmationMessageRef.current.scrollIntoView({ behavior: 'smooth' }) | ||
| scrollElementIntoView(confirmationMessageRef.current, navBarOffset); | ||
| } else { | ||
| alert("Submission failed. Please try again."); | ||
| } | ||
| } else { |
There was a problem hiding this comment.
Same issue as ContactForm: alert() is a poor UX/accessibility pattern for form errors. Align with the events.js approach by using Formik status (or a dedicated error area) and emitting the message in an aria-live region near the submit button.
| @@ -12,6 +12,7 @@ const EventForm = ({ form, title, submit_title, submit_body }) => { | |||
| const [stepNumber, setStepNumber] = useState(0); | |||
| const [memberFormOne, setMemberFormOne] = useState({}); | |||
There was a problem hiding this comment.
In this refactor, memberFormOne is no longer set in onSubmit (the previous setMemberFormOne(values); was removed), so this state may now be dead weight. If the form no longer needs memberFormOne for rendering the success step, remove it; otherwise, set it on successful submission for consistency with the other forms.
| const [memberFormOne, setMemberFormOne] = useState({}); |
Description
This PR fixes #7536
This PR abstracts and centralizes the duplicated webhook submission logic by introducing a custom useWebhookSubmit hook. It integrates this new hook into the CommonForm (index.js and events.js) and ContactForm (index.js) components. Previously, these forms used an unhandled
axios.postinside auseEffecttriggered by a state flag, which risked silent data loss on network failure. By awaiting the network requests directly inside the FormikonSubmithandlers, we ensure the UI transitions to the "Thank You" screen only upon a confirmed HTTP success.Notes for Reviewers
/contact,/community/events, and other form pages.Signed commits