update form
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { Dispatch, SetStateAction } from "react";
|
||||
|
||||
export default async function submitContactForm(e: any, setSuccess: Dispatch<SetStateAction<string | null>>, setLoading: Dispatch<SetStateAction<boolean>>) {
|
||||
export default async function submitContactForm(
|
||||
e: any,
|
||||
setSuccess: Dispatch<SetStateAction<string | null>>,
|
||||
setLoading: Dispatch<SetStateAction<boolean>>
|
||||
) {
|
||||
e.preventDefault();
|
||||
|
||||
setLoading(true);
|
||||
@@ -15,26 +19,30 @@ export default async function submitContactForm(e: any, setSuccess: Dispatch<Set
|
||||
message: message,
|
||||
};
|
||||
|
||||
let res = await fetch("/api/contactForm", {
|
||||
method: "post",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
try {
|
||||
let res = await fetch("/api/contactForm", {
|
||||
method: "post",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
let data = await res.json();
|
||||
let data = await res.json();
|
||||
|
||||
console.log(data);
|
||||
console.log(data);
|
||||
|
||||
if (data.msg === "Success") {
|
||||
setSuccess("Success");
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1000);
|
||||
} else {
|
||||
setSuccess("Failed");
|
||||
if (data.msg === "Success") {
|
||||
setSuccess("Success");
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1000);
|
||||
} else {
|
||||
setSuccess("Failed");
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
} catch (error) {
|
||||
console.log("Form submission failed. Please try again in a minute.");
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user