import { useState } from 'react'; import { useNavigate, Link } from 'react-router-dom'; import { useAuthStore } from '../../store/authStore'; import { Blocks, Eye, EyeOff, Mail, User as UserIcon, Lock, Check } from 'lucide-react'; import GoogleButton from './GoogleButton'; export default function RegisterForm() { const [email, setEmail] = useState(''); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [passwordError, setPasswordError] = useState(''); const [formError, setFormError] = useState(''); const { register, loading, error: storeError, clearError } = useAuthStore(); const navigate = useNavigate(); const displayError = formError || storeError; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setPasswordError(''); setFormError(''); if (password !== confirmPassword) { setPasswordError('Passwords do not match'); return; } if (password.length < 8) { setPasswordError('Password must be at least 8 characters'); return; } try { await register(email, username, password); navigate('/dashboard'); } catch (err: any) { setFormError(err.message || 'Registration failed. Please try again.'); } }; return (
Create your account