import React from "react"; import emailjs from "@emailjs/browser"; import { ToastContainer, toast } from "react-toastify"; import "react-toastify/dist/ReactToastify.css"; import { useTranslation } from "react-i18next"; const ContactForm = () => { const { t } = useTranslation(); const notify = () => { toast.success(t("contact.toasts.success")); }; const errorToast = () => { toast.error(t("contact.toasts.error")); }; const emptyForm = () => { toast.warning(t("contact.toasts.empty")); }; const sendEmail = (e: React.FormEvent) => { e.preventDefault(); let isEmpty = Array.from(e.currentTarget.elements).some( (input) => (input as HTMLInputElement).type !== "submit" && (input as HTMLInputElement).value.trim() === "" ); if (isEmpty) { emptyForm(); return; } emailjs .sendForm("service_o7kxotj", "template_f30zlog", e.currentTarget, { publicKey: "vcSOwPedqkRH3nmr9", }) .then( (result) => { console.log(result.text); notify(); }, (error) => { console.log(error.text); errorToast(); } ); e.currentTarget.reset(); }; return (
); }; export default ContactForm;