diff --git a/functions/frontend/submitContactForm.ts b/functions/frontend/submitContactForm.ts index a6283dd..f9b2e24 100644 --- a/functions/frontend/submitContactForm.ts +++ b/functions/frontend/submitContactForm.ts @@ -1,6 +1,10 @@ import { Dispatch, SetStateAction } from "react"; -export default async function submitContactForm(e: any, setSuccess: Dispatch>, setLoading: Dispatch>) { +export default async function submitContactForm( + e: any, + setSuccess: Dispatch>, + setLoading: Dispatch> +) { e.preventDefault(); setLoading(true); @@ -15,26 +19,30 @@ export default async function submitContactForm(e: any, setSuccess: Dispatch { - 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); } diff --git a/pages/api/contactForm.ts b/pages/api/contactForm.ts index a819ea9..20a2ddd 100644 --- a/pages/api/contactForm.ts +++ b/pages/api/contactForm.ts @@ -10,7 +10,7 @@ import { NextApiRequest, NextApiResponse } from "next"; let transporter = nodemailer.createTransport({ host: process.env.TBENMAIL_HOST, - port: 587, + port: 465, auth: { user: process.env.TBENMAIL_EMAIL, pass: process.env.TBENMAIL_EMAIL_PASSWORD, @@ -46,7 +46,9 @@ export default async function handler( res.json({ msg: "Success", info: info }); } catch (error) { console.log(error); - res.json({ msg: "Failed" }); + res.json({ + msg: "Please try again in a minute.", + }); } } }