import * as React from "react"; import { toast } from "@/components/ui/use-toast"; const Waitlist: React.FC = () => { const [name, setName] = React.useState(""); const [email, setEmail] = React.useState(""); const [loading, setLoading] = React.useState(false); const onSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!name.trim() || !email.trim()) { toast({ title: "Please provide name and email." }); return; } setLoading(true); try { const envBase = (import.meta as any).env?.VITE_API_URL as string | undefined; const base = envBase ? envBase.replace(/\/$/, "") : "http://localhost:8080"; const url = `${base}/waitlist?name=${encodeURIComponent(name)}&email=${encodeURIComponent(email)}`; const res = await fetch(url, { method: "POST" }); if (!res.ok) { const text = await res.text().catch(() => ""); throw new Error(text || `Status ${res.status}`); } toast({ title: "Success", description: "You've been added to the waitlist." }); setName(""); setEmail(""); // redirect to home after 0.5 seconds setTimeout(() => { window.location.href = "/"; }, 500); } catch (err: any) { toast({ title: "Error", description: err?.message ?? String(err) }); } finally { setLoading(false); } }; return (

Be the first to know as soon as the TailTrails App is live

TailTrails Logo
TailTrails
Find trails tailored to your dog
setName(e.target.value)} placeholder="Name" required />
setEmail(e.target.value)} placeholder="Email *" required />
); }; export default Waitlist;