// src/pages/ForgotPassword/ResetPassword.tsx import { useState, useEffect } from 'react'; import { useNavigate, Link } from 'react-router-dom'; import { Button } from '../../components/ui/button'; import { Input } from '../../components/ui/input'; import { Label } from '../../components/ui/label'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../../components/ui/card'; import { Lock, Eye, EyeOff, ArrowLeft, CheckCircle } from 'lucide-react'; import { forgotPasswordApi } from '../../lib/api/forgotPasswordApi'; export function ResetPassword() { const [newPassword, setNewPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [showConfirmPassword, setShowConfirmPassword] = useState(false); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(false); const navigate = useNavigate(); const email = sessionStorage.getItem('resetEmail'); const otp = sessionStorage.getItem('resetOtp'); useEffect(() => { if (!email || !otp) { navigate('/forgot-password'); } }, [email, otp, navigate]); const validatePassword = (password: string): string | null => { if (password.length < 6) { return 'Password must be at least 6 characters long'; } return null; }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); const passwordError = validatePassword(newPassword); if (passwordError) { setError(passwordError); return; } if (newPassword !== confirmPassword) { setError('Passwords do not match'); return; } if (!email || !otp) return; setLoading(true); setError(null); try { await forgotPasswordApi.resetPassword({ email, otp, newPassword, confirmNewPassword: confirmPassword, }); setSuccess(true); // Clear sensitive data from session storage sessionStorage.removeItem('resetEmail'); sessionStorage.removeItem('resetOtp'); // Redirect to sign in after 3 seconds setTimeout(() => { navigate('/signin'); }, 3000); } catch (err) { console.error('Password reset error:', err); setError(err instanceof Error ? err.message : 'Failed to reset password'); } finally { setLoading(false); } }; if (success) { return (
Password Reset Successful! Your password has been changed successfully.
); } return (
Back Reset Password Create a new password for your account
setNewPassword(e.target.value)} placeholder="Enter new password" className="pl-10 pr-10" required />

Password must be at least 6 characters long

setConfirmPassword(e.target.value)} placeholder="Confirm new password" className="pl-10 pr-10" required />
{error && (

{error}

)}
); }