/* ============================================================ KeS Metas — Registros (logs de auditoria: quem fez o quê) Relatório filtrável por período e por pessoa. Só o admin acessa. ============================================================ */ const { useState, useEffect } = React; function LogsScreen({ state, viewer, isOwner }) { const K = window.KES, DB = window.KESDB; const isAdmin = !!isOwner; // registros são exclusivos da conta KeS (owner) const [logs, setLogs] = useState([]); const [carregando, setCarregando] = useState(true); const [periodo, setPeriodo] = useState(() => window.buildPreset("mes")); const [quem, setQuem] = useState("todos"); useEffect(() => { let vivo = true; if (!isAdmin || !DB || !DB.configured()) { setCarregando(false); return; } setCarregando(true); // Retenção: apaga registros com mais de 90 dias antes de listar. Promise.resolve(DB.pruneLogs(state.teamId, 90)) .then(() => DB.listLogs(state.teamId, 1000)) .then((r) => { if (vivo) { setLogs(r); setCarregando(false); } }) .catch(() => { if (vivo) { setLogs([]); setCarregando(false); } }); // nunca trava em "Carregando…" return () => { vivo = false; }; }, [state.teamId]); if (!isAdmin) { return

Acesso restrito à conta KeS.

; } const usersById = {}; (state.users || []).forEach((u) => { usersById[u.id] = u; }); // Filtra por período (pela data do ts) e por pessoa. const filtrados = logs.filter((l) => { const dia = (l.ts || "").slice(0, 10); if (dia < periodo.start || dia > periodo.end) return false; if (quem !== "todos" && l.userId !== quem) return false; return true; }); function fmtTs(ts) { try { return new Date(ts).toLocaleString("pt-BR"); } catch (e) { return ts; } } // Cor por tipo de ação (verde p/ ganho, vermelho p/ excluir/perdido). function tom(acao) { if (/GANHA|concluída|criad|ativad/i.test(acao)) return "var(--ok)"; if (/exclu|PERDID|desativ/i.test(acao)) return "var(--kes-red-400)"; return "var(--fg2)"; } return (

Registros

Auditoria do sistema: quem fez o quê e quando.

Atividades

{filtrados.length}
{carregando ? (
Carregando…
) : filtrados.length === 0 ? (
Nenhum registro no período. (Os registros começam a ser gravados a partir de agora.)
) : (
{filtrados.map((l) => { const u = usersById[l.userId]; return (
{u ? :
}
{l.acao}{l.detalhe ? — {l.detalhe} : null}
{l.userNome || "—"} · {fmtTs(l.ts)}
); })}
)}
); } window.LogsScreen = LogsScreen;