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 (
Your password has been reset successfully.
Sign InChoose a new password for your account.
{error && (