di usage in website
This commit is contained in:
@@ -20,6 +20,7 @@ import Button from '@/components/ui/Button';
|
||||
import Input from '@/components/ui/Input';
|
||||
import Heading from '@/components/ui/Heading';
|
||||
import { useAuth } from '@/lib/auth/AuthContext';
|
||||
import { useResetPassword } from '@/hooks/auth/useResetPassword';
|
||||
|
||||
interface FormErrors {
|
||||
newPassword?: string;
|
||||
@@ -52,7 +53,6 @@ export default function ResetPasswordPage() {
|
||||
const searchParams = useSearchParams();
|
||||
const { session } = useAuth();
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
|
||||
const [errors, setErrors] = useState<FormErrors>({});
|
||||
@@ -112,34 +112,40 @@ export default function ResetPasswordPage() {
|
||||
return Object.keys(newErrors).length === 0;
|
||||
};
|
||||
|
||||
// Use reset password mutation hook
|
||||
const resetPasswordMutation = useResetPassword({
|
||||
onSuccess: (result) => {
|
||||
setSuccess(result.message);
|
||||
},
|
||||
onError: (error) => {
|
||||
setErrors({
|
||||
submit: error.message || 'Failed to reset password. Please try again.',
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const handleSubmit = async (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (loading) return;
|
||||
if (resetPasswordMutation.isPending) return;
|
||||
|
||||
if (!validateForm()) return;
|
||||
|
||||
setLoading(true);
|
||||
setErrors({});
|
||||
setSuccess(null);
|
||||
|
||||
try {
|
||||
const { ServiceFactory } = await import('@/lib/services/ServiceFactory');
|
||||
const serviceFactory = new ServiceFactory(process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3001');
|
||||
const authService = serviceFactory.createAuthService();
|
||||
const result = await authService.resetPassword({
|
||||
await resetPasswordMutation.mutateAsync({
|
||||
token,
|
||||
newPassword: formData.newPassword,
|
||||
});
|
||||
|
||||
setSuccess(result.message);
|
||||
} catch (error) {
|
||||
setErrors({
|
||||
submit: error instanceof Error ? error.message : 'Failed to reset password. Please try again.',
|
||||
});
|
||||
setLoading(false);
|
||||
// Error handling is done in the mutation's onError callback
|
||||
}
|
||||
};
|
||||
|
||||
// Loading state from mutation
|
||||
const loading = resetPasswordMutation.isPending;
|
||||
|
||||
return (
|
||||
<main className="min-h-screen bg-deep-graphite flex items-center justify-center px-4 py-12">
|
||||
{/* Background Pattern */}
|
||||
|
||||
Reference in New Issue
Block a user