feature/rbac y perfiles implementados
This commit is contained in:
@@ -9,6 +9,7 @@ const fetchCurrentUserWithAuth = async () => {
|
||||
};
|
||||
import { fetchWithAuth } from '../fetchWithAuth';
|
||||
import { useNotification } from '../context/NotificationContext';
|
||||
import { extractApiError } from '../api/apiError';
|
||||
import datastageModelsData from '../data/datastageModels.json';
|
||||
import pedimentosModelsData from '../data/pedimentosModels.json';
|
||||
|
||||
@@ -42,27 +43,6 @@ if (typeof document !== 'undefined' && !document.getElementById('reports-animati
|
||||
document.head.appendChild(style);
|
||||
}
|
||||
|
||||
const handleDownloadReport = async (reportId) => {
|
||||
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');
|
||||
const blob = await res.blob();
|
||||
let filename = `reporte_${reportId}.csv`;
|
||||
const disposition = res.headers.get('Content-Disposition');
|
||||
if (disposition && disposition.includes('filename=')) {
|
||||
filename = disposition.split('filename=')[1].replace(/"/g, '').trim();
|
||||
}
|
||||
const link = document.createElement('a');
|
||||
link.href = window.URL.createObjectURL(blob);
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
} catch (err) {
|
||||
alert('No se pudo descargar el reporte.');
|
||||
}
|
||||
};
|
||||
|
||||
export default function Reports() {
|
||||
// Estado para organizacion_id
|
||||
@@ -85,7 +65,7 @@ export default function Reports() {
|
||||
// Handler for Generar Reporte in Cumplimiento tab
|
||||
const handleGenerarReporteCumplimiento = async () => {
|
||||
if (!organizacionId) {
|
||||
alert('No se pudo obtener el organizacion_id. Intenta de nuevo más tarde.');
|
||||
showMessage('No se pudo obtener el ID de organización. Intenta de nuevo más tarde.', 'warning');
|
||||
return;
|
||||
}
|
||||
// Build query params from filtersCumplimiento and add organizacion_id
|
||||
@@ -97,11 +77,13 @@ export default function Reports() {
|
||||
const url = `${import.meta.env.VITE_EFC_API_URL}/reports/table-summary/${params ? `?${params}` : ''}`;
|
||||
try {
|
||||
const res = await fetchWithAuth(url);
|
||||
const data = await res.json();
|
||||
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');
|
||||
}
|
||||
};
|
||||
// Filtros replicados de TableroAlmacenamiento
|
||||
@@ -143,8 +125,8 @@ export default function Reports() {
|
||||
// Build query params from filtersCumplimiento and add organizacion_id
|
||||
const paramsObj = { ...filtersControlPedimento };
|
||||
|
||||
if(paramsObj.organizacion_id == ''){
|
||||
alert('No se pudo obtener el organizacion_id. Selecciona tu organizacion para intenta de nuevo.');
|
||||
if (paramsObj.organizacion_id === '') {
|
||||
showMessage('Selecciona tu organización antes de generar el reporte.', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -155,11 +137,13 @@ export default function Reports() {
|
||||
const url = `${import.meta.env.VITE_EFC_API_URL}/reports/control-pedimento/${params ? `?${params}` : ''}`;
|
||||
try {
|
||||
const res = await fetchWithAuth(url);
|
||||
const data = await res.json();
|
||||
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');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -189,6 +173,31 @@ export default function Reports() {
|
||||
const isDebugMode = import.meta.env.VITE_DEBUG_MODE === 'true';
|
||||
const { showMessage } = useNotification();
|
||||
|
||||
const handleDownloadReport = async (reportId) => {
|
||||
try {
|
||||
const url = `${import.meta.env.VITE_EFC_API_URL}/reports/report-document-download/${reportId}/`;
|
||||
const res = await fetchWithAuth(url);
|
||||
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');
|
||||
if (disposition && disposition.includes('filename=')) {
|
||||
filename = disposition.split('filename=')[1].replace(/"/g, '').trim();
|
||||
}
|
||||
const link = document.createElement('a');
|
||||
link.href = window.URL.createObjectURL(blob);
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
} catch (err) {
|
||||
showMessage(err.message || 'No se pudo descargar el reporte', 'error');
|
||||
}
|
||||
};
|
||||
|
||||
const [isExporting, setIsExporting] = useState(false);
|
||||
const [exportFormat, setExportFormat] = useState('excel');
|
||||
const [showExportSuccess, setShowExportSuccess] = useState(false);
|
||||
|
||||
Reference in New Issue
Block a user