"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.