const { useState } = React; window.LoginView = function({ setView, setProfile, hasUsers }) { const [email, setEmail] = useState(''); const [pass, setPass] = useState(''); const [name, setName] = useState(''); const [error, setError] = useState(''); const handleLogin = async (e) => { e.preventDefault(); setError(''); // Llamada a la API unificada para login (soporta Alias, Email o Código de trabajador) const res = await window.apiCall('login', { email_or_alias: email, password: pass }); if (res.success) { const found = res.profile; setProfile(found); localStorage.setItem('shift_active_session', JSON.stringify({ profile: found, expiresAt: Date.now() + (9 * 60 * 60 * 1000) })); setView(found.role === 'admin' || found.role === 'dueño' || found.role === 'propietario' ? 'admin' : 'dashboard'); } else { setError(res.error || "Credenciales incorrectas."); } }; return (
Acceso a Portal de Asistencia