-
Notifications
You must be signed in to change notification settings - Fork 1.5k
refactor: extract webhook submission logic into a useWebhookSubmit
#7537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Manishnemade12
wants to merge
15
commits into
layer5io:master
Choose a base branch
from
Manishnemade12:eliminate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
709d5f4
refactor: extract webhook submission logic into a `useWebhookSubmit` …
Manishnemade12 c17fb1c
Merge branch 'master' into eliminate
Manishnemade12 aeb3e68
Merge branch 'master' into eliminate
Manishnemade12 b1f5d72
Merge branch 'master' into eliminate
Manishnemade12 9dede11
Update src/utils/hooks/useWebhookSubmit.js
Manishnemade12 bff7508
Merge branch 'master' into eliminate
Manishnemade12 96f097d
Merge branch 'master' into eliminate
Manishnemade12 f744db5
Merge branch 'master' into eliminate
Manishnemade12 185c96e
Remove unnecessary state update in EventForm on successful submission
Manishnemade12 5b5f726
Merge branch 'master' into eliminate
Manishnemade12 f5f5384
fix(forms): replace alert with inline error status
Manishnemade12 9359f93
Merge branch 'master' into eliminate
Manishnemade12 271d732
fix(form): enhance error handling and status display in CommonForm an…
Manishnemade12 6bf520d
fix(forms): remove unused state and add unmount safety to webhook sub…
Manishnemade12 d916c52
Merge branch 'master' into eliminate
Rajesh-Nagarajan-11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { useEffect, useRef, useState } from 'react'; | ||
| import axios from 'axios'; | ||
|
|
||
| export const useWebhookSubmit = () => { | ||
| const [isSubmitting, setIsSubmitting] = useState(false); | ||
| const [error, setError] = useState(null); | ||
Manishnemade12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const isMountedRef = useRef(true); | ||
| const requestControllerRef = useRef(null); | ||
|
|
||
| useEffect(() => { | ||
| return () => { | ||
| isMountedRef.current = false; | ||
| if (requestControllerRef.current) { | ||
| requestControllerRef.current.abort(); | ||
| } | ||
| }; | ||
| }, []); | ||
|
|
||
| const submitForm = async (payload) => { | ||
| const controller = new AbortController(); | ||
| requestControllerRef.current = controller; | ||
|
|
||
| if (isMountedRef.current) { | ||
| setIsSubmitting(true); | ||
| setError(null); | ||
| } | ||
|
|
||
| try { | ||
| const response = await axios.post( | ||
| "https://hook.us1.make.com/nficb3d7swqkclkl467st4hp4cg65u8o", | ||
| payload, | ||
| { signal: controller.signal }, | ||
| ); | ||
| return { success: true, data: response.data }; | ||
| } catch (err) { | ||
| const isAborted = controller.signal.aborted || err?.name === "CanceledError"; | ||
| if (isAborted) { | ||
| return { success: false, error: null, errorMessage: "Request was cancelled." }; | ||
| } | ||
|
|
||
| const errorMessage = (err && err.message) || 'An error occurred during submission.'; | ||
| const errorObject = err instanceof Error ? err : new Error(errorMessage); | ||
| if (isMountedRef.current) { | ||
| setError(errorObject); | ||
| } | ||
| return { success: false, error: errorObject, errorMessage }; | ||
| } finally { | ||
| if (requestControllerRef.current === controller) { | ||
| requestControllerRef.current = null; | ||
| } | ||
| if (isMountedRef.current) { | ||
| setIsSubmitting(false); | ||
| } | ||
| } | ||
| }; | ||
Manishnemade12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const errorMessage = error ? (error.message || 'An error occurred during submission.') : null; | ||
|
|
||
| return { submitForm, isSubmitting, error, errorMessage }; | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.