Rediseño visual de panel.html (piel cream de escritorio) sobre theme.js
Reconstruye el panel de la supervisora con el lenguaje visual del diseño a
densidad de escritorio (paleta crema, tipografías, íconos de línea, logo) sin
tocar la lógica ni el cableado al backend.
theme.js:
- Nuevo set "cream de escritorio" que devuelve makeUI("panel"): reusa la
paleta/fuentes/íconos cream y añade lo propio del panel —Nav superior,
Table/Tr/Td, ProgressBar, Modal, EmptyState, Toggle, ErrorBar y Btn/Input/
Badge/Aviso densos. Íconos nuevos: plus, chevronLeft, x, users, listCheck.
- Independiente de makeCream (móvil): checada y becario no se ven afectados.
panel.html:
- Migra login, shell con navegación, tabla de becarios, detalle
(avance/jornadas/ajustes/checadas), configuración y solicitudes a los
componentes cream. ~20 estados del inventario, cada uno por su MISMO
code/estado. Endpoints, campos (becario/jornada/ajuste/config), guardia de
sesión de supervisora, mapeo de errores y el cálculo de horas en el backend
sin cambios.
- prompt()/confirm() del navegador convertidos a modales propios con el mismo
patrón (editar jornada, cerrar, autorizar/rechazar, baja, alta/edición de
becario); la llamada al backend por detrás no cambia.
- Notas intencionales conservadas: "calculado por el backend", "las jornadas
en revisión no suman", "IP y user-agent… no prueba de ubicación". La columna
User-agent de checadas se conserva. Sin marcos de navegador.
checada.html y becario.html quedan byte-idénticos.
This commit is contained in:
1 parent
2e72187c5d
commit
ae27ed6e69
2 files changed
+515
-311
No files matched your search
+306
-310
@@ -4,23 +4,32 @@
|
||||
<meta charset="UTF-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>Taboada — Panel de supervisión</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com"/>
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,600;12..96,700&family=Figtree:wght@400;500;600;700&display=swap" rel="stylesheet"/>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.23.2/babel.min.js"></script>
|
||||
<script src="theme.js"></script>
|
||||
<style>
|
||||
* { box-sizing: border-box; }
|
||||
html, body { margin: 0; padding: 0; }
|
||||
body { background: #F3EBDD; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
|
||||
input::placeholder { color: #B4A99A; }
|
||||
@keyframes tb-spin { to { transform: rotate(360deg); } }
|
||||
</style>
|
||||
</head>
|
||||
<body style="margin:0;padding:0;">
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="text/babel" data-presets="react">
|
||||
const { useState, useEffect, useCallback } = React;
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// API — el panel se sirve detrás de nginx (mismo origen); nginx hace
|
||||
// proxy_pass de /api al servicio node. credentials:'include' manda la
|
||||
// cookie de sesión de la supervisora en cada request.
|
||||
// Cableado al backend (SIN cambios). El panel se sirve detrás de nginx
|
||||
// (mismo origen); credentials:'include' manda la cookie de sesión de la
|
||||
// supervisora en cada request.
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
const API_BASE = `${window.location.origin}/api`;
|
||||
|
||||
async function apiFetch(path, options = {}) {
|
||||
const res = await fetch(`${API_BASE}${path}`, {
|
||||
credentials: "include",
|
||||
@@ -30,18 +39,18 @@ async function apiFetch(path, options = {}) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
const err = new Error(data.error || `HTTP ${res.status}`);
|
||||
err.code = data.code;
|
||||
err.status = res.status;
|
||||
err.code = data.code; err.status = res.status;
|
||||
throw err;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
// Base visual compartida (theme.js), ligada al flavor 'panel'.
|
||||
const { COLORS, FONT, SPACE, RADIUS, makeUI } = Theme;
|
||||
const { Btn, Card, Input, Badge, Field, Estado } = makeUI("panel");
|
||||
// Piel cream de escritorio (theme.js, flavor 'panel'). Nada de colores inline.
|
||||
const UI = Theme.makeUI("panel");
|
||||
const { Logo, Card, Btn, Input, Field, Badge, Aviso, ErrorBar, Toggle, ProgressBar,
|
||||
Nav, Table, Tr, Td, Modal, EmptyState, palette, fonts, icons } = UI;
|
||||
|
||||
// ── Formato (presentación en America/Mexico_City, §7) ──
|
||||
// ── Formato (presentación en America/Mexico_City) ──
|
||||
function fmtDT(iso) {
|
||||
if (!iso) return "—";
|
||||
return new Date(iso).toLocaleString("es-MX", {
|
||||
@@ -58,51 +67,59 @@ function isoToLocal(iso) {
|
||||
}
|
||||
function localToIso(v) { return v ? new Date(v).toISOString() : null; }
|
||||
|
||||
// ErrorBar y los helpers de tono son locales del panel (no compartidos).
|
||||
const ErrorBar = ({ error, onClose }) => !error ? null : (
|
||||
<div style={{ background: COLORS.dangerBg, color: COLORS.danger, padding: "10px 14px", borderRadius: "8px",
|
||||
fontSize: "14px", marginBottom: "14px", display: "flex", justifyContent: "space-between", alignItems: "center" }}>
|
||||
<span>⚠ {error}</span>
|
||||
<span onClick={onClose} style={{ cursor: "pointer", fontWeight: 700, paddingLeft: "12px" }}>✕</span>
|
||||
</div>
|
||||
);
|
||||
// Mapeo estado → tono del Badge (el Badge cream traduce el tono a color).
|
||||
const estadoBecarioTone = (e) => ({ activo: "success", pendiente: "warn", baja: "chip" }[e] || "chip");
|
||||
const estadoJornadaTone = (e) => ({ abierta: "primary", cerrada: "success", revision: "warn" }[e] || "chip");
|
||||
const estadoDispTone = (e) => ({ pendiente: "warn", aprobado: "success", revocado: "danger" }[e] || "chip");
|
||||
|
||||
const iconBtn = (name, o) => <span style={{ display: "inline-flex" }}>{icons[name](o)}</span>;
|
||||
|
||||
// ── Modal de confirmación (sustituye el diálogo nativo del navegador) ──
|
||||
// La llamada al backend vive en `onConfirm` (el padre); aquí solo la UI.
|
||||
function ConfirmModal({ title, message, confirmLabel, variant, onConfirm, onCancel }) {
|
||||
const [busy, setBusy] = useState(false);
|
||||
const go = async () => { setBusy(true); try { await onConfirm(); } finally { setBusy(false); } };
|
||||
return (
|
||||
<Modal title={title} onClose={onCancel} width={400}>
|
||||
<p style={{ margin: "0 0 20px", fontFamily: fonts.body, fontSize: "14px", color: palette.ink, lineHeight: 1.5 }}>{message}</p>
|
||||
<div style={{ display: "flex", gap: "9px" }}>
|
||||
<Btn variant={variant || "primary"} loading={busy} onClick={go}>{confirmLabel || "Confirmar"}</Btn>
|
||||
<Btn variant="outline" onClick={onCancel}>Cancelar</Btn>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
// ═══════════════════ Login ═══════════════════
|
||||
function Login({ onLogin }) {
|
||||
const [usuario, setUsuario] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [error, setError] = useState(null);
|
||||
const [error, setError] = useState(null); // { text, ic }
|
||||
const [busy, setBusy] = useState(false);
|
||||
const submit = async (e) => {
|
||||
e.preventDefault();
|
||||
setBusy(true); setError(null);
|
||||
e.preventDefault(); setBusy(true); setError(null);
|
||||
try {
|
||||
await apiFetch("/auth/login", { method: "POST", body: JSON.stringify({ usuario, password }) });
|
||||
const s = await apiFetch("/auth/session");
|
||||
onLogin(s);
|
||||
onLogin(await apiFetch("/auth/session"));
|
||||
} catch (err) {
|
||||
setError(err.status === 429 ? "Demasiados intentos. Espera un minuto." : "Usuario o contraseña incorrectos.");
|
||||
// Mismo mapeo por status de siempre; el ícono sólo acompaña.
|
||||
setError(err.status === 429
|
||||
? { text: "Demasiados intentos. Espera un minuto.", ic: "clock" }
|
||||
: { text: "Usuario o contraseña incorrectos.", ic: "alertCircle" });
|
||||
} finally { setBusy(false); }
|
||||
};
|
||||
return (
|
||||
<div style={{ minHeight: "100vh", background: COLORS.bg, display: "flex", alignItems: "center",
|
||||
justifyContent: "center", fontFamily: FONT, padding: "24px" }}>
|
||||
<Card style={{ width: "100%", maxWidth: "380px" }}>
|
||||
<h1 style={{ margin: "0 0 4px", fontSize: "22px", color: COLORS.ink }}>Taboada</h1>
|
||||
<p style={{ margin: "0 0 20px", fontSize: "14px", color: COLORS.inkSoft }}>Panel de supervisión</p>
|
||||
<ErrorBar error={error} onClose={() => setError(null)} />
|
||||
<div style={{ minHeight: "100vh", background: palette.bgGradient, display: "flex", alignItems: "center", justifyContent: "center", fontFamily: fonts.body, padding: "24px" }}>
|
||||
<Card style={{ width: "100%", maxWidth: "400px", borderRadius: "24px", padding: "36px 34px" }}>
|
||||
<div style={{ display: "flex", justifyContent: "center", marginBottom: "18px" }}><Logo style={{ height: "60px" }} /></div>
|
||||
<h1 style={{ margin: "0 0 3px", fontFamily: fonts.title, fontWeight: 600, fontSize: "24px", color: palette.brand, textAlign: "center", letterSpacing: "-.01em" }}>Taboada</h1>
|
||||
<p style={{ margin: "0 0 24px", fontFamily: fonts.body, fontSize: "14px", color: palette.inkSoft, textAlign: "center" }}>Panel de supervisión</p>
|
||||
{error && <Aviso variant="error" icon={error.ic}>{error.text}</Aviso>}
|
||||
<form onSubmit={submit}>
|
||||
<Field label="Usuario">
|
||||
<Input value={usuario} onChange={(e) => setUsuario(e.target.value)} autoFocus autoComplete="username" />
|
||||
</Field>
|
||||
<Field label="Contraseña">
|
||||
<Input type="password" value={password} onChange={(e) => setPassword(e.target.value)} autoComplete="current-password" />
|
||||
</Field>
|
||||
<Field label="Usuario"><Input value={usuario} onChange={(e) => setUsuario(e.target.value)} autoFocus autoComplete="username" /></Field>
|
||||
<Field label="Contraseña"><Input type="password" value={password} onChange={(e) => setPassword(e.target.value)} autoComplete="current-password" /></Field>
|
||||
<div style={{ marginTop: "8px" }}>
|
||||
<Btn type="submit" disabled={busy || !usuario || !password}>{busy ? "Entrando…" : "Iniciar sesión"}</Btn>
|
||||
<Btn type="submit" block loading={busy} disabled={busy || !usuario || !password}>{busy ? "Entrando…" : "Iniciar sesión"}</Btn>
|
||||
</div>
|
||||
</form>
|
||||
</Card>
|
||||
@@ -111,32 +128,30 @@ function Login({ onLogin }) {
|
||||
}
|
||||
|
||||
// ═══════════════════ Cola de aprobación de becarios ═══════════════════
|
||||
// Los becarios se auto-registran (celular+password) y quedan 'pendiente'
|
||||
// hasta que la supervisora los aprueba (§4). Sin vínculo de dispositivo.
|
||||
function ColaAprobacion({ pendientes, onAprobar }) {
|
||||
if (pendientes.length === 0) return null;
|
||||
return (
|
||||
<Card style={{ marginBottom: "18px", borderColor: COLORS.warn, background: COLORS.warnBg }}>
|
||||
<h3 style={{ margin: "0 0 12px", fontSize: "15px", color: COLORS.warn }}>
|
||||
Becarios pendientes de aprobar ({pendientes.length})
|
||||
</h3>
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: "8px" }}>
|
||||
<div style={{ background: palette.warnBg, border: `1px solid ${palette.warnBorder}`, borderRadius: "18px", padding: "18px 20px", marginBottom: "20px" }}>
|
||||
<div style={{ display: "flex", alignItems: "center", gap: "9px", marginBottom: "13px" }}>
|
||||
{iconBtn("alertTriangle", { size: 19, color: palette.amber })}
|
||||
<span style={{ fontFamily: fonts.title, fontWeight: 600, fontSize: "15px", color: palette.warnText }}>Becarios pendientes de aprobar ({pendientes.length})</span>
|
||||
</div>
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: "9px" }}>
|
||||
{pendientes.map((b) => (
|
||||
<div key={b.id} style={{ display: "flex", alignItems: "center", justifyContent: "space-between",
|
||||
background: COLORS.surface, borderRadius: "8px", padding: "10px 12px", gap: "10px", flexWrap: "wrap" }}>
|
||||
<div style={{ fontSize: "14px", color: COLORS.ink }}>
|
||||
<strong>{b.nombre}</strong>
|
||||
<div style={{ fontSize: "12px", color: COLORS.inkSoft, marginTop: "2px" }}>{b.telefono || "sin teléfono"}</div>
|
||||
<div key={b.id} style={{ display: "flex", alignItems: "center", justifyContent: "space-between", background: palette.surface, borderRadius: "12px", padding: "11px 14px", gap: "10px", flexWrap: "wrap" }}>
|
||||
<div>
|
||||
<strong style={{ fontFamily: fonts.body, fontWeight: 600, fontSize: "14px", color: palette.ink }}>{b.nombre}</strong>
|
||||
<div style={{ fontFamily: fonts.body, fontSize: "12px", color: palette.inkSoft, marginTop: "2px" }}>{b.telefono || "sin teléfono"}</div>
|
||||
</div>
|
||||
<Btn size="sm" variant="success" onClick={() => onAprobar(b)}>Aprobar</Btn>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ═══════════════════ Formulario de becario (alta/edición) ═══════════════════
|
||||
// ═══════════════════ Formulario de becario (modal alta/edición) ═══════════════════
|
||||
function BecarioForm({ inicial, onSaved, onCancel, onError }) {
|
||||
const [f, setF] = useState({
|
||||
nombre: inicial?.nombre || "", matricula: inicial?.matricula || "",
|
||||
@@ -159,96 +174,84 @@ function BecarioForm({ inicial, onSaved, onCancel, onError }) {
|
||||
} catch (err) { onError(err.message); } finally { setBusy(false); }
|
||||
};
|
||||
return (
|
||||
<Card style={{ marginBottom: "18px" }}>
|
||||
<h3 style={{ margin: "0 0 14px", fontSize: "16px", color: COLORS.ink }}>{inicial ? "Editar becario" : "Nuevo becario"}</h3>
|
||||
<Modal title={inicial ? "Editar becario" : "Nuevo becario"} onClose={onCancel} width={540}>
|
||||
<form onSubmit={submit}>
|
||||
<div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(180px,1fr))", gap: "0 16px" }}>
|
||||
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "0 18px" }}>
|
||||
<Field label="Nombre"><Input value={f.nombre} onChange={set("nombre")} required autoFocus /></Field>
|
||||
<Field label="Matrícula"><Input value={f.matricula} onChange={set("matricula")} /></Field>
|
||||
<Field label="Institución"><Input value={f.institucion} onChange={set("institucion")} /></Field>
|
||||
<Field label="Matrícula"><Input value={f.matricula} onChange={set("matricula")} placeholder="Opcional" /></Field>
|
||||
<Field label="Institución"><Input value={f.institucion} onChange={set("institucion")} placeholder="Opcional" /></Field>
|
||||
<Field label="Meta de horas"><Input type="number" min="1" value={f.meta_horas} onChange={set("meta_horas")} required /></Field>
|
||||
</div>
|
||||
<div style={{ display: "flex", gap: "8px", marginTop: "6px" }}>
|
||||
<Btn type="submit" disabled={busy || !f.nombre.trim()}>{busy ? "Guardando…" : "Guardar"}</Btn>
|
||||
<Btn variant="subtle" onClick={onCancel}>Cancelar</Btn>
|
||||
<div style={{ display: "flex", gap: "9px", marginTop: "4px" }}>
|
||||
<Btn type="submit" loading={busy} disabled={busy || !f.nombre.trim()}>{busy ? "Guardando…" : "Guardar"}</Btn>
|
||||
<Btn variant="outline" onClick={onCancel}>Cancelar</Btn>
|
||||
</div>
|
||||
</form>
|
||||
</Card>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
// ═══════════════════ Vista de becarios ═══════════════════
|
||||
function VistaBecarios({ onOpen, onError }) {
|
||||
const [becarios, setBecarios] = useState(null);
|
||||
const [form, setForm] = useState(null); // null | {} (nuevo) | becario (editar)
|
||||
const [form, setForm] = useState(null); // null | {} (nuevo) | becario (editar)
|
||||
const [confirmBaja, setConfirmBaja] = useState(null);
|
||||
const load = useCallback(async () => {
|
||||
try { setBecarios(await apiFetch("/becarios")); } catch (e) { onError(e.message); }
|
||||
}, [onError]);
|
||||
useEffect(() => { load(); }, [load]);
|
||||
const baja = async (b) => {
|
||||
if (!confirm(`¿Dar de baja a ${b.nombre}? Conserva su historial, no se elimina.`)) return;
|
||||
try { await apiFetch(`/becarios/${b.id}/baja`, { method: "POST" }); await load(); } catch (e) { onError(e.message); }
|
||||
const doBaja = async (b) => {
|
||||
try { await apiFetch(`/becarios/${b.id}/baja`, { method: "POST" }); setConfirmBaja(null); await load(); }
|
||||
catch (e) { onError(e.message); setConfirmBaja(null); }
|
||||
};
|
||||
const aprobar = async (b) => {
|
||||
try { await apiFetch(`/becarios/${b.id}/aprobar`, { method: "POST" }); await load(); } catch (e) { onError(e.message); }
|
||||
};
|
||||
const pendientes = (becarios || []).filter((b) => b.estado === "pendiente");
|
||||
const nuevoBtn = (size) => <Btn size={size} onClick={() => setForm({})}>{iconBtn("plus", { size: 16, color: "#fff", sw: 2.2 })}Nuevo becario</Btn>;
|
||||
return (
|
||||
<div>
|
||||
<ColaAprobacion pendientes={pendientes} onAprobar={aprobar} />
|
||||
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: "14px" }}>
|
||||
<h2 style={{ margin: 0, fontSize: "18px", color: COLORS.ink }}>Becarios</h2>
|
||||
{!form && <Btn onClick={() => setForm({})}>+ Nuevo becario</Btn>}
|
||||
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: "16px" }}>
|
||||
<h2 style={{ margin: 0, fontFamily: fonts.title, fontWeight: 600, fontSize: "22px", color: palette.brand, letterSpacing: "-.01em" }}>Becarios</h2>
|
||||
{nuevoBtn()}
|
||||
</div>
|
||||
{form && <BecarioForm inicial={form.id ? form : null}
|
||||
onSaved={() => { setForm(null); load(); }} onCancel={() => setForm(null)} onError={onError} />}
|
||||
{becarios === null ? <p style={{ color: COLORS.inkSoft }}>Cargando…</p> :
|
||||
becarios.length === 0 ? <Card><p style={{ margin: 0, color: COLORS.inkSoft }}>Aún no hay becarios. Crea el primero.</p></Card> :
|
||||
<Card style={{ padding: 0, overflow: "hidden" }}>
|
||||
<div style={{ overflowX: "auto" }}>
|
||||
<table style={{ width: "100%", borderCollapse: "collapse", fontFamily: FONT, fontSize: "14px" }}>
|
||||
<thead>
|
||||
<tr style={{ background: COLORS.chip, textAlign: "left", color: COLORS.inkSoft }}>
|
||||
{["Becario", "Institución", "Avance", "Estado", ""].map((h, i) =>
|
||||
<th key={i} style={{ padding: "11px 14px", fontWeight: 600, whiteSpace: "nowrap" }}>{h}</th>)}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{becarios.map((b) => {
|
||||
const h = b.horas || { total_horas: 0, meta_horas: b.meta_horas, porcentaje: 0 };
|
||||
return (
|
||||
<tr key={b.id} style={{ borderTop: `1px solid ${COLORS.border}` }}>
|
||||
<td style={{ padding: "11px 14px" }}>
|
||||
<div style={{ fontWeight: 600, color: COLORS.ink, cursor: "pointer" }} onClick={() => onOpen(b.id)}>{b.nombre}</div>
|
||||
<div style={{ fontSize: "12px", color: COLORS.inkSoft }}>{[b.telefono, b.matricula].filter(Boolean).join(" · ") || "—"}</div>
|
||||
</td>
|
||||
<td style={{ padding: "11px 14px", color: COLORS.inkSoft }}>{b.institucion || "—"}</td>
|
||||
<td style={{ padding: "11px 14px", minWidth: "160px" }}>
|
||||
<div style={{ display: "flex", justifyContent: "space-between", fontSize: "12px", marginBottom: "4px" }}>
|
||||
<span style={{ color: COLORS.ink }}>{fmtHoras(h.total_horas)} / {fmtHoras(h.meta_horas)}</span>
|
||||
<span style={{ color: COLORS.inkSoft }}>{h.porcentaje}%</span>
|
||||
</div>
|
||||
<div style={{ height: "6px", background: COLORS.chip, borderRadius: "999px", overflow: "hidden" }}>
|
||||
<div style={{ height: "100%", width: `${Math.min(100, h.porcentaje)}%`,
|
||||
background: h.porcentaje >= 100 ? COLORS.success : COLORS.primary }} />
|
||||
</div>
|
||||
</td>
|
||||
<td style={{ padding: "11px 14px" }}><Badge tone={estadoBecarioTone(b.estado)}>{b.estado}</Badge></td>
|
||||
<td style={{ padding: "11px 14px", whiteSpace: "nowrap" }}>
|
||||
<div style={{ display: "flex", gap: "6px", justifyContent: "flex-end" }}>
|
||||
{b.estado === "pendiente" && <Btn size="sm" variant="success" onClick={() => aprobar(b)}>Aprobar</Btn>}
|
||||
<Btn size="sm" variant="ghost" onClick={() => onOpen(b.id)}>Ver</Btn>
|
||||
<Btn size="sm" variant="subtle" onClick={() => setForm(b)}>Editar</Btn>
|
||||
{b.estado !== "baja" && <Btn size="sm" variant="ghost" onClick={() => baja(b)}>Baja</Btn>}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</Card>}
|
||||
{becarios === null ? <p style={{ color: palette.inkSoft, fontFamily: fonts.body }}>Cargando…</p> :
|
||||
becarios.length === 0 ? <EmptyState icon="users" tone="blue" title="Aún no hay becarios" sub="Crea el primero o espera a que se registren desde su celular." action={nuevoBtn()} /> :
|
||||
<Table head={["Becario", "Institución", "Avance", "Estado", ""]} minWidth={720}>
|
||||
{becarios.map((b) => {
|
||||
const h = b.horas || { total_horas: 0, meta_horas: b.meta_horas, porcentaje: 0 };
|
||||
return (
|
||||
<Tr key={b.id}>
|
||||
<Td>
|
||||
<div style={{ fontWeight: 600, color: palette.brand, cursor: "pointer" }} onClick={() => onOpen(b.id)}>{b.nombre}</div>
|
||||
<div style={{ fontSize: "12px", color: palette.inkSoft, marginTop: "2px" }}>{[b.telefono, b.matricula].filter(Boolean).join(" · ") || "—"}</div>
|
||||
</Td>
|
||||
<Td soft>{b.institucion || "—"}</Td>
|
||||
<Td style={{ minWidth: "180px" }}>
|
||||
<div style={{ display: "flex", justifyContent: "space-between", fontSize: "12px", marginBottom: "5px" }}>
|
||||
<span style={{ color: palette.ink }}>{fmtHoras(h.total_horas)} / {fmtHoras(h.meta_horas)}</span>
|
||||
<span style={{ color: palette.inkSoft }}>{h.porcentaje}%</span>
|
||||
</div>
|
||||
<ProgressBar value={h.porcentaje} />
|
||||
</Td>
|
||||
<Td><Badge tone={estadoBecarioTone(b.estado)}>{b.estado}</Badge></Td>
|
||||
<Td nowrap>
|
||||
<div style={{ display: "flex", gap: "6px", justifyContent: "flex-end" }}>
|
||||
{b.estado === "pendiente" && <Btn size="sm" variant="success" onClick={() => aprobar(b)}>Aprobar</Btn>}
|
||||
<Btn size="sm" variant="ghost" onClick={() => onOpen(b.id)}>Ver</Btn>
|
||||
<Btn size="sm" variant="subtle" onClick={() => setForm(b)}>Editar</Btn>
|
||||
{b.estado !== "baja" && <Btn size="sm" variant="link" onClick={() => setConfirmBaja(b)}>Baja</Btn>}
|
||||
</div>
|
||||
</Td>
|
||||
</Tr>
|
||||
);
|
||||
})}
|
||||
</Table>}
|
||||
{form && <BecarioForm inicial={form.id ? form : null} onSaved={() => { setForm(null); load(); }} onCancel={() => setForm(null)} onError={onError} />}
|
||||
{confirmBaja && <ConfirmModal title="Dar de baja" variant="danger" confirmLabel="Dar de baja"
|
||||
message={`¿Dar de baja a ${confirmBaja.nombre}? Conserva su historial, no se elimina.`}
|
||||
onConfirm={() => doBaja(confirmBaja)} onCancel={() => setConfirmBaja(null)} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -271,30 +274,47 @@ function JornadaEditor({ jornada, onSaved, onCancel, onError }) {
|
||||
} catch (e) { onError(e.message); } finally { setBusy(false); }
|
||||
};
|
||||
return (
|
||||
<div style={{ position: "fixed", inset: 0, background: "rgba(0,0,0,.4)", display: "flex",
|
||||
alignItems: "center", justifyContent: "center", padding: "20px", zIndex: 10 }}>
|
||||
<Card style={{ width: "100%", maxWidth: "380px" }}>
|
||||
<h3 style={{ margin: "0 0 6px", fontSize: "16px", color: COLORS.ink }}>Editar tiempos de jornada</h3>
|
||||
<p style={{ margin: "0 0 14px", fontSize: "12px", color: COLORS.inkSoft }}>
|
||||
El valor original se respalda en la bitácora.</p>
|
||||
<Field label="Entrada"><Input type="datetime-local" value={entrada} onChange={(e) => setEntrada(e.target.value)} /></Field>
|
||||
<Field label="Salida"><Input type="datetime-local" value={salida} onChange={(e) => setSalida(e.target.value)} /></Field>
|
||||
<div style={{ display: "flex", gap: "8px", marginTop: "6px" }}>
|
||||
<Btn onClick={save} disabled={busy}>{busy ? "Guardando…" : "Guardar"}</Btn>
|
||||
<Btn variant="subtle" onClick={onCancel}>Cancelar</Btn>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
<Modal title="Editar tiempos de jornada" sub="El valor original se respalda en la bitácora." onClose={onCancel}>
|
||||
<Field label="Entrada"><Input type="datetime-local" value={entrada} onChange={(e) => setEntrada(e.target.value)} /></Field>
|
||||
<Field label="Salida"><Input type="datetime-local" value={salida} onChange={(e) => setSalida(e.target.value)} /></Field>
|
||||
<div style={{ display: "flex", gap: "9px", marginTop: "4px" }}>
|
||||
<Btn onClick={save} loading={busy} disabled={busy}>{busy ? "Guardando…" : "Guardar"}</Btn>
|
||||
<Btn variant="outline" onClick={onCancel}>Cancelar</Btn>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
// ═══════════════════ Vista por becario ═══════════════════
|
||||
// ── Cerrar jornada en revisión sin salida (antes, un diálogo nativo) ──
|
||||
function CerrarJornadaModal({ jornada, onDone, onCancel, onError }) {
|
||||
const [salida, setSalida] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const go = async () => {
|
||||
const iso = localToIso(salida);
|
||||
if (!iso) { onError("Fecha inválida"); return; }
|
||||
setBusy(true);
|
||||
try { await apiFetch(`/jornadas/${jornada.id}/cerrar`, { method: "POST", body: JSON.stringify({ salida_ts: iso }) }); onDone(); }
|
||||
catch (e) { onError(e.message); } finally { setBusy(false); }
|
||||
};
|
||||
return (
|
||||
<Modal title="Cerrar jornada" sub="Registra la hora de salida real para cerrar esta jornada en revisión." onClose={onCancel}>
|
||||
<Field label="Hora de salida"><Input type="datetime-local" value={salida} onChange={(e) => setSalida(e.target.value)} /></Field>
|
||||
<div style={{ display: "flex", gap: "9px", marginTop: "4px" }}>
|
||||
<Btn variant="success" onClick={go} loading={busy} disabled={busy || !salida}>Cerrar jornada</Btn>
|
||||
<Btn variant="outline" onClick={onCancel}>Cancelar</Btn>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
// ═══════════════════ Vista por becario (detalle) ═══════════════════
|
||||
function VistaBecario({ becarioId, onBack, onError }) {
|
||||
const [data, setData] = useState(null); // becario + horas
|
||||
const [data, setData] = useState(null);
|
||||
const [jornadas, setJornadas] = useState([]);
|
||||
const [ajustes, setAjustes] = useState([]);
|
||||
const [checadas, setChecadas] = useState([]);
|
||||
const [editJornada, setEditJornada] = useState(null);
|
||||
const [cerrarJornada, setCerrarJornada] = useState(null);
|
||||
const [ajuste, setAjuste] = useState({ minutos: "", motivo: "" });
|
||||
const [busyAjuste, setBusyAjuste] = useState(false);
|
||||
|
||||
@@ -312,18 +332,11 @@ function VistaBecario({ becarioId, onBack, onError }) {
|
||||
useEffect(() => { load(); }, [load]);
|
||||
|
||||
const cerrar = async (j) => {
|
||||
let salida_ts;
|
||||
if (!j.salida_ts) {
|
||||
const v = prompt("Fecha/hora de salida (YYYY-MM-DD HH:MM):");
|
||||
if (!v) return;
|
||||
const iso = localToIso(v.replace(" ", "T"));
|
||||
if (!iso) { onError("Fecha inválida"); return; }
|
||||
salida_ts = iso;
|
||||
}
|
||||
try {
|
||||
await apiFetch(`/jornadas/${j.id}/cerrar`, { method: "POST", body: JSON.stringify(salida_ts ? { salida_ts } : {}) });
|
||||
await load();
|
||||
} catch (e) { onError(e.message); }
|
||||
// Con salida ya registrada, cierra directo (POST {}); sin salida, pide la hora.
|
||||
if (j.salida_ts) {
|
||||
try { await apiFetch(`/jornadas/${j.id}/cerrar`, { method: "POST", body: JSON.stringify({}) }); await load(); }
|
||||
catch (e) { onError(e.message); }
|
||||
} else { setCerrarJornada(j); }
|
||||
};
|
||||
const crearAjuste = async (e) => {
|
||||
e.preventDefault(); setBusyAjuste(true);
|
||||
@@ -335,122 +348,103 @@ function VistaBecario({ becarioId, onBack, onError }) {
|
||||
} catch (err) { onError(err.message); } finally { setBusyAjuste(false); }
|
||||
};
|
||||
|
||||
if (!data) return <p style={{ color: COLORS.inkSoft }}>Cargando…</p>;
|
||||
if (!data) return <p style={{ color: palette.inkSoft, fontFamily: fonts.body }}>Cargando…</p>;
|
||||
const h = data.horas;
|
||||
const sec = { margin: "0 0 12px", fontFamily: fonts.title, fontWeight: 600, fontSize: "17px", color: palette.brand };
|
||||
return (
|
||||
<div>
|
||||
{editJornada && <JornadaEditor jornada={editJornada}
|
||||
onSaved={() => { setEditJornada(null); load(); }} onCancel={() => setEditJornada(null)} onError={onError} />}
|
||||
<Btn variant="subtle" size="sm" onClick={onBack}>← Volver a becarios</Btn>
|
||||
<div style={{ margin: "14px 0 18px", display: "flex", justifyContent: "space-between", alignItems: "flex-start", gap: "12px", flexWrap: "wrap" }}>
|
||||
<div>
|
||||
<h2 style={{ margin: "0 0 4px", fontSize: "20px", color: COLORS.ink }}>{data.nombre}</h2>
|
||||
<div style={{ fontSize: "13px", color: COLORS.inkSoft }}>
|
||||
{[data.telefono, data.matricula, data.institucion].filter(Boolean).join(" · ") || "sin datos"}
|
||||
{" "}<Badge tone={estadoBecarioTone(data.estado)}>{data.estado}</Badge>
|
||||
</div>
|
||||
</div>
|
||||
<Btn variant="subtle" size="sm" onClick={onBack}>{iconBtn("chevronLeft", { size: 15, color: palette.label })}Volver a becarios</Btn>
|
||||
<div style={{ margin: "18px 0 6px", display: "flex", alignItems: "center", gap: "12px", flexWrap: "wrap" }}>
|
||||
<h2 style={{ margin: 0, fontFamily: fonts.title, fontWeight: 600, fontSize: "24px", color: palette.brand, letterSpacing: "-.01em" }}>{data.nombre}</h2>
|
||||
<Badge tone={estadoBecarioTone(data.estado)}>{data.estado}</Badge>
|
||||
</div>
|
||||
<div style={{ fontFamily: fonts.body, fontSize: "13px", color: palette.inkSoft, marginBottom: "20px" }}>
|
||||
{[data.telefono, data.matricula, data.institucion].filter(Boolean).join(" · ") || "sin datos"}
|
||||
</div>
|
||||
|
||||
<Card style={{ marginBottom: "18px" }}>
|
||||
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", marginBottom: "8px" }}>
|
||||
<span style={{ fontSize: "15px", fontWeight: 600, color: COLORS.ink }}>Avance</span>
|
||||
<span style={{ fontSize: "13px", color: COLORS.inkSoft }}>calculado por el backend</span>
|
||||
<Card style={{ marginBottom: "20px", padding: "22px 24px" }}>
|
||||
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", marginBottom: "10px" }}>
|
||||
<span style={{ fontFamily: fonts.body, fontWeight: 600, fontSize: "15px", color: palette.ink }}>Avance</span>
|
||||
<span style={{ fontFamily: fonts.body, fontSize: "12px", color: palette.placeholder }}>calculado por el backend</span>
|
||||
</div>
|
||||
<div style={{ fontSize: "26px", fontWeight: 700, color: COLORS.ink }}>
|
||||
{fmtHoras(h.total_horas)} <span style={{ fontSize: "15px", color: COLORS.inkSoft, fontWeight: 500 }}>de {fmtHoras(h.meta_horas)} ({h.porcentaje}%)</span>
|
||||
<div style={{ fontFamily: fonts.title, fontWeight: 700, fontSize: "30px", color: palette.brand, letterSpacing: "-.01em" }}>
|
||||
{fmtHoras(h.total_horas)} <span style={{ fontFamily: fonts.body, fontSize: "15px", color: palette.inkSoft, fontWeight: 500 }}>de {fmtHoras(h.meta_horas)} ({h.porcentaje}%)</span>
|
||||
</div>
|
||||
<div style={{ height: "8px", background: COLORS.chip, borderRadius: "999px", overflow: "hidden", margin: "10px 0" }}>
|
||||
<div style={{ height: "100%", width: `${Math.min(100, h.porcentaje)}%`, background: h.porcentaje >= 100 ? COLORS.success : COLORS.primary }} />
|
||||
</div>
|
||||
<div style={{ fontSize: "13px", color: COLORS.inkSoft }}>
|
||||
<div style={{ margin: "14px 0" }}><ProgressBar value={h.porcentaje} height={9} /></div>
|
||||
<div style={{ fontFamily: fonts.body, fontSize: "13px", color: palette.inkSoft }}>
|
||||
Jornadas cerradas: {(h.minutos_jornadas / 60).toFixed(1)} h · Ajustes: {(h.minutos_ajustes / 60).toFixed(1)} h
|
||||
<span style={{ color: COLORS.warn }}> · las jornadas en revisión no suman</span>
|
||||
<span style={{ color: palette.amber }}> · las jornadas en revisión no suman</span>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<h3 style={{ margin: "0 0 10px", fontSize: "16px", color: COLORS.ink }}>Jornadas</h3>
|
||||
{jornadas.length === 0 ? <Card style={{ marginBottom: "18px" }}><p style={{ margin: 0, color: COLORS.inkSoft }}>Sin jornadas.</p></Card> :
|
||||
<Card style={{ padding: 0, marginBottom: "18px", overflow: "hidden" }}>
|
||||
<div style={{ overflowX: "auto" }}>
|
||||
<table style={{ width: "100%", borderCollapse: "collapse", fontSize: "13px", fontFamily: FONT }}>
|
||||
<thead><tr style={{ background: COLORS.chip, textAlign: "left", color: COLORS.inkSoft }}>
|
||||
{["Entrada", "Salida", "Duración", "Estado", ""].map((c, i) => <th key={i} style={{ padding: "10px 12px", fontWeight: 600, whiteSpace: "nowrap" }}>{c}</th>)}
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
{jornadas.map((j) => (
|
||||
<tr key={j.id} style={{ borderTop: `1px solid ${COLORS.border}` }}>
|
||||
<td style={{ padding: "10px 12px", whiteSpace: "nowrap" }}>{fmtDT(j.entrada_ts)}</td>
|
||||
<td style={{ padding: "10px 12px", whiteSpace: "nowrap" }}>{fmtDT(j.salida_ts)}</td>
|
||||
<td style={{ padding: "10px 12px", whiteSpace: "nowrap" }}>{j.duracion_minutos != null ? `${(j.duracion_minutos / 60).toFixed(1)} h` : "—"}</td>
|
||||
<td style={{ padding: "10px 12px" }}>
|
||||
<Badge tone={estadoJornadaTone(j.estado)}>{j.estado}</Badge>
|
||||
{j.editada && <span style={{ marginLeft: "6px", fontSize: "11px", color: COLORS.inkSoft }}>editada</span>}
|
||||
</td>
|
||||
<td style={{ padding: "10px 12px", whiteSpace: "nowrap" }}>
|
||||
<div style={{ display: "flex", gap: "6px", justifyContent: "flex-end" }}>
|
||||
<Btn size="sm" variant="subtle" onClick={() => setEditJornada(j)}>Editar</Btn>
|
||||
{j.estado === "revision" && <Btn size="sm" variant="success" onClick={() => cerrar(j)}>Cerrar</Btn>}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</Card>}
|
||||
<h3 style={sec}>Jornadas</h3>
|
||||
{jornadas.length === 0 ? <div style={{ marginBottom: "22px" }}><EmptyState icon="calendar" tone="neutral" title="Sin jornadas todavía" sub="Este becario aún no registra entradas ni salidas." /></div> :
|
||||
<div style={{ marginBottom: "22px" }}>
|
||||
<Table head={["Entrada", "Salida", "Duración", "Estado", ""]} minWidth={640}>
|
||||
{jornadas.map((j) => (
|
||||
<Tr key={j.id}>
|
||||
<Td nowrap>{fmtDT(j.entrada_ts)}</Td>
|
||||
<Td nowrap soft={!j.salida_ts}>{fmtDT(j.salida_ts)}</Td>
|
||||
<Td nowrap soft={j.duracion_minutos == null}>{j.duracion_minutos != null ? `${(j.duracion_minutos / 60).toFixed(1)} h` : "—"}</Td>
|
||||
<Td>
|
||||
<Badge tone={estadoJornadaTone(j.estado)}>{j.estado}</Badge>
|
||||
{j.editada && <span style={{ marginLeft: "6px", fontFamily: fonts.body, fontSize: "11px", color: palette.inkSoft }}>editada</span>}
|
||||
</Td>
|
||||
<Td nowrap>
|
||||
<div style={{ display: "flex", gap: "6px", justifyContent: "flex-end" }}>
|
||||
<Btn size="sm" variant="subtle" onClick={() => setEditJornada(j)}>Editar</Btn>
|
||||
{j.estado === "revision" && <Btn size="sm" variant="success" onClick={() => cerrar(j)}>Cerrar</Btn>}
|
||||
</div>
|
||||
</Td>
|
||||
</Tr>
|
||||
))}
|
||||
</Table>
|
||||
</div>}
|
||||
|
||||
<h3 style={{ margin: "0 0 10px", fontSize: "16px", color: COLORS.ink }}>Ajustes</h3>
|
||||
<Card>
|
||||
<form onSubmit={crearAjuste} style={{ display: "flex", gap: "10px", alignItems: "flex-end", flexWrap: "wrap", marginBottom: ajustes.length ? "16px" : 0 }}>
|
||||
<div style={{ width: "120px" }}>
|
||||
<h3 style={sec}>Ajustes</h3>
|
||||
<Card style={{ marginBottom: "22px", padding: "20px 22px" }}>
|
||||
<form onSubmit={crearAjuste} style={{ display: "flex", gap: "12px", alignItems: "flex-end", flexWrap: "wrap", marginBottom: ajustes.length ? "4px" : 0 }}>
|
||||
<div style={{ width: "130px" }}>
|
||||
<Field label="Minutos (+/−)"><Input type="number" value={ajuste.minutos} onChange={(e) => setAjuste({ ...ajuste, minutos: e.target.value })} placeholder="ej. 60 o -30" required /></Field>
|
||||
</div>
|
||||
<div style={{ flex: 1, minWidth: "200px" }}>
|
||||
<div style={{ flex: 1, minWidth: "220px" }}>
|
||||
<Field label="Motivo (obligatorio)"><Input value={ajuste.motivo} onChange={(e) => setAjuste({ ...ajuste, motivo: e.target.value })} required /></Field>
|
||||
</div>
|
||||
<div style={{ marginBottom: "12px" }}>
|
||||
<Btn type="submit" disabled={busyAjuste || !ajuste.minutos || Number(ajuste.minutos) === 0 || !ajuste.motivo.trim()}>Agregar</Btn>
|
||||
<div style={{ marginBottom: "14px" }}>
|
||||
<Btn type="submit" loading={busyAjuste} disabled={busyAjuste || !ajuste.minutos || Number(ajuste.minutos) === 0 || !ajuste.motivo.trim()}>Agregar</Btn>
|
||||
</div>
|
||||
</form>
|
||||
{ajustes.map((a) => (
|
||||
<div key={a.id} style={{ display: "flex", justifyContent: "space-between", alignItems: "center",
|
||||
borderTop: `1px solid ${COLORS.border}`, padding: "10px 0", gap: "10px" }}>
|
||||
<div style={{ fontSize: "14px", color: COLORS.ink }}>
|
||||
<strong style={{ color: a.minutos >= 0 ? COLORS.success : COLORS.danger }}>{a.minutos >= 0 ? "+" : ""}{a.minutos} min</strong>
|
||||
<span style={{ color: COLORS.inkSoft }}> · {a.motivo}</span>
|
||||
<div key={a.id} style={{ display: "flex", justifyContent: "space-between", alignItems: "center", borderTop: `1px solid ${palette.cardBorder}`, padding: "12px 0", gap: "10px" }}>
|
||||
<div style={{ fontFamily: fonts.body, fontSize: "14px", color: palette.ink }}>
|
||||
<strong style={{ color: a.minutos >= 0 ? palette.green : palette.danger, fontWeight: 700 }}>{a.minutos >= 0 ? "+" : ""}{a.minutos} min</strong>
|
||||
<span style={{ color: palette.inkSoft }}> · {a.motivo}</span>
|
||||
</div>
|
||||
<span style={{ fontSize: "12px", color: COLORS.inkSoft, whiteSpace: "nowrap" }}>{fmtDT(a.created_at)}</span>
|
||||
<span style={{ fontFamily: fonts.body, fontSize: "12px", color: palette.inkSoft, whiteSpace: "nowrap" }}>{fmtDT(a.created_at)}</span>
|
||||
</div>
|
||||
))}
|
||||
</Card>
|
||||
|
||||
<h3 style={{ margin: "18px 0 10px", fontSize: "16px", color: COLORS.ink }}>Checadas (con IP / dispositivo)</h3>
|
||||
<p style={{ margin: "0 0 10px", fontSize: "12px", color: COLORS.inkSoft }}>
|
||||
IP y user-agent son señal secundaria de anomalías, no prueba de ubicación (§3).
|
||||
<h3 style={{ ...sec, marginBottom: "6px" }}>Checadas <span style={{ fontFamily: fonts.body, fontWeight: 400, fontSize: "13px", color: palette.inkSoft }}>(con IP / dispositivo)</span></h3>
|
||||
<p style={{ margin: "0 0 12px", fontFamily: fonts.body, fontSize: "12px", color: palette.inkSoft }}>
|
||||
IP y user-agent son señal secundaria de anomalías, no prueba de ubicación.
|
||||
</p>
|
||||
{checadas.length === 0 ? <Card><p style={{ margin: 0, color: COLORS.inkSoft }}>Sin checadas.</p></Card> :
|
||||
<Card style={{ padding: 0, overflow: "hidden" }}>
|
||||
<div style={{ overflowX: "auto" }}>
|
||||
<table style={{ width: "100%", borderCollapse: "collapse", fontSize: "13px", fontFamily: FONT }}>
|
||||
<thead><tr style={{ background: COLORS.chip, textAlign: "left", color: COLORS.inkSoft }}>
|
||||
{["Momento", "Tipo", "Origen", "Concepto", "IP", "User-agent"].map((c, i) => <th key={i} style={{ padding: "10px 12px", fontWeight: 600, whiteSpace: "nowrap" }}>{c}</th>)}
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
{checadas.map((c) => (
|
||||
<tr key={c.id} style={{ borderTop: `1px solid ${COLORS.border}` }}>
|
||||
<td style={{ padding: "9px 12px", whiteSpace: "nowrap" }}>{fmtDT(c.ts)}</td>
|
||||
<td style={{ padding: "9px 12px" }}><Badge tone={c.tipo === "entrada" ? "success" : "primary"}>{c.tipo}</Badge></td>
|
||||
<td style={{ padding: "9px 12px", color: COLORS.inkSoft }}>{c.origen}</td>
|
||||
<td style={{ padding: "9px 12px", color: COLORS.inkSoft }}>{c.concepto || "—"}</td>
|
||||
<td style={{ padding: "9px 12px", color: COLORS.inkSoft, fontFamily: "monospace" }}>{c.ip || "—"}</td>
|
||||
<td style={{ padding: "9px 12px", color: COLORS.inkSoft, maxWidth: "220px", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }} title={c.user_agent || ""}>{c.user_agent || "—"}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</Card>}
|
||||
{checadas.length === 0 ? <EmptyState icon="clock" tone="neutral" title="Sin checadas" sub="No hay registros de chip NFC para este becario." /> :
|
||||
<Table head={["Momento", "Tipo", "Origen", "Concepto", "IP", "User-agent"]} minWidth={780}>
|
||||
{checadas.map((c) => (
|
||||
<Tr key={c.id}>
|
||||
<Td nowrap>{fmtDT(c.ts)}</Td>
|
||||
<Td><Badge tone={c.tipo === "entrada" ? "success" : "primary"}>{c.tipo}</Badge></Td>
|
||||
<Td soft>{c.origen}</Td>
|
||||
<Td soft>{c.concepto || "—"}</Td>
|
||||
<Td soft mono>{c.ip || "—"}</Td>
|
||||
<Td soft ellipsis title={c.user_agent || ""}>{c.user_agent || "—"}</Td>
|
||||
</Tr>
|
||||
))}
|
||||
</Table>}
|
||||
|
||||
{editJornada && <JornadaEditor jornada={editJornada} onSaved={() => { setEditJornada(null); load(); }} onCancel={() => setEditJornada(null)} onError={onError} />}
|
||||
{cerrarJornada && <CerrarJornadaModal jornada={cerrarJornada} onDone={() => { setCerrarJornada(null); load(); }} onCancel={() => setCerrarJornada(null)} onError={onError} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -485,25 +479,24 @@ function VistaConfig({ onError }) {
|
||||
setOkMsg("Configuración guardada."); await load();
|
||||
} catch (err) { onError(err.message); } finally { setBusy(false); }
|
||||
};
|
||||
if (!cfg) return <p style={{ color: COLORS.inkSoft }}>Cargando…</p>;
|
||||
if (!cfg) return <p style={{ color: palette.inkSoft, fontFamily: fonts.body }}>Cargando…</p>;
|
||||
return (
|
||||
<div>
|
||||
<h2 style={{ margin: "0 0 14px", fontSize: "18px", color: COLORS.ink }}>Configuración</h2>
|
||||
<Card style={{ maxWidth: "520px" }}>
|
||||
<h2 style={{ margin: "0 0 16px", fontFamily: fonts.title, fontWeight: 600, fontSize: "22px", color: palette.brand, letterSpacing: "-.01em" }}>Configuración</h2>
|
||||
<Card style={{ maxWidth: "560px" }}>
|
||||
<form onSubmit={guardar}>
|
||||
<div style={{ marginBottom: "6px", fontSize: "14px", fontWeight: 600, color: COLORS.ink }}>Ventana horaria de checado</div>
|
||||
<p style={{ margin: "0 0 10px", fontSize: "12px", color: COLORS.inkSoft }}>Fuera de este rango no se emiten tokens y las jornadas abiertas se auto-cierran a revisión.</p>
|
||||
<div style={{ fontFamily: fonts.body, fontWeight: 600, fontSize: "14px", color: palette.ink, marginBottom: "5px" }}>Ventana horaria de checado</div>
|
||||
<p style={{ margin: "0 0 14px", fontFamily: fonts.body, fontSize: "12px", color: palette.inkSoft, lineHeight: 1.5 }}>Fuera de este rango no se emiten tokens y las jornadas abiertas se auto-cierran a revisión.</p>
|
||||
<div style={{ display: "flex", gap: "14px" }}>
|
||||
<Field label="Inicio"><Input type="time" value={f.inicio} onChange={(e) => setF({ ...f, inicio: e.target.value })} /></Field>
|
||||
<Field label="Fin"><Input type="time" value={f.fin} onChange={(e) => setF({ ...f, fin: e.target.value })} /></Field>
|
||||
<div style={{ flex: 1 }}><Field label="Inicio"><Input type="time" value={f.inicio} onChange={(e) => setF({ ...f, inicio: e.target.value })} /></Field></div>
|
||||
<div style={{ flex: 1 }}><Field label="Fin"><Input type="time" value={f.fin} onChange={(e) => setF({ ...f, fin: e.target.value })} /></Field></div>
|
||||
</div>
|
||||
<div style={{ margin: "6px 0 18px" }}>
|
||||
<Toggle checked={f.tarea_activa} onChange={(v) => setF({ ...f, tarea_activa: v })} label="Pedir el concepto de la tarea al checar (switch global)" />
|
||||
</div>
|
||||
<label style={{ display: "flex", alignItems: "center", gap: "10px", margin: "8px 0 16px", cursor: "pointer" }}>
|
||||
<input type="checkbox" checked={f.tarea_activa} onChange={(e) => setF({ ...f, tarea_activa: e.target.checked })} style={{ width: "18px", height: "18px" }} />
|
||||
<span style={{ fontSize: "14px", color: COLORS.ink }}>Pedir el concepto de la tarea al checar (switch global)</span>
|
||||
</label>
|
||||
<Field label="Meta de horas por defecto"><Input type="number" min="1" value={f.meta} onChange={(e) => setF({ ...f, meta: e.target.value })} style={{ maxWidth: "160px" }} /></Field>
|
||||
{okMsg && <p style={{ color: COLORS.success, fontSize: "13px" }}>✓ {okMsg}</p>}
|
||||
<div style={{ marginTop: "6px" }}><Btn type="submit" disabled={busy}>{busy ? "Guardando…" : "Guardar configuración"}</Btn></div>
|
||||
{okMsg && <Aviso variant="success" icon="check">{okMsg}</Aviso>}
|
||||
<div style={{ marginTop: "6px" }}><Btn type="submit" loading={busy} disabled={busy}>{busy ? "Guardando…" : "Guardar configuración"}</Btn></div>
|
||||
</form>
|
||||
</Card>
|
||||
</div>
|
||||
@@ -511,68 +504,90 @@ function VistaConfig({ onError }) {
|
||||
}
|
||||
|
||||
// ═══════════════════ Cola de solicitudes ═══════════════════
|
||||
// Autorizar/rechazar usan modales propios (antes, diálogos nativos del
|
||||
// navegador); la llamada al backend por detrás no cambia.
|
||||
function AutorizarModal({ solicitud, onDone, onCancel, onError }) {
|
||||
const olvido = solicitud.tipo === "olvido_entrada";
|
||||
const [entrada, setEntrada] = useState(olvido ? isoToLocal(solicitud.propuesta?.entrada_ts) : "");
|
||||
const [salida, setSalida] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const go = async () => {
|
||||
setBusy(true);
|
||||
try {
|
||||
const body = {};
|
||||
if (olvido) {
|
||||
const eIso = localToIso(entrada);
|
||||
if (!eIso) { onError("Fecha de entrada inválida"); setBusy(false); return; }
|
||||
body.entrada_ts = eIso;
|
||||
const sIso = localToIso(salida);
|
||||
if (sIso) body.salida_ts = sIso;
|
||||
} else {
|
||||
const sIso = localToIso(salida);
|
||||
if (!sIso) { onError("Fecha de salida inválida"); setBusy(false); return; }
|
||||
body.salida_ts = sIso;
|
||||
}
|
||||
await apiFetch(`/solicitudes/${solicitud.id}/autorizar`, { method: "POST", body: JSON.stringify(body) });
|
||||
onDone();
|
||||
} catch (e) { onError(e.message); } finally { setBusy(false); }
|
||||
};
|
||||
return (
|
||||
<Modal title={olvido ? "Autorizar olvido de entrada" : "Autorizar auto-cierre"}
|
||||
sub={olvido ? "Confirma la hora de entrada; la salida es opcional (déjala vacía si sigue en curso)." : "Registra la hora de salida real para cerrar la jornada."}
|
||||
onClose={onCancel}>
|
||||
{olvido && <Field label="Hora de entrada"><Input type="datetime-local" value={entrada} onChange={(e) => setEntrada(e.target.value)} /></Field>}
|
||||
<Field label={olvido ? "Hora de salida (opcional)" : "Hora de salida"}><Input type="datetime-local" value={salida} onChange={(e) => setSalida(e.target.value)} /></Field>
|
||||
<div style={{ display: "flex", gap: "9px", marginTop: "4px" }}>
|
||||
<Btn variant="success" onClick={go} loading={busy} disabled={busy || (olvido ? !entrada : !salida)}>Autorizar</Btn>
|
||||
<Btn variant="outline" onClick={onCancel}>Cancelar</Btn>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function VistaSolicitudes({ onError }) {
|
||||
const [sols, setSols] = useState(null);
|
||||
const [busy, setBusy] = useState(null);
|
||||
const [autorizar, setAutorizar] = useState(null);
|
||||
const [confirmRechazo, setConfirmRechazo] = useState(null);
|
||||
const load = useCallback(async () => {
|
||||
try { setSols(await apiFetch("/solicitudes?estado=pendiente")); } catch (e) { onError(e.message); }
|
||||
}, [onError]);
|
||||
useEffect(() => { load(); }, [load]);
|
||||
|
||||
const autorizar = async (s) => {
|
||||
setBusy(s.id);
|
||||
try {
|
||||
const body = {};
|
||||
if (s.tipo === "olvido_entrada") {
|
||||
const ent = prompt("Hora de entrada a autorizar (YYYY-MM-DD HH:MM):", (s.propuesta?.entrada_ts || "").slice(0, 16).replace("T", " "));
|
||||
if (!ent) { setBusy(null); return; }
|
||||
body.entrada_ts = new Date(ent.replace(" ", "T")).toISOString();
|
||||
const sal = prompt("Hora de salida (opcional, para que sume; deja vacío si sigue en curso):", "");
|
||||
if (sal) body.salida_ts = new Date(sal.replace(" ", "T")).toISOString();
|
||||
} else {
|
||||
const sal = prompt("Hora de salida real para cerrar la jornada (YYYY-MM-DD HH:MM):", "");
|
||||
if (!sal) { setBusy(null); return; }
|
||||
body.salida_ts = new Date(sal.replace(" ", "T")).toISOString();
|
||||
}
|
||||
await apiFetch(`/solicitudes/${s.id}/autorizar`, { method: "POST", body: JSON.stringify(body) });
|
||||
await load();
|
||||
} catch (e) { onError(e.message); } finally { setBusy(null); }
|
||||
const doRechazo = async (s) => {
|
||||
try { await apiFetch(`/solicitudes/${s.id}/rechazar`, { method: "POST" }); setConfirmRechazo(null); await load(); }
|
||||
catch (e) { onError(e.message); setConfirmRechazo(null); }
|
||||
};
|
||||
const rechazar = async (s) => {
|
||||
if (!confirm("¿Rechazar esta solicitud?")) return;
|
||||
setBusy(s.id);
|
||||
try { await apiFetch(`/solicitudes/${s.id}/rechazar`, { method: "POST" }); await load(); }
|
||||
catch (e) { onError(e.message); } finally { setBusy(null); }
|
||||
};
|
||||
|
||||
if (sols === null) return <p style={{ color: COLORS.inkSoft }}>Cargando…</p>;
|
||||
if (sols === null) return <p style={{ color: palette.inkSoft, fontFamily: fonts.body }}>Cargando…</p>;
|
||||
return (
|
||||
<div>
|
||||
<h2 style={{ margin: "0 0 14px", fontSize: "18px", color: COLORS.ink }}>Solicitudes pendientes</h2>
|
||||
{sols.length === 0 ? <Card><p style={{ margin: 0, color: COLORS.inkSoft }}>No hay solicitudes pendientes.</p></Card> :
|
||||
<h2 style={{ margin: "0 0 16px", fontFamily: fonts.title, fontWeight: 600, fontSize: "22px", color: palette.brand, letterSpacing: "-.01em" }}>Solicitudes pendientes</h2>
|
||||
{sols.length === 0 ? <EmptyState icon="listCheck" tone="green" title="No hay solicitudes pendientes" sub="Cuando un becario pida un olvido de entrada o auto-cierre, aparecerá aquí." /> :
|
||||
sols.map((s) => (
|
||||
<Card key={s.id} style={{ marginBottom: "12px" }}>
|
||||
<Card key={s.id} style={{ marginBottom: "14px", borderRadius: "16px", padding: "18px 20px" }}>
|
||||
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-start", gap: "12px", flexWrap: "wrap" }}>
|
||||
<div>
|
||||
<div style={{ fontWeight: 600, color: COLORS.ink }}>
|
||||
<div style={{ fontFamily: fonts.body, fontWeight: 600, fontSize: "15px", color: palette.ink }}>
|
||||
{s.tipo === "olvido_entrada" ? "Olvido de entrada" : "Autorizar auto-cierre"}
|
||||
</div>
|
||||
<div style={{ fontSize: "13px", color: COLORS.inkSoft, marginTop: "2px" }}>
|
||||
<div style={{ fontFamily: fonts.body, fontSize: "13px", color: palette.inkSoft, marginTop: "3px" }}>
|
||||
{s.becario_nombre} · {s.becario_telefono || "sin tel."}
|
||||
</div>
|
||||
<div style={{ fontSize: "13px", color: COLORS.ink, marginTop: "6px" }}>
|
||||
<div style={{ fontFamily: fonts.body, fontSize: "13px", color: palette.ink, marginTop: "8px" }}>
|
||||
{s.tipo === "olvido_entrada"
|
||||
? <>Entrada propuesta: <strong>{fmtDT(s.propuesta?.entrada_ts)}</strong></>
|
||||
: <>Jornada en revisión desde <strong>{fmtDT(s.propuesta?.entrada_ts)}</strong></>}
|
||||
? <>Entrada propuesta: <strong style={{ color: palette.brand }}>{fmtDT(s.propuesta?.entrada_ts)}</strong></>
|
||||
: <>Jornada en revisión desde <strong style={{ color: palette.brand }}>{fmtDT(s.propuesta?.entrada_ts)}</strong></>}
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ display: "flex", gap: "8px" }}>
|
||||
<Btn size="sm" variant="success" disabled={busy === s.id} onClick={() => autorizar(s)}>Autorizar</Btn>
|
||||
<Btn size="sm" variant="ghost" disabled={busy === s.id} onClick={() => rechazar(s)}>Rechazar</Btn>
|
||||
<Btn size="sm" variant="success" onClick={() => setAutorizar(s)}>Autorizar</Btn>
|
||||
<Btn size="sm" variant="outline" onClick={() => setConfirmRechazo(s)}>Rechazar</Btn>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
{autorizar && <AutorizarModal solicitud={autorizar} onDone={() => { setAutorizar(null); load(); }} onCancel={() => setAutorizar(null)} onError={onError} />}
|
||||
{confirmRechazo && <ConfirmModal title="Rechazar solicitud" variant="danger" confirmLabel="Rechazar"
|
||||
message="¿Rechazar esta solicitud? El becario deberá volver a enviarla si fue un error."
|
||||
onConfirm={() => doRechazo(confirmRechazo)} onCancel={() => setConfirmRechazo(null)} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -588,29 +603,10 @@ function Panel({ session, onLogout }) {
|
||||
{ key: "config", label: "Configuración" },
|
||||
];
|
||||
const activeTab = view.name === "detalle" ? "lista" : view.name;
|
||||
const tabStyle = (active) => ({
|
||||
padding: "8px 14px", borderRadius: "8px", border: "none", cursor: "pointer", fontFamily: FONT,
|
||||
fontSize: "14px", fontWeight: 600, background: active ? COLORS.accentBg : "transparent",
|
||||
color: active ? COLORS.primaryDark : COLORS.inkSoft,
|
||||
});
|
||||
return (
|
||||
<div style={{ minHeight: "100vh", background: COLORS.bg, fontFamily: FONT }}>
|
||||
<header style={{ background: COLORS.surface, borderBottom: `1px solid ${COLORS.border}`, padding: "12px 20px",
|
||||
display: "flex", justifyContent: "space-between", alignItems: "center", flexWrap: "wrap", gap: "10px" }}>
|
||||
<div style={{ display: "flex", alignItems: "center", gap: "18px" }}>
|
||||
<div style={{ fontWeight: 700, color: COLORS.ink, fontSize: "16px" }}>Taboada · Supervisión</div>
|
||||
<nav style={{ display: "flex", gap: "4px" }}>
|
||||
{tabs.map((t) => (
|
||||
<button key={t.key} style={tabStyle(activeTab === t.key)} onClick={() => setView({ name: t.key })}>{t.label}</button>
|
||||
))}
|
||||
</nav>
|
||||
</div>
|
||||
<div style={{ display: "flex", alignItems: "center", gap: "12px" }}>
|
||||
<span style={{ fontSize: "13px", color: COLORS.inkSoft }}>{session.usuario}</span>
|
||||
<Btn size="sm" variant="ghost" onClick={logout}>Salir</Btn>
|
||||
</div>
|
||||
</header>
|
||||
<main style={{ maxWidth: "980px", margin: "0 auto", padding: "22px 20px 60px" }}>
|
||||
<div style={{ minHeight: "100vh", background: palette.bgGradient, fontFamily: fonts.body }}>
|
||||
<Nav tabs={tabs} active={activeTab} onTab={(k) => setView({ name: k })} user={session.usuario} onLogout={logout} />
|
||||
<main style={{ maxWidth: "1040px", margin: "0 auto", padding: "26px 24px 60px" }}>
|
||||
<ErrorBar error={error} onClose={() => setError(null)} />
|
||||
{view.name === "lista" && <VistaBecarios onOpen={(id) => setView({ name: "detalle", id })} onError={setError} />}
|
||||
{view.name === "detalle" && <VistaBecario becarioId={view.id} onBack={() => setView({ name: "lista" })} onError={setError} />}
|
||||
@@ -625,7 +621,7 @@ function App() {
|
||||
const [session, setSession] = useState(undefined); // undefined=cargando, null=sin sesión
|
||||
useEffect(() => { apiFetch("/auth/session").then(setSession).catch(() => setSession(null)); }, []);
|
||||
if (session === undefined)
|
||||
return <div style={{ minHeight: "100vh", display: "grid", placeItems: "center", fontFamily: FONT, color: COLORS.inkSoft }}>Cargando…</div>;
|
||||
return <div style={{ minHeight: "100vh", display: "grid", placeItems: "center", fontFamily: fonts.body, color: palette.inkSoft }}>Cargando…</div>;
|
||||
if (!session) return <Login onLogin={setSession} />;
|
||||
return <Panel session={session} onLogout={() => setSession(null)} />;
|
||||
}
|
||||
|
||||
+209
-1
@@ -132,6 +132,11 @@ window.Theme = (function () {
|
||||
fill: o.color || CREAM.gold, stroke: o.stroke || CREAM.goldDark, strokeWidth: 1, strokeLinejoin: "round", style: o.style },
|
||||
h("path", { d: "M12 2.4l2.9 5.9 6.5.95-4.7 4.57 1.1 6.48L12 17.8l-5.8 3.06 1.1-6.48L2.6 9.25l6.5-.95z" }));
|
||||
},
|
||||
plus: function (o) { return ic([["path",{d:"M12 5v14"}],["path",{d:"M5 12h14"}]], o); },
|
||||
chevronLeft: function (o) { return ic([["path",{d:"M14 6l-6 6 6 6"}]], o); },
|
||||
x: function (o) { return ic([["path",{d:"M6 6l12 12"}],["path",{d:"M18 6 6 18"}]], o); },
|
||||
users: function (o) { return ic([["circle",{cx:9,cy:8,r:3.4}],["path",{d:"M3.5 20a5.5 5.5 0 0 1 11 0"}],["path",{d:"M17 8h4"}],["path",{d:"M19 6v4"}]], o); },
|
||||
listCheck: function (o) { return ic([["path",{d:"M4 6h11"}],["path",{d:"M4 11h8"}],["path",{d:"M4 16h6"}],["path",{d:"m14.5 16.5 2 2 4-4"}]], o); },
|
||||
spinner: function (o) {
|
||||
o = o || {};
|
||||
return h("svg", { width: o.size || 18, height: o.size || 18, viewBox: "0 0 24 24", fill: "none",
|
||||
@@ -294,10 +299,213 @@ window.Theme = (function () {
|
||||
palette: C, fonts: fonts, icons: icons };
|
||||
}
|
||||
|
||||
// ── Set cream de ESCRITORIO para el flavor 'panel' (rediseño visual) ──
|
||||
// Reusa paleta/fuentes/íconos cream a densidad de escritorio y añade lo propio
|
||||
// del panel: Nav, Table/Tr/Td, ProgressBar, Modal, EmptyState, Toggle, ErrorBar.
|
||||
// Independiente de makeCream (móvil): checada y becario no se ven afectados.
|
||||
function makePanel(React) {
|
||||
var h = React.createElement;
|
||||
var C = CREAM;
|
||||
var fonts = { title: FONT_TITLE, body: FONT_BODY };
|
||||
var icons = makeIcons(React);
|
||||
// tonos semánticos del panel (los helpers estadoXTone siguen en panel.html).
|
||||
var BADGE = {
|
||||
success: [C.greenTint, C.green], warn: [C.amberTint, C.amber],
|
||||
primary: [C.blueTint, C.primary], danger: [C.dangerTint, C.danger],
|
||||
chip: [C.neutralTint, C.inkSoft], neutral: [C.neutralTint, C.inkSoft],
|
||||
};
|
||||
|
||||
function Logo(props) {
|
||||
return h("img", { src: "logo-taboada.png", alt: "Fundación Taboada",
|
||||
style: Object.assign({ height: "40px", width: "auto", display: "block" }, (props && props.style) || {}) });
|
||||
}
|
||||
|
||||
function Card(props) {
|
||||
return h("div", { style: Object.assign({
|
||||
background: C.surface, border: "1px solid " + C.cardBorder, borderRadius: "18px",
|
||||
padding: "24px", boxShadow: "0 18px 40px -30px rgba(33,28,22,.3)",
|
||||
}, props.style || {}) }, props.children);
|
||||
}
|
||||
|
||||
function Btn(props) {
|
||||
var v = props.variant || "primary";
|
||||
var size = props.size === "sm" ? { pad: "7px 13px", font: "13px", radius: "10px" } : { pad: "11px 18px", font: "14px", radius: "13px" };
|
||||
var disabled = props.disabled;
|
||||
var VAR = {
|
||||
primary: { bg: C.primary, fg: "#fff", bd: "none", sh: "0 10px 20px -12px rgba(46,119,184,.7)" },
|
||||
success: { bg: C.green, fg: "#fff", bd: "none", sh: "0 10px 20px -12px rgba(47,138,99,.7)" },
|
||||
danger: { bg: C.danger, fg: "#fff", bd: "none", sh: "none" },
|
||||
subtle: { bg: C.softTint, fg: C.label, bd: "none", sh: "none" },
|
||||
ghost: { bg: "transparent", fg: C.primary, bd: "none", sh: "none" },
|
||||
link: { bg: "transparent", fg: C.inkSoft, bd: "none", sh: "none" },
|
||||
outline: { bg: "transparent", fg: C.label, bd: "1px solid " + C.line, sh: "none" },
|
||||
};
|
||||
var s = VAR[v] || VAR.primary;
|
||||
var solid = v === "primary" || v === "success" || v === "danger";
|
||||
var style = {
|
||||
display: props.block ? "flex" : "inline-flex", width: props.block ? "100%" : "auto", boxSizing: "border-box",
|
||||
alignItems: "center", justifyContent: "center", gap: "8px",
|
||||
padding: size.pad, borderRadius: size.radius, border: disabled ? "none" : s.bd,
|
||||
background: disabled ? "#C6CFD8" : s.bg, color: disabled ? "#F4F8FC" : s.fg,
|
||||
fontFamily: fonts.body, fontSize: size.font, fontWeight: 700,
|
||||
cursor: disabled ? "not-allowed" : (props.loading ? "progress" : "pointer"),
|
||||
boxShadow: disabled ? "none" : s.sh, whiteSpace: "nowrap",
|
||||
};
|
||||
var kids = [];
|
||||
if (props.loading) kids.push(h("span", { key: "s", style: { display: "inline-flex" } },
|
||||
icons.spinner({ size: 15, color: solid ? "#fff" : C.primary, track: C.line })));
|
||||
kids.push(h("span", { key: "t", style: { display: "inline-flex", alignItems: "center", gap: "7px" } }, props.children));
|
||||
return h("button", { type: props.type || "button", onClick: props.onClick, disabled: disabled, style: style }, kids);
|
||||
}
|
||||
|
||||
function Input(props) {
|
||||
var rest = Object.assign({}, props); delete rest.style;
|
||||
var style = Object.assign({
|
||||
width: "100%", boxSizing: "border-box", padding: "11px 14px",
|
||||
border: "1.5px solid " + C.inputBorder, borderRadius: "13px", background: C.inputBg,
|
||||
fontFamily: fonts.body, fontSize: "14px", color: C.ink, outline: "none",
|
||||
}, props.style || {});
|
||||
return h("input", Object.assign(rest, { style: style }));
|
||||
}
|
||||
|
||||
function Field(props) {
|
||||
return h("label", { style: { display: "block", marginBottom: "14px" } },
|
||||
h("span", { style: { display: "block", fontFamily: fonts.body, fontSize: "12px", fontWeight: 600, color: C.label, marginBottom: "6px" } }, props.label),
|
||||
props.children);
|
||||
}
|
||||
|
||||
function Badge(props) {
|
||||
var t = BADGE[props.tone] || BADGE.chip;
|
||||
return h("span", { style: { display: "inline-block", padding: "4px 11px", borderRadius: "99px",
|
||||
fontFamily: fonts.body, fontSize: "12px", fontWeight: 600, background: t[0], color: t[1], whiteSpace: "nowrap" } }, props.children);
|
||||
}
|
||||
|
||||
function Aviso(props) {
|
||||
var v = props.variant;
|
||||
var box = v === "warn" ? { bg: C.warnBg, bd: C.warnBorder, text: C.warnText, ink: C.amber }
|
||||
: v === "success" ? { bg: C.greenTint, bd: C.okBorder, text: C.okText, ink: C.green }
|
||||
: { bg: C.errBg, bd: C.errBorder, text: C.errText, ink: C.danger };
|
||||
var glyph = icons[props.icon] ? icons[props.icon]({ color: box.ink, size: 18, style: { flexShrink: 0 } }) : null;
|
||||
return h("div", { style: { display: "flex", gap: "10px", alignItems: "flex-start",
|
||||
background: box.bg, border: "1px solid " + box.bd, borderRadius: "13px", padding: "11px 13px", marginBottom: "14px" } },
|
||||
[ glyph ? h("span", { key: "i", style: { display: "inline-flex", flexShrink: 0, marginTop: "1px" } }, glyph) : null,
|
||||
h("span", { key: "t", style: { fontFamily: fonts.body, fontSize: "13px", fontWeight: 500, color: box.text, lineHeight: 1.45 } }, props.children) ]);
|
||||
}
|
||||
|
||||
// Barra de error global, descartable (mapea err.message; el mapeo por code lo
|
||||
// hace quien la invoca).
|
||||
function ErrorBar(props) {
|
||||
if (!props.error) return null;
|
||||
return h("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "12px",
|
||||
background: C.errBg, border: "1px solid " + C.errBorder, borderRadius: "14px", padding: "12px 16px", marginBottom: "16px" } },
|
||||
[ h("span", { key: "l", style: { display: "flex", alignItems: "center", gap: "10px" } },
|
||||
[ h("span", { key: "i", style: { display: "inline-flex", flexShrink: 0 } }, icons.alertTriangle({ size: 18, color: C.danger })),
|
||||
h("span", { key: "t", style: { fontFamily: fonts.body, fontSize: "14px", fontWeight: 500, color: C.errText } }, props.error) ]),
|
||||
h("span", { key: "x", onClick: props.onClose, style: { cursor: "pointer", display: "inline-flex", flexShrink: 0 } }, icons.x({ size: 16, color: C.errText, sw: 2.2 })) ]);
|
||||
}
|
||||
|
||||
function Toggle(props) {
|
||||
var on = !!props.checked;
|
||||
return h("label", { style: { display: "flex", alignItems: "center", gap: "11px", cursor: "pointer" } },
|
||||
[ h("span", { key: "sw", onClick: function () { props.onChange(!on); },
|
||||
style: { width: "42px", height: "24px", borderRadius: "99px", background: on ? C.primary : "#D6CDBB", position: "relative", flexShrink: 0, transition: "background .15s" } },
|
||||
h("span", { style: { position: "absolute", top: "3px", left: on ? "21px" : "3px", width: "18px", height: "18px", borderRadius: "50%", background: "#fff", transition: "left .15s" } })),
|
||||
props.label ? h("span", { key: "l", style: { fontFamily: fonts.body, fontSize: "14px", color: C.ink } }, props.label) : null ]);
|
||||
}
|
||||
|
||||
function ProgressBar(props) {
|
||||
var pct = Math.max(0, Math.min(100, props.value || 0));
|
||||
var done = (props.value || 0) >= 100;
|
||||
return h("div", { style: { height: (props.height || 7) + "px", background: C.track, borderRadius: "99px", overflow: "hidden" } },
|
||||
h("div", { style: { height: "100%", width: pct + "%", background: done ? C.green : C.primary, borderRadius: "99px" } }));
|
||||
}
|
||||
|
||||
// Navegación superior (logo + marca + pestañas + usuario + salir).
|
||||
function Nav(props) {
|
||||
var tab = function (t) {
|
||||
var active = props.active === t.key;
|
||||
return h("button", { key: t.key, onClick: function () { props.onTab(t.key); },
|
||||
style: { padding: "8px 15px", borderRadius: "11px", border: "none", cursor: "pointer",
|
||||
fontFamily: fonts.body, fontSize: "14px", fontWeight: 600,
|
||||
background: active ? C.blueTint : "transparent", color: active ? C.primaryDark : C.inkSoft } }, t.label);
|
||||
};
|
||||
return h("header", { style: { background: C.surface, borderBottom: "1px solid " + C.cardBorder,
|
||||
padding: "12px 24px", display: "flex", justifyContent: "space-between", alignItems: "center", flexWrap: "wrap", gap: "10px" } },
|
||||
[ h("div", { key: "l", style: { display: "flex", alignItems: "center", gap: "22px" } },
|
||||
[ h("div", { key: "b", style: { display: "flex", alignItems: "center", gap: "10px" } },
|
||||
[ h(Logo, { key: "lo", style: { height: "34px" } }),
|
||||
h("span", { key: "n", style: { fontFamily: fonts.title, fontWeight: 600, fontSize: "16px", color: C.brand } }, "Supervisión") ]),
|
||||
h("nav", { key: "t", style: { display: "flex", gap: "4px", flexWrap: "wrap" } }, props.tabs.map(tab)) ]),
|
||||
h("div", { key: "r", style: { display: "flex", alignItems: "center", gap: "14px" } },
|
||||
[ h("span", { key: "u", style: { fontFamily: fonts.body, fontSize: "13px", color: C.inkSoft } }, props.user),
|
||||
h(Btn, { key: "s", variant: "ghost", size: "sm", onClick: props.onLogout }, "Salir") ]) ]);
|
||||
}
|
||||
|
||||
// Tabla de escritorio: contenedor + thead temático. Filas con Tr/Td.
|
||||
function Table(props) {
|
||||
return h("div", { style: { background: C.surface, border: "1px solid " + C.cardBorder, borderRadius: "18px",
|
||||
overflow: "hidden", boxShadow: "0 18px 40px -30px rgba(33,28,22,.3)" } },
|
||||
h("div", { style: { overflowX: "auto" } },
|
||||
h("table", { style: { width: "100%", minWidth: (props.minWidth || 0) + "px", borderCollapse: "collapse", fontFamily: fonts.body, fontSize: "14px" } },
|
||||
[ h("thead", { key: "h" }, h("tr", { style: { background: "#F6F1E9", textAlign: "left" } },
|
||||
props.head.map(function (c, i) {
|
||||
return h("th", { key: i, style: { padding: "13px 16px", fontFamily: fonts.body, fontSize: "12px", fontWeight: 600,
|
||||
color: C.placeholder, textTransform: "uppercase", letterSpacing: ".06em", whiteSpace: "nowrap" } }, c);
|
||||
}))),
|
||||
h("tbody", { key: "b" }, props.children) ])));
|
||||
}
|
||||
function Tr(props) {
|
||||
return h("tr", { onClick: props.onClick, style: Object.assign({ borderTop: "1px solid " + C.cardBorder }, props.onClick ? { cursor: "pointer" } : {}) }, props.children);
|
||||
}
|
||||
function Td(props) {
|
||||
var style = {
|
||||
padding: "13px 16px", verticalAlign: "middle",
|
||||
fontFamily: props.mono ? "ui-monospace,SFMono-Regular,Menlo,monospace" : fonts.body,
|
||||
color: props.soft ? C.inkSoft : C.ink,
|
||||
};
|
||||
if (props.nowrap) style.whiteSpace = "nowrap";
|
||||
if (props.ellipsis) { style.maxWidth = "220px"; style.overflow = "hidden"; style.textOverflow = "ellipsis"; style.whiteSpace = "nowrap"; }
|
||||
Object.assign(style, props.style || {});
|
||||
return h("td", { style: style, title: props.title }, props.children);
|
||||
}
|
||||
|
||||
// Modal genérico (overlay + tarjeta). Mismo patrón para editar jornada,
|
||||
// alta/edición de becario y confirmaciones (autorizar/rechazar/baja/cerrar).
|
||||
function Modal(props) {
|
||||
return h("div", { style: { position: "fixed", inset: 0, background: "rgba(33,28,22,.4)",
|
||||
display: "flex", alignItems: "center", justifyContent: "center", padding: "20px", zIndex: 50 } },
|
||||
h("div", { style: { width: "100%", maxWidth: (props.width || 400) + "px", background: C.surface, borderRadius: "22px",
|
||||
padding: "26px", boxShadow: "0 30px 60px -20px rgba(33,28,22,.5)", maxHeight: "90vh", overflowY: "auto" } },
|
||||
[ h("h3", { key: "t", style: { margin: "0 0 " + (props.sub ? "6px" : "18px"), fontFamily: fonts.title, fontWeight: 600, fontSize: "18px", color: C.brand } }, props.title),
|
||||
props.sub ? h("p", { key: "s", style: { margin: "0 0 18px", fontFamily: fonts.body, fontSize: "12px", color: C.inkSoft, lineHeight: 1.5 } }, props.sub) : null,
|
||||
h("div", { key: "c" }, props.children) ]));
|
||||
}
|
||||
|
||||
// Estado vacío: círculo con ícono + título + texto + acción opcional.
|
||||
function EmptyState(props) {
|
||||
var TONE = { blue: [C.blueTint, C.primary], green: [C.greenTint, C.green], neutral: [C.softTint, C.inkSoft] };
|
||||
var t = TONE[props.tone] || TONE.neutral;
|
||||
var glyph = icons[props.icon] ? icons[props.icon]({ color: t[1], size: 27, sw: 1.6 }) : null;
|
||||
var kids = [
|
||||
h("div", { key: "i", style: { width: "60px", height: "60px", borderRadius: "50%", background: t[0], display: "flex", alignItems: "center", justifyContent: "center", margin: "0 auto 16px" } }, glyph),
|
||||
h("h3", { key: "t", style: { margin: "0 0 6px", fontFamily: fonts.title, fontWeight: 600, fontSize: "17px", color: C.brand } }, props.title),
|
||||
];
|
||||
if (props.sub) kids.push(h("p", { key: "s", style: { margin: 0, fontFamily: fonts.body, fontSize: "13px", color: C.inkSoft, lineHeight: 1.5 } }, props.sub));
|
||||
if (props.action) kids.push(h("div", { key: "a", style: { marginTop: "18px" } }, props.action));
|
||||
return h("div", { style: { background: C.surface, border: "1px solid " + C.cardBorder, borderRadius: "20px",
|
||||
padding: "36px 26px", textAlign: "center", boxShadow: "0 20px 44px -32px rgba(33,28,22,.35)" } }, kids);
|
||||
}
|
||||
|
||||
return { palette: C, fonts: fonts, icons: icons, Logo: Logo, Card: Card, Btn: Btn, Input: Input, Field: Field,
|
||||
Badge: Badge, Aviso: Aviso, ErrorBar: ErrorBar, Toggle: Toggle, ProgressBar: ProgressBar,
|
||||
Nav: Nav, Table: Table, Tr: Tr, Td: Td, Modal: Modal, EmptyState: EmptyState };
|
||||
}
|
||||
|
||||
function makeUI(flavor) {
|
||||
var React = window.React;
|
||||
var h = React.createElement;
|
||||
if (flavor === "checada" || flavor === "becario") return makeCream(React); // rediseño móvil: set cream
|
||||
if (flavor === "panel") return makePanel(React); // rediseño escritorio: set cream denso
|
||||
if (flavor === "checada" || flavor === "becario") return makeCream(React); // rediseño móvil: set cream
|
||||
var F = FLAVORS[flavor];
|
||||
if (!F) throw new Error("Theme.makeUI: flavor desconocido '" + flavor + "'");
|
||||
|
||||
|
||||
Reference in new issue
Block a user