'use client'; import { registerPage } from '../registry.js'; import { useState, useEffect, useRef } from 'react'; import { useSearchParams } from 'next/navigation'; import { Card } from '@zen/core/shared/components'; const ConfirmEmailChangePage = () => { const searchParams = useSearchParams(); const token = searchParams.get('token'); const [isLoading, setIsLoading] = useState(true); const [success, setSuccess] = useState(''); const [error, setError] = useState(''); const hasConfirmedRef = useRef(false); useEffect(() => { if (!token) { setError('Lien de confirmation invalide.'); setIsLoading(false); return; } if (hasConfirmedRef.current) return; hasConfirmedRef.current = true; fetch(`/zen/api/users/email/confirm?token=${encodeURIComponent(token)}`, { credentials: 'include' }) .then(res => res.json().then(data => ({ ok: res.ok, data }))) .then(({ ok, data }) => { if (ok && data.success) { setSuccess('Votre adresse courriel a été mise à jour avec succès.'); setTimeout(() => { window.location.href = '/admin/profile'; }, 3000); } else { setError(data.error || data.message || 'Lien de confirmation invalide ou expiré.'); } }) .catch(() => setError('Une erreur inattendue est survenue.')) .finally(() => setIsLoading(false)); }, [token]); return (

Confirmation du courriel

Validation de votre nouvelle adresse courriel...

{isLoading && (

Confirmation en cours...

)} {success && ( <>
{success}

Redirection vers votre profil...

)} {error && (
{error}
)}
); }; export default ConfirmEmailChangePage; registerPage({ slug: 'confirm-email-change', title: 'Confirmation du courriel', Component: ConfirmEmailChangePage });