'use client' import { motion, AnimatePresence } from 'framer-motion' import { useState } from 'react' import { Check, ArrowRight, Loader2 } from 'lucide-react' import { Button } from '@/components/ui/button' export function WaitlistForm() { const [email, setEmail] = useState('') const [isSubmitting, setIsSubmitting] = useState(false) const [isSuccess, setIsSuccess] = useState(false) const [error, setError] = useState('') const [confetti, setConfetti] = useState>([]) const validateEmail = (email: string) => { const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ return emailRegex.test(email) } const triggerConfetti = () => { const colors = ['hsl(var(--primary))', 'hsl(var(--teal))', 'hsl(var(--burgundy))', '#fbbf24', '#f97316'] const particles = Array.from({ length: 50 }, (_, i) => ({ id: Date.now() + i, x: 50 + (Math.random() - 0.5) * 40, // Center around 50% y: 50, rotation: Math.random() * 360, color: colors[Math.floor(Math.random() * colors.length)] })) setConfetti(particles) setTimeout(() => setConfetti([]), 3000) } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError('') if (!email) { setError('Please enter your email') return } if (!validateEmail(email)) { setError('Please enter a valid email') return } setIsSubmitting(true) try { const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001' const response = await fetch(`${apiUrl}/api/waitlist`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, source: 'landing_page', referrer: typeof window !== 'undefined' ? document.referrer : undefined, }), }) const data = await response.json() if (data.success) { setIsSubmitting(false) setIsSuccess(true) triggerConfetti() } else { setIsSubmitting(false) setError(data.message || 'Something went wrong. Please try again.') } } catch (err) { console.error('Waitlist signup error:', err) setIsSubmitting(false) setError('Connection error. Please try again.') } } if (isSuccess) { return ( {/* Confetti */} {confetti.map(particle => ( ))} {/* Success Card */} {/* Animated background accent */} {/* Success Icon */} {/* Success Message */} You're on the list! Check your inbox for confirmation {/* Bonus Badge */} 🎉 Early access: 50% off for 6 months ) } return (
{/* Email Input */} { setEmail(e.target.value) setError('') }} placeholder="Enter your email" disabled={isSubmitting} className={`w-full h-14 rounded-full px-6 text-base border-2 transition-all outline-none ${error ? 'border-red-500 bg-red-50 focus:border-red-500 focus:ring-4 focus:ring-red-500/20' : 'border-border bg-background focus:border-[hsl(var(--primary))] focus:ring-4 focus:ring-[hsl(var(--primary))]/20' } disabled:opacity-50 disabled:cursor-not-allowed`} /> {error && ( {error} )} {/* Submit Button */}
{/* Trust Signals Below Form */}
No credit card needed
•
No spam, ever
) }