feat(real-data): carga dinamica de workstations y tickets/movimientos reales desde SQL Server
This commit is contained in:
@@ -2,17 +2,38 @@
|
||||
// Vista de Inicio de Sesión de Operador / Guardia
|
||||
// Optimizado para uso táctil en tablets Samsung Galaxy Tab (Touch-First)
|
||||
// ==============================================================================
|
||||
import React, { useState } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useAuth } from '../context/AuthContext';
|
||||
import { workstationApi, WorkstationListItem } from '../api/workstationApi';
|
||||
|
||||
export const LoginView: React.FC = () => {
|
||||
const { login, workstation, setWorkstation } = useAuth();
|
||||
const [username, setUsername] = useState<string>('guardia');
|
||||
const [password, setPassword] = useState<string>('');
|
||||
const [selectedWks, setSelectedWks] = useState<string>(workstation || 'CFT-DESK');
|
||||
const [availableWorkstations, setAvailableWorkstations] = useState<WorkstationListItem[]>([]);
|
||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||
const [errorMsg, setErrorMsg] = useState<string | null>(null);
|
||||
|
||||
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) {
|
||||
@@ -98,7 +119,7 @@ export const LoginView: React.FC = () => {
|
||||
)}
|
||||
|
||||
<form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column', gap: '1.25rem' }}>
|
||||
{/* Selector de Workstation / Garita */}
|
||||
{/* Selector de Workstation Real desde SQL Server */}
|
||||
<div>
|
||||
<label
|
||||
style={{
|
||||
@@ -117,10 +138,15 @@ export const LoginView: React.FC = () => {
|
||||
onChange={(e) => setSelectedWks(e.target.value)}
|
||||
style={{ width: '100%' }}
|
||||
>
|
||||
<option value="CFT-DESK">CFT-DESK (Garita Principal)</option>
|
||||
<option value="GARITA_SUR">GARITA_SUR</option>
|
||||
<option value="GARITA_NORTE">GARITA_NORTE</option>
|
||||
<option value="ACCESO_PROVEEDORES">ACCESO_PROVEEDORES</option>
|
||||
{availableWorkstations.length > 0 ? (
|
||||
availableWorkstations.map((w) => (
|
||||
<option key={w.id} value={w.name}>
|
||||
{w.name} (ID {w.id})
|
||||
</option>
|
||||
))
|
||||
) : (
|
||||
<option value="CFT-DESK">CFT-DESK (ID 100001)</option>
|
||||
)}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -192,7 +218,7 @@ export const LoginView: React.FC = () => {
|
||||
</form>
|
||||
|
||||
<div style={{ marginTop: '2rem', textAlign: 'center', fontSize: '0.75rem', color: 'var(--text-muted)' }}>
|
||||
OnEverControl Web v0.5.0-beta • Samsung Galaxy Tab Ready
|
||||
OnEverControl Web v0.6.0-beta • Conectado a Microsoft SQL Server videoman
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user