'use client'; import { useState } from 'react'; import Link from 'next/link'; import { Eye, EyeOff, Mail, Lock, ArrowRight, Loader2, CheckCircle, AlertTriangle, UserPlus, Languages, User, } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { useRegister } from './useRegister'; import { cn } from '@/lib/utils'; function validateEmail(email: string) { return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); } function validatePassword(password: string) { return password.length >= 8; } function getPasswordStrength(password: string) { if (password.length === 0) return { score: 0, label: '', color: '' }; let score = 0; if (password.length >= 8) score++; if (password.length >= 12) score++; if (/[A-Z]/.test(password)) score++; if (/[a-z]/.test(password)) score++; if (/[0-9]/.test(password)) score++; if (/[^A-Za-z0-9]/.test(password)) score++; if (score <= 2) return { score, label: 'Faible', color: 'bg-destructive' }; if (score <= 4) return { score, label: 'Moyen', color: 'bg-yellow-500' }; return { score, label: 'Fort', color: 'bg-green-500' }; } function PasswordToggleIcon({ visible, onToggle, label }: { visible: boolean; onToggle: () => void; label: string }) { return ( ); } export function RegisterForm() { const [name, setName] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [showConfirm, setShowConfirm] = useState(false); const [touched, setTouched] = useState({ name: false, email: false, password: false, confirmPassword: false }); const registerMutation = useRegister(); const nameError = touched.name && name.length > 0 && name.length < 2 ? 'Le nom doit contenir au moins 2 caractères' : undefined; const emailError = touched.email && email.length > 0 && !validateEmail(email) ? 'Adresse email invalide' : undefined; const passwordError = touched.password && password.length > 0 && !validatePassword(password) ? 'Mot de passe trop court (minimum 8 caractères)' : undefined; const confirmError = touched.confirmPassword && confirmPassword.length > 0 && password !== confirmPassword ? 'Les mots de passe ne correspondent pas' : undefined; const passwordStrength = getPasswordStrength(password); const isFormValid = name.length >= 2 && validateEmail(email) && validatePassword(password) && password === confirmPassword; const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); setTouched({ name: true, email: true, password: true, confirmPassword: true }); if (!isFormValid) return; registerMutation.mutate({ name, email, password }); }; const getConfirmRightIcon = () => { if (touched.confirmPassword && confirmPassword.length > 0 && password === confirmPassword) { return ; } return ( setShowConfirm(!showConfirm)} label={showConfirm ? 'Masquer' : 'Afficher'} /> ); }; return (
Office Translator Créer un compte Commencez à traduire gratuitement
{registerMutation.isError && (

{registerMutation.error?.message || "L'inscription a échoué"}

)}
setName(e.target.value)} onBlur={() => setTouched((t) => ({ ...t, name: true }))} leftIcon={} rightIcon={ touched.name && name.length > 0 ? name.length >= 2 ? : : undefined } error={nameError} required autoComplete="name" />
setEmail(e.target.value)} onBlur={() => setTouched((t) => ({ ...t, email: true }))} leftIcon={} rightIcon={ touched.email && email.length > 0 ? validateEmail(email) ? : : undefined } error={emailError} required autoComplete="email" />
setPassword(e.target.value)} onBlur={() => setTouched((t) => ({ ...t, password: true }))} leftIcon={} rightIcon={ setShowPassword(!showPassword)} label={showPassword ? 'Masquer le mot de passe' : 'Afficher le mot de passe'} /> } error={passwordError} required minLength={8} autoComplete="new-password" /> {password.length > 0 && (
{[1, 2, 3, 4].map((level) => (
))}

Force : {passwordStrength.label}

)}
setConfirmPassword(e.target.value)} onBlur={() => setTouched((t) => ({ ...t, confirmPassword: true }))} leftIcon={} rightIcon={getConfirmRightIcon()} error={confirmError} required autoComplete="new-password" />

Vous avez déjà un compte ?{' '} Se connecter

En créant un compte, vous acceptez notre{' '} utilisation du service .

); }