"use client"; import HCaptcha from "@hcaptcha/react-hcaptcha"; import { Send } from "lucide-react"; import { useRef, useState } from "react"; import { emails } from "@/constants"; import { isEmail } from "validator"; import SocialIcons from "@/components/SocialIcons"; function Contact() { const [name, setName] = useState(""); const [email, setEmail] = useState(""); const [message, setMessage] = useState(""); const [status, setStatus] = useState(""); const [hCaptchaToken, setHCaptchaToken] = useState(null); const captchaRef = useRef(); return (

Contact us

{ e.preventDefault(); try { const res = await fetch("/api/contact", { method: "POST", body: JSON.stringify({ captchaToken: hCaptchaToken, name: name, email: email, message: message }), headers: { "Content-Type": "application/json", Accept: "application/json" } }); if (res.status == 200) { setStatus("Your message has been sent."); } else { setStatus("Uh oh! Something went wrong."); } } catch (error) { console.error(error); setStatus("Uh oh! Something went wrong."); } setHCaptchaToken(null); captchaRef.current.resetCaptcha(); setName(""); setEmail(""); setMessage(""); }} > { setName(e.target.value); }} value={name} id="contact-name" className="block mb-4 bg-accent text-accent-foreground w-full rounded-md px-2 py-1 focus:outline focus:outline-2 focus:outline-primary" /> { setEmail(e.target.value); }} value={email} id="contact-email" className="block mb-4 bg-accent text-accent-foreground w-full rounded-md px-2 py-1 focus:outline focus:outline-2 focus:outline-primary" />