import { useState, useEffect } from 'react' import { Link, useNavigate, useSearchParams } from 'react-router-dom' import { useAuth } from '@/context/AuthContext' import { analytics } from '@/hooks/useAnalytics' import { captureUTMParams } from '@/lib/analytics' import { api } from '@/lib/api' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Badge } from '@/components/ui/badge' import { Mail, Lock, User, ArrowRight, AlertCircle, Check, Sparkles } from 'lucide-react' export function Register() { const [searchParams] = useSearchParams() const selectedPlan = searchParams.get('plan') || 'pro' const referralCode = searchParams.get('ref') || null const [name, setName] = useState('') const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') const [error, setError] = useState('') const [loading, setLoading] = useState(false) const { register, user } = useAuth() const navigate = useNavigate() // Capture UTM parameters on mount useEffect(() => { captureUTMParams() }, []) // Track referral and signup after user is registered useEffect(() => { if (user?.$id && referralCode) { // Track referral if code exists api.trackReferral(user.$id, referralCode).catch((err) => { console.error('Failed to track referral:', err) }) } if (user?.$id) { // Track signup conversion with UTM parameters analytics.trackSignup(user.$id, email) analytics.setUserId(user.$id) } }, [user, referralCode, email]) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError('') if (password !== confirmPassword) { setError('Passwords do not match.') return } if (password.length < 8) { setError('Password must be at least 8 characters long.') return } setLoading(true) try { await register(email, password, name) navigate('/setup') } catch (err: unknown) { setError(err instanceof Error ? err.message : 'Registration failed. Please try again.') } finally { setLoading(false) } } return (
{/* Left side - Decorative */}
{/* Background pattern */}
14-day free trial

Start with MailFlow today

    {[ 'No credit card required', 'Gmail & Outlook support', 'AI-powered categorization', 'Cancel anytime', ].map((item, index) => (
  • {item}
  • ))}
{/* Plan indicator */}

Selected plan

{selectedPlan}

{/* Right side - Form */}
{/* Logo */} MailFlow Logo MailFlow

Create account

Ready to go in less than a minute.

{/* Error message */} {error && (

{error}

)} {/* Form */}
setName(e.target.value)} className="pl-10" />
setEmail(e.target.value)} className="pl-10" required />
setPassword(e.target.value)} className="pl-10" required />
setConfirmPassword(e.target.value)} className="pl-10" required />

By signing up, you agree to our{' '} Terms of Service and{' '} Privacy Policy.

Already have an account?{' '} Sign in

) }