import { useState } from "react"; import { useMutation } from "@tanstack/react-query"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { useToast } from "@/hooks/use-toast"; import { apiRequest } from "@/lib/queryClient"; export default function Newsletter() { const [email, setEmail] = useState(""); const { toast } = useToast(); const subscribeMutation = useMutation({ mutationFn: async (email: string) => { return apiRequest("POST", "/api/newsletter/subscribe", { email }); }, onSuccess: () => { toast({ title: "Success!", description: "You've been successfully subscribed to our newsletter.", }); setEmail(""); }, onError: (error: Error) => { toast({ title: "Error", description: error.message || "Failed to subscribe. Please try again.", variant: "destructive", }); }, }); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (!email) return; subscribeMutation.mutate(email); }; return (

Subscribe to Newsletter

Stay informed about our services, grief support resources, and community events.

setEmail(e.target.value)} className="flex-1 px-4 py-3 rounded-l-md text-charcoal focus:outline-none focus:ring-2 focus:ring-gold" required />
); }