"use client"; import { useState, useEffect, useRef } from "react"; import { X, KeyRound, Eye, EyeOff, Loader2, ShieldCheck } from "lucide-react"; interface ChangePasswordModalProps { isOpen: boolean; onClose: () => void; onConfirm: (newPassword: string) => Promise; username: string; } export function ChangePasswordModal({ isOpen, onClose, onConfirm, username, }: ChangePasswordModalProps) { const [password, setPassword] = useState(""); const [confirm, setConfirm] = useState(""); const [showPassword, setShowPassword] = useState(false); const [showConfirm, setShowConfirm] = useState(false); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const [isVisible, setIsVisible] = useState(false); const inputRef = useRef(null); useEffect(() => { if (isOpen) { setIsVisible(true); setPassword(""); setConfirm(""); setError(null); setTimeout(() => inputRef.current?.focus(), 50); } else { setIsVisible(false); } }, [isOpen]); const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Escape") handleClose(); }; const handleClose = () => { setIsVisible(false); setTimeout(onClose, 250); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); if (password.length < 4) { setError("Le mot de passe doit faire au moins 4 caractères."); return; } if (password !== confirm) { setError("Les mots de passe ne correspondent pas."); return; } setIsLoading(true); try { await onConfirm(password); handleClose(); } catch (err: any) { setError(err?.message ?? "Une erreur est survenue."); } finally { setIsLoading(false); } }; if (!isOpen && !isVisible) return null; return (
{/* Backdrop */}
{/* Panel */}
{/* Accent bar */}
{/* Close button */}
{/* Header */}

Changer le mot de passe

Compte : {username}

{/* New password */}
setPassword(e.target.value)} placeholder="Min. 4 caractères" className="apple-input pr-10" required />
{/* Confirm */}
setConfirm(e.target.value)} placeholder="Répétez le mot de passe" className="apple-input pr-10" required />
{/* Password match indicator */} {confirm.length > 0 && (
{password === confirm ? "Les mots de passe correspondent" : "Les mots de passe ne correspondent pas"}
)} {/* Error */} {error && (
{error}
)} {/* Actions */}
); }