"use client"; import { useState, type FormEvent } from "react"; import { Input } from "@cohaise/ui"; import { useLanguage } from "../contexts/LanguageContext"; import { LEADS_ENDPOINT } from "../lib/api"; import { Section, SectionHeading } from "./Section"; type Status = "idle" | "sending" | "success" | "error"; const text = (value: FormDataEntryValue | null): string => String(value ?? "").trim(); export const Contact = () => { const { t } = useLanguage(); const [status, setStatus] = useState("idle"); const handleSubmit = async (event: FormEvent) => { event.preventDefault(); const form = event.currentTarget; const data = new FormData(form); const payload = { firstName: text(data.get("firstName")), lastName: text(data.get("lastName")), email: text(data.get("email")), organization: text(data.get("organization")) || null, phone: text(data.get("phone")) || null, message: text(data.get("message")), website: text(data.get("website")), }; if (!payload.firstName || !payload.lastName || !payload.email) { setStatus("error"); return; } setStatus("sending"); try { const response = await fetch(LEADS_ENDPOINT, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }); if (!response.ok) throw new Error("request failed"); setStatus("success"); form.reset(); } catch { setStatus("error"); } }; return (
void handleSubmit(event)} className="glass max-w-2xl rounded-lg border border-border/60 p-5 sm:p-6" data-reveal data-reveal-delay="0.1" noValidate >