import { useState, type FormEvent, type ReactNode } from "react"; import { submitEnquiry, type EnquiryResult } from "@/data/enquiry"; /** * Editorial form used in two places: * variant="contact" — the Contact Us page * variant="bespoke" — bulk gifting / bespoke gifting enquiries */ const CONTACT_TOPICS = [ "General enquiry", "My order", "Feedback", "Press & collaborations", ]; const BESPOKE_TYPES = [ "Corporate & bulk gifting", "Weddings & celebrations", "Brand collaboration", "Events & experiences", "Custom packaging", ]; const BUDGETS = [ "Under ₹25,000", "₹25,000 – ₹1,00,000", "₹1,00,000 – ₹5,00,000", "Above ₹5,00,000", ]; const inputClass = "mt-2 w-full border-b border-ink-900/20 bg-transparent pb-3 pt-1 text-[1.05rem] font-light text-ink-900 outline-none transition-colors duration-300 placeholder:text-ink-500/40 focus:border-orange-500"; function Field({ label, error, children, className = "", }: { label: string; error?: string; children: ReactNode; className?: string; }) { return ( {label} {children} {error && {error}} ); } export default function ContactForm({ variant }: { variant: "contact" | "bespoke" }) { const bespoke = variant === "bespoke"; const [pending, setPending] = useState(false); const [errors, setErrors] = useState>({}); const [done, setDone] = useState(false); async function onSubmit(event: FormEvent) { event.preventDefault(); const form = event.currentTarget; const f = new FormData(form); const get = (k: string) => String(f.get(k) ?? "").trim(); setPending(true); setErrors({}); let result: EnquiryResult; try { result = await submitEnquiry({ data: { form: variant, name: get("name"), email: get("email"), phone: get("phone"), company: get("company"), topic: bespoke ? undefined : get("topic"), enquiryType: bespoke ? get("enquiryType") : undefined, quantity: get("quantity"), budget: get("budget"), date: get("date"), message: get("message"), website: get("website"), }, }); } catch { result = { ok: false, errors: { form: "Something went wrong — please try again, or call the atelier." } }; } setPending(false); if (result.ok) { form.reset(); setDone(true); } else { setErrors(result.errors); } } if (done) { return ( Thank you Your {bespoke ? "enquiry" : "note"} has reached the atelier — we reply within one working day. setDone(false)} className="link-quiet eyebrow mt-8 text-ink-700 hover:text-orange-500" > Send another ); } return ( {/* honeypot — hidden from real users */} {bespoke ? ( ) : ( {CONTACT_TOPICS.map((t) => ( {t} ))} )} {bespoke && ( {BESPOKE_TYPES.map((t) => ( {t} ))} Select a range {BUDGETS.map((b) => ( {b} ))} )} {errors.form && {errors.form}} {pending ? "Sending…" : bespoke ? "Send enquiry" : "Send message"} We reply within one working day. ); }
Thank you
Your {bespoke ? "enquiry" : "note"} has reached the atelier — we reply within one working day.
{errors.form}
We reply within one working day.