// ============================================================================== // Vista de Inicio de Sesión de Operador / Guardia (OnEverControl Web) // Paridad Visual 1:1 con la versión de escritorio de OneverAccess (login_window.py) // Sistema de Diseño OnEver con Ola Gradiente (Indigo/Blue), Pills inputs y Glassmorphism // ============================================================================== import React, { useState, useEffect } from 'react'; import { useAuth } from '../context/AuthContext'; import { workstationApi, WorkstationListItem } from '../api/workstationApi'; import { useTheme } from '../hooks/useTheme'; import { APP_VERSION, APP_BUILD } from '../version'; export const LoginView: React.FC = () => { const { login, workstation, setWorkstation } = useAuth(); const { theme, toggleTheme } = useTheme(); const [username, setUsername] = useState(() => { return localStorage.getItem('on_ever_username') || 'guardia'; }); const [password, setPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [rememberMe, setRememberMe] = useState(() => { const saved = localStorage.getItem('on_ever_remember_me'); return saved !== null ? saved === 'true' : true; }); const [selectedWks, setSelectedWks] = useState(workstation || 'CFT-DESK'); const [availableWorkstations, setAvailableWorkstations] = useState([]); const [isLoading, setIsLoading] = useState(false); const [errorMsg, setErrorMsg] = useState(null); const isDark = theme === 'dark'; useEffect(() => { // Carga de Workstations reales desde SQL Server workstationApi .getAvailableWorkstations() .then((list) => { if (list && list.length > 0) { setAvailableWorkstations(list); const currentMatch = list.find( (w) => w.name.toUpperCase() === (workstation || 'CFT-DESK').toUpperCase() ); if (currentMatch) { setSelectedWks(currentMatch.name); } else { setSelectedWks(list[0].name); } } }) .catch((err) => { console.warn('No se pudieron listar estaciones desde DB:', err); }); }, [workstation]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!username.trim() || !password) { setErrorMsg('Ingrese usuario y contraseña'); return; } setIsLoading(true); setErrorMsg(null); try { setWorkstation(selectedWks); await login(username.trim(), password, selectedWks, rememberMe); } catch (err: any) { setErrorMsg(err.message || 'Credenciales inválidas. Verifique usuario o contraseña.'); } finally { setIsLoading(false); } }; const toggleFullscreen = () => { if (!document.fullscreenElement) { document.documentElement.requestFullscreen().catch(() => {}); } else { document.exitFullscreen().catch(() => {}); } }; return (
{/* Botones Flotantes de Utilidades (Tema y Pantalla Completa) */}
{/* Tarjeta de Login (Paridad con LoginBackgroundFrame de OneverAccess Desktop) */}
{/* Onda Decorativa Superior con Gradiente Curvo (Idéntica a LoginBackgroundFrame) */}
{isDark ? ( <> {/* Indigo */} {/* Blue */} ) : ( <> {/* Purple */} {/* Light Blue */} )} {/* Curva Bezier cúbica idéntica al painter.cubicTo de PyQt6 */}
{/* Contenido Principal del Formulario */}
{/* Logo Corporativo OneverAccess */}
OnEver Access { (e.target as HTMLImageElement).src = '/logo_mini.png'; }} />
{/* Formulario */}
{/* Puesto de Control / Workstation (Pill Shape) */}
{/* Campo Usuario (Pill Shape) */}
setUsername(e.target.value)} placeholder="Username" autoCapitalize="none" autoCorrect="off" required style={{ width: '100%', height: '46px', borderRadius: '23px', backgroundColor: isDark ? '#1E293B' : '#F8FAFC', border: `1px solid ${isDark ? '#374151' : '#CBD5E1'}`, color: isDark ? '#F8FAFC' : '#0F172A', padding: '0 20px', fontSize: '0.925rem', fontWeight: 500, outline: 'none', transition: 'border-color 0.2s, box-shadow 0.2s', }} onFocus={(e) => { e.currentTarget.style.borderColor = '#2563EB'; e.currentTarget.style.boxShadow = '0 0 0 3px rgba(37, 99, 235, 0.2)'; }} onBlur={(e) => { e.currentTarget.style.borderColor = isDark ? '#374151' : '#CBD5E1'; e.currentTarget.style.boxShadow = 'none'; }} />
{/* Campo Contraseña con Botón de Ojo (Pill Shape) */}
setPassword(e.target.value)} placeholder="Password" required style={{ flex: 1, height: '100%', border: 'none', backgroundColor: 'transparent', color: isDark ? '#F8FAFC' : '#0F172A', padding: '0 0 0 20px', fontSize: '0.925rem', fontWeight: 500, outline: 'none', }} onFocus={() => { const el = document.getElementById('passwordContainer'); if (el) { el.style.borderColor = '#2563EB'; el.style.boxShadow = '0 0 0 3px rgba(37, 99, 235, 0.2)'; } }} onBlur={() => { const el = document.getElementById('passwordContainer'); if (el) { el.style.borderColor = isDark ? '#374151' : '#CBD5E1'; el.style.boxShadow = 'none'; } }} />
{/* Checkbox: Recordar sesión y permanecer conectado (PWA / Tablets) */}
(Guardar sesión)
{/* Mensaje de Error (si ocurre) */} {errorMsg && (
⚠️ {errorMsg}
)} {/* Botón Ingresar / Login (Pill Shape estilo OnEver Desktop) */}
{/* Pie Informativo y Estado de Conexión */}
{ (e.target as HTMLElement).style.display = 'none'; }} /> OnEver Access · Control Web {APP_VERSION} {APP_BUILD}
● Conectado a Microsoft SQL Server (Transaccional)
); };