refactor: extract webhook submission logic into a useWebhookSubmit#7537
refactor: extract webhook submission logic into a useWebhookSubmit#7537Manishnemade12 wants to merge 14 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 |
src/components/CommonForm/events.js
Outdated
| @@ -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({}); |
rishiraj38
left a comment
There was a problem hiding this comment.
Please also change the alerts in these lines.
…d ContactForm Signed-off-by: Manishnemade12 <mnemade140@gmail.com>
|
@rishiraj38 i Replaced alert("Submission failed...") in both index.js and index.js with Formik setStatus + inline accessible error UI (role="alert", aria-live="assertive"). |
|
Please take a look at copilot suggestions. |
@rishiraj38 i addressed all Copilot comments |
|
@Manishnemade12 Please present it tommorow meeting https://meet.layer5.io/websites-minutes |
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