'use client'; import { useState } from 'react'; interface ForgotPasswordModalProps { isOpen: boolean; onClose: () => void; isProfileContext?: boolean; } export default function ForgotPasswordModal({ isOpen, onClose, isProfileContext = false }: ForgotPasswordModalProps) { const [email, setEmail] = useState(''); const [loading, setLoading] = useState(false); const [emailSent, setEmailSent] = useState(false); const [error, setError] = useState(null); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(null); try { const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/auth/forgot-password`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ email }), }); const data = await response.json(); if (data.success) { setEmailSent(true); } else { setError(data.message || 'Failed to send reset email'); } } catch (error) { setError('An error occurred. Please try again.'); } finally { setLoading(false); } }; const handleClose = () => { setEmail(''); setEmailSent(false); setError(null); onClose(); }; if (!isOpen) return null; return (
Reset Password
{emailSent ? (

Email Sent!

If an account exists for {email}, you'll receive a password reset link shortly.

The link will expire in 10 minutes. Be sure to check your spam folder if you don't see the email in your inbox.

) : (
{error && (
{error}
)}
setEmail(e.target.value)} required placeholder="Enter your email" />
{isProfileContext ? ( 'Forgot your current password? Enter your email address and we\'ll send you instructions to reset it.' ) : ( 'Enter your email address and we\'ll send you instructions to reset your password.' )}
)}
); }