Se soluciono autenticacion
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import React, { useEffect, useState, useLayoutEffect, useRef } from 'react';
|
||||
import { fetchWithAuth, postWithAuth } from '../fetchWithAuth';
|
||||
// Animación fade-in/slide-up para bloques
|
||||
const fadeInSlideUp = `@keyframes fadein-slideup { 0% { opacity: 0; transform: translateY(40px); } 100% { opacity: 1; transform: translateY(0); } }`;
|
||||
if (typeof document !== 'undefined' && !document.getElementById('fadein-slideup-documents')) {
|
||||
@@ -15,35 +16,28 @@ import { Link } from 'react-router-dom';
|
||||
const API_URL = import.meta.env.VITE_EFC_API_URL;
|
||||
|
||||
const downloadFile = async (id, filename = 'archivo', setSuccess, setError, showMessage) => {
|
||||
const token = localStorage.getItem('access');
|
||||
const res = await fetch(`${API_URL}/record/documents/descargar/${id}/`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
if (res.status === 401) {
|
||||
showMessage('Tu sesión ha expirado, por favor inicia sesión de nuevo.', 'error');
|
||||
localStorage.removeItem('access');
|
||||
localStorage.removeItem('refresh');
|
||||
setTimeout(() => {
|
||||
window.location.href = '/login';
|
||||
}, 2000);
|
||||
return;
|
||||
try {
|
||||
const res = await fetchWithAuth(`${API_URL}/record/documents/descargar/${id}/`);
|
||||
|
||||
if (!res.ok) {
|
||||
alert('No autorizado o error en la descarga');
|
||||
return;
|
||||
}
|
||||
|
||||
const blob = await res.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
window.URL.revokeObjectURL(url);
|
||||
if (setSuccess) setSuccess('Descarga exitosa');
|
||||
} catch (error) {
|
||||
console.error('Error downloading file:', error);
|
||||
showMessage('Error al descargar el archivo', 'error');
|
||||
}
|
||||
if (!res.ok) {
|
||||
alert('No autorizado o error en la descarga');
|
||||
return;
|
||||
}
|
||||
const blob = await res.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
window.URL.revokeObjectURL(url);
|
||||
if (setSuccess) setSuccess('Descarga exitosa');useEffect
|
||||
};
|
||||
|
||||
export default function Documents() {
|
||||
@@ -83,7 +77,6 @@ export default function Documents() {
|
||||
|
||||
// Fetching usando la función tipada de TypeScript
|
||||
const fetchPedimentosData = async (page = currentPage, pageSize = itemsPerPage) => {
|
||||
const token = localStorage.getItem('access');
|
||||
// Construir objeto de filtros
|
||||
const filters = {
|
||||
search: searchFilter || undefined,
|
||||
@@ -98,7 +91,7 @@ export default function Documents() {
|
||||
tipo_operacion: tipoOperacionFilter || undefined,
|
||||
clave_pedimento: clavePedimentoFilter || undefined,
|
||||
};
|
||||
return await fetchDocuments(token, page, pageSize, filters);
|
||||
return await fetchDocuments(page, pageSize, filters);
|
||||
};
|
||||
|
||||
// Hook de polling que se ejecuta cada 30 segundos
|
||||
|
||||
Reference in New Issue
Block a user