import { useState, type FC } from 'react'; import { useNavigate, Link } from 'react-router-dom'; import { Container, Paper, TextField, Button, Typography, Box, Alert, CircularProgress, } from '@mui/material'; import { useAuthStore } from '../store/useStore'; export const RecoveryPage: FC = () => { const navigate = useNavigate(); const { recover, isLoading, error, clearError } = useAuthStore(); const [email, setEmail] = useState(''); const [recoveryPhrase, setRecoveryPhrase] = useState(''); const [newPassword, setNewPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [localError, setLocalError] = useState(''); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); clearError(); setLocalError(''); if (newPassword !== confirmPassword) { setLocalError('Passwords do not match'); return; } if (newPassword.length < 8) { setLocalError('Password must be at least 8 characters'); return; } try { await recover(email, recoveryPhrase, newPassword); navigate('/login', { replace: true }); } catch { /* error surfaced via store */ } }; return ( Recover Account Enter your recovery phrase to reset your password and regain access to your encrypted data. {(error || localError) && ( {error || localError} )} setEmail(e.target.value)} disabled={isLoading} autoFocus /> setRecoveryPhrase(e.target.value)} disabled={isLoading} /> setNewPassword(e.target.value)} disabled={isLoading} /> setConfirmPassword(e.target.value)} disabled={isLoading} /> Back to Sign In ); }; export default RecoveryPage;