import React, { useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { useNavigate } from 'react-router-dom'; import { clearError } from '../store/reducers/authSlice'; import authService from '../services/authService'; const ForgotPassword = () => { const dispatch = useDispatch(); const navigate = useNavigate(); const { loading, error } = useSelector(state => state.auth); const [formData, setFormData] = useState({ email: '' }); const [isFocused, setIsFocused] = useState({ email: false }); const [success, setSuccess] = useState(false); const handleChange = (e) => { setFormData({ ...formData, [e.target.name]: e.target.value }); }; const handleFocus = (field) => { setIsFocused({ ...isFocused, [field]: true }); }; const handleBlur = (field) => { setIsFocused({ ...isFocused, [field]: false }); }; const handleSubmit = async (e) => { e.preventDefault(); // Prevent form submission if already loading if (loading === 'pending') { return; } try { await authService.forgotPassword(formData.email); setSuccess(true); // Clear form setFormData({ email: '' }); } catch (err) { console.error('Password reset request failed:', err); } }; const handleBackToLogin = () => { dispatch(clearError()); navigate('/login'); }; return (
{/* Logo and Brand */}
Lin

Reset Password

{success ? 'Check your email for password reset instructions' : 'Enter your email to receive password reset instructions'}

{/* Auth Card */}
{/* Success Message */} {success && (
Password reset instructions sent to your email. Please check your inbox.
)} {/* Error Message */} {error && !success && (
{error}
)} {!success && (
{/* Email Field */}
handleFocus('email')} onBlur={() => handleBlur('email')} className={`w-full px-3 sm:px-4 py-2 sm:py-3 rounded-xl border-2 transition-all duration-200 ${ isFocused.email ? 'border-primary-500 shadow-md' : 'border-gray-200 hover:border-gray-300' } ${formData.email ? 'text-gray-900' : 'text-gray-500'} focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 touch-manipulation`} placeholder="Enter your email" required aria-required="true" aria-label="Email address" />
{/* Submit Button */}
)} {/* Back to Login Link */}
{/* Footer */}

© 2024 Lin. All rights reserved.

); }; export default ForgotPassword;