Se soluciono autenticacion
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { fetchProcesamientoPedimentos } from '../api/procesos.ts';
|
||||
import { postWithAuth } from '../fetchWithAuth';
|
||||
const API_URL = import.meta.env.VITE_EFC_API_URL;
|
||||
const MICROSERVICE_URL = import.meta.env.VITE_EFC_MICROSERVICE_URL;
|
||||
|
||||
@@ -62,31 +63,26 @@ export default function Procesos() {
|
||||
setExecutingId(null);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const token = localStorage.getItem('access');
|
||||
if (!token) {
|
||||
alert('No hay token de autenticación. Por favor, inicia sesión nuevamente.');
|
||||
setExecutingId(null);
|
||||
return;
|
||||
}
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
};
|
||||
const body = JSON.stringify({
|
||||
const body = {
|
||||
pedimento: typeof proc.pedimento === 'object' && proc.pedimento !== null ? proc.pedimento.id : proc.pedimento,
|
||||
organizacion: proc.organizacion_id || proc.organizacion || proc.organizacionId,
|
||||
});
|
||||
const res = await fetch(`${MICROSERVICE_URL}${endpoint}`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body,
|
||||
});
|
||||
};
|
||||
|
||||
const res = await postWithAuth(`${MICROSERVICE_URL}${endpoint}`, body);
|
||||
|
||||
if (!res.ok) throw new Error('Error al ejecutar el servicio');
|
||||
|
||||
alert('Servicio ejecutado correctamente');
|
||||
setOpenDropdownId(null);
|
||||
} catch (err) {
|
||||
alert('Error al ejecutar el servicio: ' + (err instanceof Error ? err.message : String(err)));
|
||||
console.error('Error executing service:', err);
|
||||
if (err.message === 'SESSION_EXPIRED') {
|
||||
alert('Tu sesión ha expirado. Por favor, inicia sesión nuevamente.');
|
||||
} else {
|
||||
alert('Error al ejecutar el servicio: ' + (err instanceof Error ? err.message : String(err)));
|
||||
}
|
||||
} finally {
|
||||
setExecutingId(null);
|
||||
}
|
||||
@@ -115,41 +111,29 @@ export default function Procesos() {
|
||||
setLoading(true);
|
||||
setError('');
|
||||
try {
|
||||
const token = localStorage.getItem('access');
|
||||
if (!token) {
|
||||
setError('No hay token de autenticación. Por favor, inicia sesión nuevamente.');
|
||||
return;
|
||||
}
|
||||
// Construir query params
|
||||
const params = new URLSearchParams();
|
||||
params.append('page', String(page));
|
||||
params.append('page_size', String(itemsPerPage));
|
||||
if (pedimentoPedimentoFilter) params.append('pedimento__pedimento', pedimentoPedimentoFilter);
|
||||
if (estadoFilter) params.append('estado', estadoFilter);
|
||||
if (servicioFilter) params.append('servicio', servicioFilter);
|
||||
// Construir filtros
|
||||
const filters = {};
|
||||
if (pedimentoPedimentoFilter) filters['pedimento__pedimento'] = pedimentoPedimentoFilter;
|
||||
if (estadoFilter) filters['estado'] = estadoFilter;
|
||||
if (servicioFilter) filters['servicio'] = servicioFilter;
|
||||
if (sortField) {
|
||||
params.append('ordering', (sortOrder === 'desc' ? '-' : '') + sortField);
|
||||
filters['ordering'] = (sortOrder === 'desc' ? '-' : '') + sortField;
|
||||
}
|
||||
const API_URL = import.meta.env.VITE_EFC_API_URL;
|
||||
const headers = {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
console.log('Fetching procesos with token:', token ? 'Token present' : 'No token');
|
||||
console.log('URL:', `${API_URL}/customs/procesamientopedimentos/?${params.toString()}`);
|
||||
const res = await fetch(`${API_URL}/customs/procesamientopedimentos/?${params.toString()}`, { headers });
|
||||
console.log('Response status:', res.status);
|
||||
if (!res.ok) {
|
||||
const errorText = await res.text();
|
||||
console.log('Error response:', errorText);
|
||||
throw new Error(`Error al obtener procesamiento de pedimentos: ${res.status} - ${errorText}`);
|
||||
}
|
||||
const data = await res.json();
|
||||
|
||||
console.log('Fetching procesos with filters:', filters);
|
||||
|
||||
const data = await fetchProcesamientoPedimentos(page, itemsPerPage, filters);
|
||||
|
||||
console.log('Data received:', data);
|
||||
setProcesos(data.results || []);
|
||||
setCount(data.count || 0);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
console.error('Error fetching procesos:', err);
|
||||
if (err.message === 'SESSION_EXPIRED') {
|
||||
setError('Tu sesión ha expirado. Por favor, inicia sesión nuevamente.');
|
||||
} else {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user