import React, { useState } from "react"; import { authAPI } from "../services/api"; interface ForgotPasswordModalProps { show: boolean; onHide: () => void; onBackToLogin?: () => void; } const ForgotPasswordModal: React.FC = ({ show, onHide, onBackToLogin, }) => { const [email, setEmail] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const [success, setSuccess] = useState(false); const resetModal = () => { setEmail(""); setError(""); setSuccess(false); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(""); try { await authAPI.forgotPassword(email); setSuccess(true); } catch (err: any) { console.error('Forgot password error:', err); const errorData = err.response?.data; // Check for rate limiting if (err.response?.status === 429) { const retryAfter = errorData?.retryAfter; if (retryAfter) { const minutes = Math.ceil(retryAfter / 60); setError(`Too many password reset requests. Please try again in ${minutes} minute${minutes > 1 ? 's' : ''}.`); } else { setError('Too many password reset requests. Please try again later.'); } } else if (errorData?.details) { // Validation errors const validationErrors = errorData.details.map((d: any) => d.message).join(', '); setError(validationErrors); } else { setError(errorData?.error || "Failed to send reset email. Please try again."); } } finally { setLoading(false); } }; if (!show) return null; return ( <>
{success ? ( <>

Check Your Email

If an account exists with that email address, you will receive password reset instructions shortly.

Please check your spam folder if you don't see the email within a few minutes.

) : ( <>

Forgot Password?

Enter your email address and we'll send you instructions to reset your password.

{error && (
{error}
)}
setEmail(e.target.value)} placeholder="your@email.com" required />
)}
); }; export default ForgotPasswordModal;