From faca97f1ae1ba870673347f98557191fcd5c123a Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Sun, 22 Jun 2025 13:21:03 +0200 Subject: add upstash rate limiting --- apps/web/src/components/landing/hero.tsx | 61 ++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) (limited to 'apps/web/src/components') diff --git a/apps/web/src/components/landing/hero.tsx b/apps/web/src/components/landing/hero.tsx index e5f0b867..e5eca8b6 100644 --- a/apps/web/src/components/landing/hero.tsx +++ b/apps/web/src/components/landing/hero.tsx @@ -5,8 +5,53 @@ import { Button } from "../ui/button"; import { Input } from "../ui/input"; import { ArrowRight } from "lucide-react"; import Link from "next/link"; +import { useState } from "react"; +import { toast } from "sonner"; export function Hero() { + const [email, setEmail] = useState(""); + const [isSubmitting, setIsSubmitting] = useState(false); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + + if (!email.trim()) { + toast.error("Email required", { + description: "Please enter your email address.", + }); + return; + } + + setIsSubmitting(true); + + try { + const response = await fetch("/api/waitlist", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ email: email.trim() }), + }); + + const data = await response.json(); + + if (response.ok) { + toast.success("Welcome to the waitlist! 🎉"); + setEmail(""); + } else { + toast.error("Oops!", { + description: data.error || "Something went wrong. Please try again.", + }); + } + } catch (error) { + toast.error("Network error", { + description: "Please check your connection and try again.", + }); + } finally { + setIsSubmitting(false); + } + }; + return (
-
+ setEmail(e.target.value)} + disabled={isSubmitting} required /> -
-- cgit v1.3.1