diff --git a/site/app/newsletter-form.tsx b/site/app/newsletter-form.tsx new file mode 100644 index 0000000..b5e39f1 --- /dev/null +++ b/site/app/newsletter-form.tsx @@ -0,0 +1,82 @@ +"use client"; + +import { useState } from "react"; + +const API_URL = "https://alezmad-nuc.tail58f5ad.ts.net"; + +export function NewsletterForm({ project = "cladm" }: { project?: string }) { + const [email, setEmail] = useState(""); + const [status, setStatus] = useState<"idle" | "loading" | "ok" | "error">("idle"); + const [msg, setMsg] = useState(""); + + async function handleSubmit(e: React.FormEvent) { + e.preventDefault(); + if (!email.trim()) return; + setStatus("loading"); + try { + const res = await fetch(`${API_URL}/subscribe`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ email: email.trim(), project }), + }); + const data = await res.json(); + if (data.ok) { + setStatus("ok"); + setMsg("subscribed"); + setEmail(""); + } else { + setStatus("error"); + setMsg(data.error || "failed"); + } + } catch { + setStatus("error"); + setMsg("network error"); + } + } + + if (status === "ok") { + return ( +
+ You'll hear about new features and launches. +
+