'use client' import { useState } from 'react' import { useForm } from 'react-hook-form' import { zodResolver } from '@hookform/resolvers/zod' import { z } from 'zod' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from '@/components/ui/card' import { Header } from '@/components/header' import { Footer } from '@/components/footer' import { Mail, ArrowLeft } from 'lucide-react' import Link from 'next/link' const ForgotPasswordSchema = z.object({ email: z.string().email('Please enter a valid email address'), }) type ForgotPasswordFormData = z.infer export default function ForgotPasswordPage() { const [isSubmitted, setIsSubmitted] = useState(false) const [error, setError] = useState(null) const [loading, setLoading] = useState(false) const { register, handleSubmit, formState: { errors }, getValues, } = useForm({ resolver: zodResolver(ForgotPasswordSchema), }) const onSubmit = async (data: ForgotPasswordFormData) => { try { setLoading(true) setError(null) const response = await fetch('/api/auth/forgot-password', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(data), }) const result = await response.json() if (result.success) { setIsSubmitted(true) } else { setError(result.error?.message || 'Failed to send reset email') } } catch (err) { setError('An error occurred. Please try again.') } finally { setLoading(false) } } return (

Reset Password

Enter your email address and we'll send you a link to reset your password

{isSubmitted ? ( <> Check Your Email We've sent a password reset link to {getValues('email')}

Click the link in the email to reset your password. If you don't see the email, check your spam folder.

) : ( <> Forgot Password Enter your email address to receive a password reset link
{error && (
{error}
)}
{errors.email && (

{errors.email.message}

)}
)}
) }