diff --git a/src/App.tsx b/src/App.tsx index 0e26556..1504336 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,6 +6,7 @@ import { BrowserRouter, Routes, Route } from "react-router-dom"; import Index from "./pages/Index"; import Privacy from "./pages/Privacy"; import NotFound from "./pages/NotFound"; +import Waitlist from "./pages/Waitlist"; const queryClient = new QueryClient(); @@ -18,6 +19,7 @@ const App = () => ( } /> } /> + } /> {/* ADD ALL CUSTOM ROUTES ABOVE THE CATCH-ALL "*" ROUTE */} } /> diff --git a/src/pages/Waitlist.tsx b/src/pages/Waitlist.tsx new file mode 100644 index 0000000..5fe9e5c --- /dev/null +++ b/src/pages/Waitlist.tsx @@ -0,0 +1,104 @@ +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(""); + } 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 + Find trails tailored to your dog + + + + + + + + + Name + setName(e.target.value)} + placeholder="Name" + required + /> + + + + Email + setEmail(e.target.value)} + placeholder="Email *" + required + /> + + + + + {loading ? "Sending..." : "Join our Pack"} + + + + + + + + + + + ); +}; + +export default Waitlist;