diff --git a/components/newsletter-signup.tsx b/components/newsletter-signup.tsx new file mode 100644 index 0000000..78d336d --- /dev/null +++ b/components/newsletter-signup.tsx @@ -0,0 +1,95 @@ +"use client" + +import { useState } from "react" +import { Button } from "@/components/ui/button" + +const NEWSLETTER_API = "https://newsletter.jeffemmett.com/api/subscribe" +const LIST_UUID = "2d247234-34cf-4ee6-858f-2b5e24e2e5dc" // rSpace list + +export function NewsletterSignup() { + const [email, setEmail] = useState("") + const [status, setStatus] = useState<"idle" | "loading" | "success" | "error">("idle") + const [message, setMessage] = useState("") + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault() + + if (!email) return + + setStatus("loading") + + try { + const response = await fetch(`${NEWSLETTER_API}/subscribe`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + email: email, + list_uuid: LIST_UUID, + }), + }) + + if (response.ok) { + setStatus("success") + setMessage("Welcome to (you)rSpace. See you there.") + setEmail("") + } else { + throw new Error("Subscription failed") + } + } catch { + setStatus("error") + setMessage("Something went wrong. Please try again.") + } + } + + return ( +
+
+
+
+

+ Stay Connected with rSpace +

+

+ Subscribe for updates on real-time collaboration, + spatial computing, and building connected futures. +

+
+ + {status === "success" ? ( +
+ {message} +
+ ) : ( +
+ setEmail(e.target.value)} + required + className="flex-1 px-4 py-2 rounded-lg border bg-background focus:outline-none focus:ring-2 focus:ring-primary/50" + /> + +
+ )} + + {status === "error" && ( +

{message}

+ )} + +

+ No spam, unsubscribe anytime. We respect your privacy. +

+
+
+
+ ) +}