Actualizar frontend/src/pages/Ventas.jsx

This commit is contained in:
2026-07-10 14:39:01 -05:00
parent 5a7b55e793
commit 4da3a5ae6e

View File

@@ -4,6 +4,7 @@ import { api } from "../lib/api";
import { Loader, ErrorBox, Filters, Select } from "../components/UI"; import { Loader, ErrorBox, Filters, Select } from "../components/UI";
import Modal from "../components/Modal"; import Modal from "../components/Modal";
import { useColumnasAjustables } from "../lib/useColumnasAjustables"; import { useColumnasAjustables } from "../lib/useColumnasAjustables";
import { setVistaActual, onRefrescar } from "../lib/vistaActual";
const MESES = ["ENERO","FEBRERO","MARZO","ABRIL","MAYO","JUNIO","JULIO","AGOSTO","SEPTIEMBRE","OCTUBRE","NOVIEMBRE","DICIEMBRE"]; const MESES = ["ENERO","FEBRERO","MARZO","ABRIL","MAYO","JUNIO","JULIO","AGOSTO","SEPTIEMBRE","OCTUBRE","NOVIEMBRE","DICIEMBRE"];
const ANOS = [2024, 2025, 2026]; const ANOS = [2024, 2025, 2026];
@@ -27,11 +28,16 @@ export default function Ventas() {
useEffect(() => { useEffect(() => {
let activo = true; let activo = true;
setLoading(true); setError(null); setVistaActual(`ventas:${ano}|${mes}|${sede}|${programa}|False`);
api.ventas(ano, mes, sede, programa) const cargar = () => {
.then((res) => { if (activo) { setFilas(res.filas || []); setLoading(false); } }) setLoading(true); setError(null);
.catch((e) => { if (activo) { setError(e.message); setLoading(false); } }); api.ventas(ano, mes, sede, programa)
return () => { activo = false; }; .then((res) => { if (activo) { setFilas(res.filas || []); setLoading(false); } })
.catch((e) => { if (activo) { setError(e.message); setLoading(false); } });
};
cargar();
const off = onRefrescar(cargar);
return () => { activo = false; off(); };
}, [ano, mes, sede, programa]); }, [ano, mes, sede, programa]);
const total = useMemo(() => filas.find((f) => f[0] === "TOTAL GENERAL"), [filas]); const total = useMemo(() => filas.find((f) => f[0] === "TOTAL GENERAL"), [filas]);