import { createFileRoute, Link } from '@tanstack/react-router'; import { z } from 'zod'; import { useState } from 'react'; import { CheckCircle, Lock, Loader2, Eye, EyeOff } from 'lucide-react'; import { apiClient } from '@/infrastructure/http/ApiClient'; import { RESET_PASSWORD } from '@archer/api-interface/endpoints/customer-api'; const resetPasswordSearchSchema = z.object({ token: z.string(), }); export const Route = createFileRoute('/auth/reset-password')({ validateSearch: resetPasswordSearchSchema, component: ResetPasswordPage, }); function ResetPasswordPage() { const { token } = Route.useSearch(); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); const [isSuccess, setIsSuccess] = useState(false); const [error, setError] = useState(''); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); if (password.length < 8) { setError('Password must be at least 8 characters.'); return; } if (password !== confirmPassword) { setError('Passwords do not match.'); return; } setIsSubmitting(true); try { await apiClient.post(RESET_PASSWORD.path, { token, newPassword: password }); setIsSuccess(true); } catch (err: any) { setError(err?.response?.data?.message || 'Failed to reset password. The link may be expired.'); } finally { setIsSubmitting(false); } }; if (isSuccess) { return (

Password Reset

Your password has been reset successfully.

Sign In
); } return (

Set New Password

Choose a new password for your account.

{error && (
{error}
)}
setPassword(e.target.value)} className="w-full pl-10 pr-10 py-2.5 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Min. 8 characters" required />
setConfirmPassword(e.target.value)} className="w-full pl-10 pr-4 py-2.5 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Repeat your password" required />
); }