feature/rbac y perfiles implementados

This commit is contained in:
2026-05-21 08:00:43 -06:00
parent 546a411df8
commit dc5f9fd6ce
29 changed files with 2007 additions and 977 deletions

View File

@@ -1,5 +1,7 @@
import React, { useEffect, useState } from 'react';
import fetchWithAuth from '../fetchWithAuth';
import { useNotification } from '../context/NotificationContext';
import { extractApiError } from '../api/apiError';
const initialFilters = {
pedimento_app: '',
aduana: '',
@@ -12,6 +14,7 @@ const initialFilters = {
contribuyente__rfc: '',
};
export default function TableroAlmacenamiento() {
const { showMessage } = useNotification();
const [filters, setFilters] = useState(initialFilters);
const [summary, setSummary] = useState(null);
const [isLoading, setIsLoading] = useState(false);
@@ -25,10 +28,13 @@ export default function TableroAlmacenamiento() {
.join('&');
const url = `${import.meta.env.VITE_EFC_API_URL}/reports/table-summary/${params ? `?${params}` : ''}`;
const res = await fetchWithAuth(url, { method: 'POST' });
if (!res.ok) throw new Error('Error al generar el reporte');
alert('Reporte solicitado correctamente. Aparecerá en el historial cuando esté listo.');
if (!res.ok) {
const errMsg = await extractApiError(res);
throw new Error(errMsg);
}
showMessage('Reporte solicitado correctamente. Aparecerá en el historial cuando esté listo.', 'success');
} catch (err) {
alert('No se pudo generar el reporte.');
showMessage(err.message || 'No se pudo generar el reporte', 'error');
}
};
@@ -36,7 +42,10 @@ export default function TableroAlmacenamiento() {
try {
const url = `${import.meta.env.VITE_EFC_API_URL}/reports/report-document-download/${reportId}/`;
const res = await fetchWithAuth(url);
if (!res.ok) throw new Error('Error al descargar el reporte');
if (!res.ok) {
const errMsg = await extractApiError(res);
throw new Error(errMsg);
}
const blob = await res.blob();
let filename = `reporte_${reportId}.csv`;
const disposition = res.headers.get('Content-Disposition');
@@ -50,7 +59,7 @@ export default function TableroAlmacenamiento() {
link.click();
document.body.removeChild(link);
} catch (err) {
alert('No se pudo descargar el reporte.');
showMessage(err.message || 'No se pudo descargar el reporte', 'error');
}
};
@@ -64,9 +73,14 @@ export default function TableroAlmacenamiento() {
.join('&');
const url = `${import.meta.env.VITE_EFC_API_URL}/reports/dashboard/summary/${params ? `?${params}` : ''}`;
const res = await fetchWithAuth(url);
if (!res.ok) {
const errMsg = await extractApiError(res);
throw new Error(errMsg);
}
const data = await res.json();
setSummary(data);
} catch (err) {
showMessage(err.message || 'Error al cargar el resumen', 'error');
setSummary(null);
}
setIsLoading(false);
@@ -82,6 +96,7 @@ export default function TableroAlmacenamiento() {
const data = await res.json();
setReports(data);
} catch (err) {
showMessage(err.message || 'Error al cargar el historial de reportes', 'error');
setReports([]);
}
};
@@ -147,7 +162,7 @@ export default function TableroAlmacenamiento() {
<button
type="button"
className="bg-green-600 text-white px-4 py-2 rounded-md hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2 transition-colors"
onClick={() => alert('Generar reporte (implementación pendiente)')}
onClick={handleGenerateReport}
>
Generar Reporte
</button>