From f9f246835b7a69825e199a3319414442d76ce65e Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sun, 19 Oct 2025 05:51:54 +0000 Subject: [PATCH] Add Wix microsite component: LeadForm with /api/leads submit cgen-8b8603d28aac4af8ae188d427cca7722 --- client/components/wix/LeadForm.tsx | 110 +++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 client/components/wix/LeadForm.tsx diff --git a/client/components/wix/LeadForm.tsx b/client/components/wix/LeadForm.tsx new file mode 100644 index 00000000..6b134718 --- /dev/null +++ b/client/components/wix/LeadForm.tsx @@ -0,0 +1,110 @@ +import { useEffect, useMemo, useState } from "react"; +import { Button } from "@/components/ui/button"; +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Textarea } from "@/components/ui/textarea"; +import { useAuth } from "@/contexts/AuthContext"; +import { useToast } from "@/components/ui/use-toast"; + +export default function LeadForm() { + const { user, profile } = useAuth(); + const { toast } = useToast(); + const [loading, setLoading] = useState(false); + const [form, setForm] = useState({ + name: "", + email: "", + company: "", + website: "", + budget: "", + timeline: "", + message: "", + source: "wix", + }); + + const inferred = useMemo(() => { + const full = (profile?.full_name || "").trim(); + const email = (user?.email || profile?.email || "").trim(); + return { full, email }; + }, [user, profile]); + + useEffect(() => { + setForm((f) => ({ + ...f, + name: f.name || inferred.full, + email: f.email || inferred.email, + })); + }, [inferred.full, inferred.email]); + + const update = (k: keyof typeof form) => (e: any) => setForm({ ...form, [k]: e.target.value }); + + const submit = async () => { + if (!form.email) { + toast({ title: "Email required", description: "Please provide a valid email." }); + return; + } + setLoading(true); + try { + const r = await fetch("/api/leads", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify(form), + }); + const ok = r.ok; + const data = await r.json().catch(() => ({})); + if (!ok) throw new Error(data?.error || `Request failed (${r.status})`); + toast({ title: "Thanks!", description: "We’ll follow up shortly with next steps." }); + setForm({ ...form, message: "" }); + } catch (e: any) { + toast({ title: "Submission failed", description: e?.message || "Try again later.", variant: "destructive" as any }); + } finally { + setLoading(false); + } + }; + + return ( +
+ + + Start a Wix project + Tell us a bit about your goals. We’ll get back within 1 business day. + + +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +