'use client'; import { useState } from 'react'; import { Box, TextField, Button, Typography, Paper, Alert, CircularProgress, Link as MuiLink, } from '@mui/material'; import { Email, ArrowBack } from '@mui/icons-material'; import { motion } from 'framer-motion'; import Link from 'next/link'; import apiClient from '@/lib/api/client'; import { useErrorMessage } from '@/components/common/ErrorMessage'; import { formatErrorMessage } from '@/lib/utils/errorHandler'; export default function ForgotPasswordPage() { const [email, setEmail] = useState(''); const [loading, setLoading] = useState(false); const { error, showError, clearError, hasError } = useErrorMessage(); const [success, setSuccess] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!email.trim()) { showError({ message: 'Please enter your email address', code: 'VALIDATION_EMAIL_REQUIRED' }); return; } setLoading(true); clearError(); try { await apiClient.post('/api/v1/auth/password/forgot', { email }); setSuccess(true); } catch (err: any) { showError(err); } finally { setLoading(false); } }; return ( {!success ? ( <> Forgot Password? No worries! Enter your email address and we'll send you a link to reset your password. {hasError && ( {formatErrorMessage(error)} )}
setEmail(e.target.value)} disabled={loading} required sx={{ mb: 3, '& .MuiOutlinedInput-root': { borderRadius: 3, }, }} /> Back to Login ) : ( Check Your Email 📧 If an account with that email exists, we've sent you a password reset link. Please check your inbox and follow the instructions. Didn't receive the email? • Check your spam or junk folder
• Make sure you entered the correct email
• The link expires in 1 hour
Back to Login
)}
); }