{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"waitlist-action","type":"registry:block","title":"Waitlist Capture + API","description":"Email waitlist form wired to a server-validated Next.js POST Route Handler with loading, success, and error states.","dependencies":["lucide-react"],"files":[{"path":"components/incepture/waitlist-action.tsx","type":"registry:block","target":"components/incepture/waitlist-action.tsx","content":"\"use client\";\n\nimport { useState, type FormEvent } from \"react\";\nimport { ArrowRight, CheckCircle2, Loader2 } from \"lucide-react\";\n\nexport interface WaitlistActionProps {\n  endpoint?: string;\n  heading?: string;\n  subcopy?: string;\n}\n\nexport function WaitlistAction({\n  endpoint = \"/api/demo/waitlist\",\n  heading = \"Get notified when we launch.\",\n  subcopy = \"Server-validated email capture backed by a Next.js Route Handler. Swap in Postgres, Resend, or Supabase in one file.\",\n}: WaitlistActionProps) {\n  const [email, setEmail] = useState(\"\");\n  const [status, setStatus] = useState<\"idle\" | \"loading\" | \"success\" | \"error\">(\"idle\");\n  const [message, setMessage] = useState(\"\");\n\n  async function handleSubmit(e: FormEvent) {\n    e.preventDefault();\n    if (!email.trim()) return;\n\n    setStatus(\"loading\");\n    setMessage(\"\");\n\n    try {\n      const res = await fetch(endpoint, {\n        method: \"POST\",\n        headers: { \"Content-Type\": \"application/json\" },\n        body: JSON.stringify({ email }),\n      });\n      const data = (await res.json()) as { message?: string; error?: string };\n\n      if (!res.ok) {\n        setStatus(\"error\");\n        setMessage(data.error || \"Unable to join right now.\");\n        return;\n      }\n\n      setStatus(\"success\");\n      setMessage(data.message || \"You're on the list.\");\n      setEmail(\"\");\n    } catch {\n      setStatus(\"error\");\n      setMessage(\"Network error. Please try again.\");\n    }\n  }\n\n  return (\n    <section className=\"mx-auto w-full max-w-2xl rounded-xl border border-stone-200 bg-white p-6 sm:p-8 text-stone-900 shadow-sm dark:border-stone-800 dark:bg-stone-900 dark:text-stone-100\">\n      <div className=\"space-y-2\">\n        <p className=\"font-mono text-[11px] uppercase tracking-[0.14em] text-orange-700 dark:text-orange-400\">\n          Full-Stack Block // API Route\n        </p>\n        <h3 className=\"text-2xl font-semibold tracking-tight\">{heading}</h3>\n        <p className=\"text-sm text-stone-600 dark:text-stone-400\">{subcopy}</p>\n      </div>\n\n      <form onSubmit={handleSubmit} className=\"mt-6 flex flex-col sm:flex-row gap-2.5\">\n        <input\n          type=\"email\"\n          required\n          value={email}\n          onChange={(e) => setEmail(e.target.value)}\n          placeholder=\"founder@hackathon.dev\"\n          aria-label=\"Email address\"\n          className=\"flex-1 rounded-lg border border-stone-300 bg-stone-50 px-3.5 py-2.5 text-sm outline-none focus:border-stone-900 dark:border-stone-700 dark:bg-stone-950 dark:focus:border-stone-200\"\n        />\n        <button\n          type=\"submit\"\n          disabled={status === \"loading\"}\n          className=\"inline-flex items-center justify-center gap-2 rounded-lg bg-stone-900 px-5 py-2.5 text-sm font-medium text-stone-50 transition hover:bg-stone-800 disabled:opacity-50 dark:bg-stone-100 dark:text-stone-950 dark:hover:bg-white\"\n        >\n          {status === \"loading\" ? (\n            <Loader2 className=\"h-4 w-4 animate-spin\" />\n          ) : (\n            <>\n              <span>Join waitlist</span>\n              <ArrowRight className=\"h-4 w-4\" />\n            </>\n          )}\n        </button>\n      </form>\n\n      {status === \"success\" && (\n        <p className=\"mt-3 inline-flex items-center gap-1.5 text-xs text-emerald-700 dark:text-emerald-400\">\n          <CheckCircle2 className=\"h-4 w-4\" />\n          <span>{message}</span>\n        </p>\n      )}\n      {status === \"error\" && (\n        <p className=\"mt-3 text-xs text-red-600 dark:text-red-400\">{message}</p>\n      )}\n    </section>\n  );\n}\n"},{"path":"app/api/demo/waitlist/route.ts","type":"registry:page","target":"app/api/demo/waitlist/route.ts","content":"import { NextRequest, NextResponse } from \"next/server\";\n\nconst EMAIL_RE = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\nexport async function POST(req: NextRequest) {\n  let email = \"\";\n  try {\n    const body = (await req.json()) as { email?: string };\n    email = typeof body.email === \"string\" ? body.email.trim().toLowerCase() : \"\";\n  } catch {\n    return NextResponse.json({ error: \"Invalid request body.\" }, { status: 400 });\n  }\n\n  if (!EMAIL_RE.test(email)) {\n    return NextResponse.json(\n      { error: \"Please enter a valid email address.\" },\n      { status: 422 }\n    );\n  }\n\n  // In your project, persist `email` to Postgres, Supabase, or Resend here.\n  return NextResponse.json({\n    ok: true,\n    message: `Server verified ${email} — ready to wire to your database.`,\n  });\n}\n"}]}