import { useState, type FormEvent } from 'react'; import { Link, useNavigate, useSearchParams } from 'react-router-dom'; import { useSession } from '@/entities/session'; export function RegisterPage() { const navigate = useNavigate(); const [searchParams] = useSearchParams(); const { register } = useSession(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [name, setName] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const redirect = searchParams.get('redirect') || '/'; async function handleSubmit(e: FormEvent) { e.preventDefault(); setError(''); if (password !== confirmPassword) { setError('Пароли не совпадают'); return; } setLoading(true); try { await register(email, password, name || undefined); navigate(redirect); } catch (err) { setError(err instanceof Error ? err.message : 'Ошибка регистрации'); } finally { setLoading(false); } } return (

Регистрация

{error &&
{error}
}
setName(e.target.value)} style={inputStyle} placeholder="Иван Иванов" />
setEmail(e.target.value)} required style={inputStyle} placeholder="email@example.com" />
setPassword(e.target.value)} required minLength={6} style={inputStyle} placeholder="Минимум 6 символов" />
setConfirmPassword(e.target.value)} required style={inputStyle} placeholder="Повторите пароль" />

Уже есть аккаунт?{' '} Войти

); } const inputStyle: React.CSSProperties = { width: '100%', padding: '10px 12px', border: '1px solid #e0e0e0', borderRadius: 'var(--border-radius)', fontSize: 16, outline: 'none', boxSizing: 'border-box', }; const buttonStyle: React.CSSProperties = { padding: '12px 24px', background: 'var(--color-primary)', color: '#fff', border: 'none', borderRadius: 'var(--border-radius)', fontSize: 16, fontWeight: 600, cursor: 'pointer', };