import { type FormEvent, useState } from "react"; /** Newsletter subscribe form. Shared by the marketing footer and home page. */ export function NewsletterSignup() { const [email, setEmail] = useState(""); const [status, setStatus] = useState< "idle" | "loading" | "success" | "error" >("idle"); const [errorMessage, setErrorMessage] = useState(""); const handleSubmit = async (e: FormEvent) => { e.preventDefault(); setStatus("loading"); setErrorMessage(""); try { const res = await fetch("/api/subscribe", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email }), }); if (!res.ok) { const data = await res.json().catch(() => ({})); throw new Error( (data as { error?: string }).error || "Something went wrong", ); } setStatus("success"); setEmail(""); } catch (err) { setStatus("error"); setErrorMessage( err instanceof Error ? err.message : "Something went wrong", ); } }; if (status === "success") { return
You're on the list.
; } return ( ); }