Se modifico formulario de actualizazcion
This commit is contained in:
6
.env
6
.env
@@ -1,4 +1,4 @@
|
||||
DEBUG_MODE=false
|
||||
VITE_DEBUG_MODE=false
|
||||
|
||||
VITE_EFC_API_URL=https://api.efc-aduanasoft.com/api/v1
|
||||
VITE_EFC_MICROSERVICE_URL=https://api.efc-aduanasoft.com/microservice/api/v1
|
||||
VITE_EFC_API_URL=http://192.168.1.195:8000/api/v1
|
||||
VITE_EFC_MICROSERVICE_URL=http://192.168.1.195:8001/api/v1
|
||||
|
||||
@@ -289,4 +289,140 @@ export const postFormDataWithAuth = async (url, formData) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Función para hacer peticiones PUT con FormData (para archivos)
|
||||
export const putFormDataWithAuth = async (url, formData) => {
|
||||
let token = localStorage.getItem('access');
|
||||
|
||||
const options = {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
...(token && { 'Authorization': `Bearer ${token}` })
|
||||
},
|
||||
body: formData
|
||||
};
|
||||
|
||||
try {
|
||||
let response = await fetch(url, options);
|
||||
|
||||
if (response.status === 401) {
|
||||
if (!isRefreshing) {
|
||||
isRefreshing = true;
|
||||
|
||||
try {
|
||||
const newToken = await refreshToken();
|
||||
processQueue(null, newToken);
|
||||
|
||||
options.headers['Authorization'] = `Bearer ${newToken}`;
|
||||
response = await fetch(url, options);
|
||||
|
||||
} catch (refreshError) {
|
||||
processQueue(refreshError, null);
|
||||
throw refreshError;
|
||||
} finally {
|
||||
isRefreshing = false;
|
||||
}
|
||||
} else {
|
||||
// Ya hay un refresh en proceso, agregar esta petición a la cola
|
||||
return new Promise((resolve, reject) => {
|
||||
failedQueue.push({
|
||||
resolve: (token) => {
|
||||
options.headers['Authorization'] = `Bearer ${token}`;
|
||||
fetch(url, options)
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
},
|
||||
reject
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (response.status === 401) {
|
||||
localStorage.removeItem('access');
|
||||
localStorage.removeItem('refresh');
|
||||
localStorage.removeItem('user_id');
|
||||
localStorage.removeItem('user_is_importador');
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.href = '/login';
|
||||
}, 1000);
|
||||
|
||||
throw new Error('Session expired');
|
||||
}
|
||||
|
||||
return response;
|
||||
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Función para hacer peticiones PATCH con FormData (para archivos)
|
||||
export const patchFormDataWithAuth = async (url, formData) => {
|
||||
let token = localStorage.getItem('access');
|
||||
|
||||
const options = {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
...(token && { 'Authorization': `Bearer ${token}` })
|
||||
},
|
||||
body: formData
|
||||
};
|
||||
|
||||
try {
|
||||
let response = await fetch(url, options);
|
||||
|
||||
if (response.status === 401) {
|
||||
if (!isRefreshing) {
|
||||
isRefreshing = true;
|
||||
|
||||
try {
|
||||
const newToken = await refreshToken();
|
||||
processQueue(null, newToken);
|
||||
|
||||
options.headers['Authorization'] = `Bearer ${newToken}`;
|
||||
response = await fetch(url, options);
|
||||
|
||||
} catch (refreshError) {
|
||||
processQueue(refreshError, null);
|
||||
throw refreshError;
|
||||
} finally {
|
||||
isRefreshing = false;
|
||||
}
|
||||
} else {
|
||||
// Ya hay un refresh en proceso, agregar esta petición a la cola
|
||||
return new Promise((resolve, reject) => {
|
||||
failedQueue.push({
|
||||
resolve: (token) => {
|
||||
options.headers['Authorization'] = `Bearer ${token}`;
|
||||
fetch(url, options)
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
},
|
||||
reject
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (response.status === 401) {
|
||||
localStorage.removeItem('access');
|
||||
localStorage.removeItem('refresh');
|
||||
localStorage.removeItem('user_id');
|
||||
localStorage.removeItem('user_is_importador');
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.href = '/login';
|
||||
}, 1000);
|
||||
|
||||
throw new Error('Session expired');
|
||||
}
|
||||
|
||||
return response;
|
||||
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export default fetchWithAuth;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { fetchWithAuth, postWithAuth, putWithAuth, deleteWithAuth } from '../fetchWithAuth';
|
||||
import { fetchWithAuth, postWithAuth, putWithAuth, deleteWithAuth, putFormDataWithAuth, postFormDataWithAuth } from '../fetchWithAuth';
|
||||
|
||||
const API_URL = import.meta.env.VITE_EFC_API_URL;
|
||||
export default function Vucem() {
|
||||
@@ -931,7 +931,7 @@ export default function Vucem() {
|
||||
formData.append('acuseedocument', form.acuseedocument);
|
||||
formData.append('is_active', form.is_active);
|
||||
try {
|
||||
const res = await postWithAuth(`${API_URL}/vucem/vucem/`, formData);
|
||||
const res = await postFormDataWithAuth(`${API_URL}/vucem/vucem/`, formData);
|
||||
if (!res.ok) throw new Error('Error al crear VUCEM');
|
||||
await fetchVucem();
|
||||
closeModals();
|
||||
@@ -1095,7 +1095,7 @@ export default function Vucem() {
|
||||
formData.append('acuseedocument', form.acuseedocument);
|
||||
formData.append('is_active', form.is_active);
|
||||
try {
|
||||
const res = await putWithAuth(`${API_URL}/vucem/vucem/${editVucem.id}/`, formData);
|
||||
const res = await putFormDataWithAuth(`${API_URL}/vucem/vucem/${editVucem.id}/`, formData);
|
||||
if (!res.ok) throw new Error('Error al actualizar VUCEM');
|
||||
await fetchVucem();
|
||||
closeModals();
|
||||
|
||||
Reference in New Issue
Block a user