const { useState } = React; window.LoginView = function({ setProfile, setView, onLogin, setUser }) { const [emailOrAlias, setEmailOrAlias] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [errorMsg, setErrorMsg] = useState(''); const isLogoEnabled = window.SHIFT_CONFIG?.showCompanyLogo !== false && window.SHIFT_CONFIG?.showCompanyLogo !== 0; const logoToDisplay = isLogoEnabled ? (window.SHIFT_CONFIG?.companyLogo || '') : ''; const companyTitle = window.SHIFT_CONFIG?.companyName || 'Shift Central'; const handleSubmit = async (e) => { e.preventDefault(); setErrorMsg(''); setLoading(true); try { const res = await window.apiCall('login', { email_or_alias: emailOrAlias, password: password }); if (res && res.success && res.profile) { const profile = res.profile; // 1. Guardar sesión y estampa de tiempo try { localStorage.setItem('shift_user', JSON.stringify(profile)); localStorage.setItem('shift_session_time', Date.now().toString()); } catch (eStorage) {} // 2. Asignar perfil al estado central const loginFn = setProfile || onLogin || setUser; if (typeof loginFn === 'function') { loginFn(profile); } if (typeof setView === 'function') { const r = (profile.role || profile.role_name || '').toLowerCase(); const isOwnerOrAdmin = r === 'propietario' || r === 'admin' || r === 'dueño' || window.SHIFT_CONFIG?.isMaster; setView(isOwnerOrAdmin ? 'admin' : 'dashboard'); } } else { setErrorMsg(res?.error || "Credenciales incorrectas."); } } catch (err) { setErrorMsg("Error de conexión con el servidor: " + err.message); } finally { setLoading(false); } }; return (
Acceso a Portal de Asistencia y Turnos
Shift Marcas • Control Operativo Empresarial