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 ( +
+
+ SUBSCRIBED +
+

+ You'll hear about new features and launches. +

+
+ ); + } + + return ( +
+
+ // STAY IN THE LOOP +
+

+ Get notified about new features, releases, and tools I'm building. +

+
+ { setEmail(e.target.value); setStatus("idle"); }} + placeholder="you@example.com" + required + className="flex-1 bg-bg border-2 border-border px-4 py-2 font-[family-name:var(--font-mono)] text-text text-xs outline-none focus:border-accent transition-colors placeholder:text-dim/50" + /> + +
+ {status === "error" && ( +

+ {msg} +

+ )} +
+ ); +} diff --git a/site/app/page.tsx b/site/app/page.tsx index e35fecc..8b1c842 100644 --- a/site/app/page.tsx +++ b/site/app/page.tsx @@ -1,5 +1,6 @@ import Image from "next/image"; import { EmailReveal } from "./email-reveal"; +import { NewsletterForm } from "./newsletter-form"; import { TerminalCascade } from "./terminal-cascade"; import { SearchIcon, @@ -596,6 +597,13 @@ export default function Home() { + {/* ══════ NEWSLETTER ══════ */} +
+
+ +
+
+ {/* ══════ AUTHOR ══════ */}