import React, { useState } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { useAuth } from '../context/AuthContext'; import { GoogleLogin } from '@react-oauth/google'; import { useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; const AuthPage = () => { const { t } = useTranslation(); const [isLogin, setIsLogin] = useState(true); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [displayName, setDisplayName] = useState(''); const [error, setError] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const { user, login, register, googleLogin } = useAuth(); const navigate = useNavigate(); React.useEffect(() => { if (user) { navigate('/dashboard'); } }, [user, navigate]); const handleSubmit = async (e) => { e.preventDefault(); setError(''); if (!isLogin && password !== confirmPassword) { setError(t('auth.passwords_do_not_match', 'Passwords do not match')); return; } setIsSubmitting(true); let result; if (isLogin) { result = await login(email, password); } else { result = await register(email, password, displayName); } if (result.success) { navigate('/dashboard'); } else { setError(result.message); } setIsSubmitting(false); }; const handleGoogleSuccess = async (credentialResponse) => { setIsSubmitting(true); const result = await googleLogin(credentialResponse.credential); if (result.success) { navigate('/dashboard'); } else { setError(result.message); } setIsSubmitting(false); }; return (
{isLogin ? t('auth.plans_waiting', 'Your plans are waiting for you.') : t('auth.join_revolution', 'Join the visual revolution.')}