Skip to content

Commit

Permalink
Add contact form
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaynegi45 committed Dec 8, 2024
1 parent 2ae853c commit c941133
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/app/contactform/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,28 @@ export default function ContactForm() {
};

const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
// e.preventDefault();
//
// try {
// const res = await fetch('/api/contact', {
// method: 'POST',
// headers: { 'Content-Type': 'application/json' },
// body: JSON.stringify(formData),
// });
//
// if (res.ok) {
// toast.success("Thank you for contacting us! Your message has been sent.");
// setFormData({ name: '', email: '', reason: '', message: '' });
// } else {
// toast.error("There was a problem sending the message. Please try again");
// }
// } catch (error) {
// toast.error("An unexpected error occurred. Please try again.");
// }

try {
const res = await fetch('/api/contact', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData),
});

if (res.ok) {
toast.success("Thank you for contacting us! Your message has been sent.");
setFormData({ name: '', email: '', reason: '', message: '' });
} else {
toast.error("There was a problem sending the message. Please try again");
}
} catch (error) {
toast.error("An unexpected error occurred. Please try again.");
}
};
toast.info("Currently Working on this form!");

return (
<div className={styles.container}>
Expand Down

0 comments on commit c941133

Please sign in to comment.