diff --git a/src/components/Auth/Login.js b/src/components/Auth/Login.js index fe13b99..1a99e88 100644 --- a/src/components/Auth/Login.js +++ b/src/components/Auth/Login.js @@ -2,21 +2,31 @@ import React, { useState } from 'react'; import '../../styles/components.css'; const Login = ({ onLogin }) => { + const [mode, setMode] = useState('login'); // 'login' | 'register' | 'forgot' + + // Login state const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); + + // Register state + const [name, setName] = useState(''); + const [confirmPassword, setConfirmPassword] = useState(''); + + // Forgot state + const [forgotEmail, setForgotEmail] = useState(''); + const [forgotSent, setForgotSent] = useState(false); - const handleSubmit = (e) => { + const handleLoginSubmit = (e) => { e.preventDefault(); setError(''); - // Validación muy básica if (!email || !password) { setError('Por favor, ingresa tu correo y contraseña.'); return; } - // Aquí iría la llamada real a API. Por ahora, simulamos éxito. + // Simulación de éxito try { localStorage.setItem('auth', 'true'); onLogin?.(); @@ -25,44 +35,190 @@ const Login = ({ onLogin }) => { } }; + const handleRegisterSubmit = (e) => { + e.preventDefault(); + setError(''); + + if (!email || !password) { + setError('Por favor, completa correo y contraseña.'); + return; + } + if (password.length < 6) { + setError('La contraseña debe tener al menos 6 caracteres.'); + return; + } + if (password !== confirmPassword) { + setError('Las contraseñas no coinciden.'); + return; + } + + // Simulación de registro + login automático + try { + localStorage.setItem('auth', 'true'); + onLogin?.(); + } catch (err) { + setError('Ocurrió un error al registrarte.'); + } + }; + + const handleForgotSubmit = (e) => { + e.preventDefault(); + setError(''); + + if (!forgotEmail) { + setError('Por favor, ingresa tu correo.'); + return; + } + + // Simulación de envío de correo + setForgotSent(true); + }; + + const renderLogin = () => ( +
+
+ + setEmail(e.target.value)} + autoFocus={mode === 'login'} + aria-invalid={!!error && (!email || !password)} + /> +
+
+ + setPassword(e.target.value)} + aria-invalid={!!error && (!email || !password)} + /> +
+ + {error &&
{error}
} + + + +
+ + + +
+
+ ); + + const renderRegister = () => ( +
+
+ + setName(e.target.value)} + autoFocus={mode === 'register'} + /> +
+
+ + setEmail(e.target.value)} + aria-invalid={!!error && !email} + /> +
+
+ + setPassword(e.target.value)} + aria-invalid={!!error && password.length < 6} + /> +
+
+ + setConfirmPassword(e.target.value)} + aria-invalid={!!error && password !== confirmPassword} + /> +
+ + {error &&
{error}
} + + +
+ +
+
+ ); + + const renderForgot = () => ( +
+ {!forgotSent ? ( + <> +
+ + setForgotEmail(e.target.value)} + autoFocus={mode === 'forgot'} + aria-invalid={!!error && !forgotEmail} + /> +
+ {error &&
{error}
} + + + ) : ( + <> +
+ Si existe una cuenta con ese correo, recibirás un email con instrucciones para restablecer tu contraseña. +
+
+ +
+ + )} + {!forgotSent && ( +
+ +
+ )} +
+ ); + return (

- - Iniciar Sesión + + {mode === 'login' && 'Iniciar Sesión'} + {mode === 'register' && 'Crear Cuenta'} + {mode === 'forgot' && 'Recuperar Contraseña'}

-
-
- - setEmail(e.target.value)} - autoFocus - aria-invalid={!!error && (!email || !password)} - /> -
-
- - setPassword(e.target.value)} - aria-invalid={!!error && (!email || !password)} - /> -
- - {error &&
{error}
} - - -
+ {mode === 'login' && renderLogin()} + {mode === 'register' && renderRegister()} + {mode === 'forgot' && renderForgot()}
); diff --git a/src/styles/components.css b/src/styles/components.css index 65881e4..1fa650b 100644 --- a/src/styles/components.css +++ b/src/styles/components.css @@ -716,3 +716,30 @@ textarea { max-width: 100%; } } + +/* Auth helpers: links below forms */ +.auth-links { + margin-top: 12px; + display: flex; + align-items: center; + justify-content: center; + gap: 8px; + flex-wrap: wrap; +} + +.auth-links .divider { + color: var(--gray); +} + +.link { + background: none; + border: none; + padding: 0; + color: var(--primary); + cursor: pointer; + font-weight: 600; +} + +.link:hover { + text-decoration: underline; +}