import { useState } from 'react'; import { Link, useNavigate, useSearchParams } from 'react-router-dom'; import { useAuth } from '../contexts/AuthContext'; import { useLanguage } from '../contexts/LanguageContext'; import { useBranding } from '../contexts/BrandingContext'; import { Mail, Lock, User, ArrowRight, Loader2, CheckCircle, ShieldAlert, LogIn } from 'lucide-react'; import BrandLogo from '../components/BrandLogo'; import toast from 'react-hot-toast'; export default function Register() { const [searchParams] = useSearchParams(); const inviteToken = searchParams.get('invite') || ''; const [username, setUsername] = useState(''); const [displayName, setDisplayName] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [loading, setLoading] = useState(false); const [needsVerification, setNeedsVerification] = useState(false); const { register } = useAuth(); const { t } = useLanguage(); const { registrationMode, oauthEnabled, oauthDisplayName } = useBranding(); const navigate = useNavigate(); // Invite-only mode without a token → show blocked message const isBlocked = registrationMode === 'invite' && !inviteToken; const handleSubmit = async (e) => { e.preventDefault(); if (password !== confirmPassword) { toast.error(t('auth.passwordMismatch')); return; } if (password.length < 8) { toast.error(t('auth.passwordTooShort')); return; } setLoading(true); try { const result = await register(username, displayName, email, password, inviteToken); if (result?.needsVerification) { setNeedsVerification(true); toast.success(t('auth.verificationSent')); } else { toast.success(t('auth.registerSuccess')); navigate('/dashboard'); } } catch (err) { toast.error(err.response?.data?.error || t('auth.registerFailed')); } finally { setLoading(false); } }; return (
{/* Animated background */}
{/* Register card */}
{/* Logo */}
{needsVerification ? (

{t('auth.checkYourEmail')}

{t('auth.verificationSentDesc')}

{email}

{t('auth.login')}
) : isBlocked ? (

{t('auth.inviteOnly')}

{t('auth.inviteOnlyDesc')}

{t('auth.login')}
) : ( <>

{t('auth.createAccount')}

{t('auth.registerSubtitle')}

setUsername(e.target.value)} className="input-field pl-11" placeholder={t('auth.usernamePlaceholder')} required />

{t('auth.usernameHint')}

setDisplayName(e.target.value)} className="input-field pl-11" placeholder={t('auth.displayNamePlaceholder')} required />
setEmail(e.target.value)} className="input-field pl-11" placeholder={t('auth.emailPlaceholder')} required />
setPassword(e.target.value)} className="input-field pl-11" placeholder={t('auth.minPassword')} required minLength={6} />
setConfirmPassword(e.target.value)} className="input-field pl-11" placeholder={t('auth.repeatPassword')} required minLength={6} />
{oauthEnabled && ( <>
{t('auth.orContinueWith')}
{t('auth.registerWithOAuth').replace('{provider}', oauthDisplayName || 'SSO')} )}

{t('auth.hasAccount')}{' '} {t('auth.signInNow')}

{t('auth.backToHome')} )}
); }