"use client"; import SubmitToast from "@/app/components/ui/SubmitToast"; import { useMemo, useState } from "react"; type IndustryOption = { value: string; label: string }; const emptyRegistration = { fullName: "", phone: "", email: "", company: "", jobTitle: "", industry: "", notes: "", }; export default function RegistrationForm({ data, }: { data: { sections: { personal: { title: string; fullName: string; phone: string; email: string }; professional: { title: string; company: string; jobTitle: string }; industry: { title: string; label: string; placeholder: string; options: IndustryOption[] }; additional: { title: string; label: string; placeholder: string }; }; submit: { label: string; disclaimer: string }; }; }) { const industries = useMemo(() => data.sections.industry.options, [data.sections.industry.options]); const [form, setForm] = useState(emptyRegistration); const [submitState, setSubmitState] = useState<"idle" | "sending" | "ok" | "error">("idle"); return (
{ e.preventDefault(); setSubmitState("sending"); const industryLabel = industries.find((o) => o.value === form.industry)?.label ?? ""; try { const res = await fetch("/ipv6/api/submissions", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ type: "registration", ...form, industryLabel, }), }); if (!res.ok) { const err = await res.json().catch(() => ({})); throw new Error(typeof err?.error === "string" ? err.error : res.statusText); } setSubmitState("ok"); } catch { setSubmitState("error"); } }} >

{data.sections.personal.title}

setForm((s) => ({ ...s, fullName: e.target.value }))} />
setForm((s) => ({ ...s, phone: e.target.value }))} />
setForm((s) => ({ ...s, email: e.target.value }))} />

{data.sections.professional.title}

setForm((s) => ({ ...s, company: e.target.value }))} />
setForm((s) => ({ ...s, jobTitle: e.target.value }))} />

{data.sections.industry.title}

expand_more

{data.sections.additional.title}