-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathuseWebhookSubmit.js
More file actions
27 lines (23 loc) · 976 Bytes
/
useWebhookSubmit.js
File metadata and controls
27 lines (23 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { useState } from 'react';
import axios from 'axios';
export const useWebhookSubmit = () => {
const [isSubmitting, setIsSubmitting] = useState(false);
const [error, setError] = useState(null);
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);
}
};
const errorMessage = error ? (error.message || 'An error occurred during submission.') : null;
return { submitForm, isSubmitting, error, errorMessage };
};