"use client"; import { useState, useEffect, Suspense } from "react"; import { useSearchParams, useRouter } from "next/navigation"; import Link from "next/link"; import { ROUTES, API_BASE_URL } from "@/utils/constants"; function ResetPasswordForm() { const searchParams = useSearchParams(); const router = useRouter(); const token = searchParams.get("token"); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [isSubmitting, setIsSubmitting] = useState(false); const [isSuccess, setIsSuccess] = useState(false); const [error, setError] = useState(""); const [showPassword, setShowPassword] = useState(false); useEffect(() => { if (!token) { setError("Token de réinitialisation manquant. Veuillez demander un nouveau lien."); } }, [token]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(""); // Validation if (password.length < 8) { setError("Le mot de passe doit contenir au moins 8 caractères"); return; } if (password !== confirmPassword) { setError("Les mots de passe ne correspondent pas"); return; } setIsSubmitting(true); try { const response = await fetch(`${API_BASE_URL}/auth/reset-password`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ token, password, confirmPassword }), }); const data = await response.json(); if (data.success) { setIsSuccess(true); // Redirection après 3 secondes setTimeout(() => { router.push(ROUTES.LOGIN); }, 3000); } else { setError(data.message || 'Une erreur est survenue'); } } catch (err) { setError('Erreur de connexion au serveur'); console.error('Reset password error:', err); } finally { setIsSubmitting(false); } }; if (isSuccess) { return (

Mot de passe modifié !

Votre mot de passe a été réinitialisé

Vous allez être redirigé vers la page de connexion...

Se connecter maintenant
); } return (
{/* Title */}

Nouveau mot de passe

Choisissez un nouveau mot de passe sécurisé

{/* Main Card */}
{/* Error Message */} {error && (
{error}
)} {/* Form */}
{/* New Password */}
setPassword(e.target.value)} placeholder="Minimum 8 caractères" className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-[#1a4d2e] focus:border-transparent pr-12" disabled={!token} />
{/* Confirm Password */}
setConfirmPassword(e.target.value)} placeholder="Répétez le mot de passe" className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-[#1a4d2e] focus:border-transparent" disabled={!token} />
{/* Password Requirements */}

Le mot de passe doit contenir :

  • = 8 ? 'text-green-600' : ''}`}> {password.length >= 8 ? ( ) : ( )} Au moins 8 caractères
  • 0 ? 'text-green-600' : ''}`}> {password === confirmPassword && password.length > 0 ? ( ) : ( )} Les mots de passe correspondent
{/* Submit Button */} {/* Back to Login */}
Retour à la connexion
); } export default function ResetPasswordPage() { return (

Chargement...

}>
); }