Validacion de errores en pediemntos y tipos de transporte
This commit is contained in:
@@ -323,6 +323,7 @@
|
||||
start_date: loadServerDate(datesData?.start_date) || currentDate,
|
||||
end_date: loadServerDate(datesData?.end_date) || end_date,
|
||||
payment_date: loadServerDate(datesData?.payment_date) || payment_date,
|
||||
pedimento_date: loadServerDate(datesData?.pedimento_date) || null,
|
||||
extraction_date: loadServerDate(datesData?.entry_date) || null,
|
||||
original_date: loadServerDate(datesData?.original_date) || null,
|
||||
// Mapeos de sub-recursos
|
||||
|
||||
@@ -470,6 +470,28 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Validar consistencia de la sección de transportes (todos o ninguno)
|
||||
if (generalFormData?.pedimento_transport_means) {
|
||||
const t = generalFormData.pedimento_transport_means;
|
||||
const hasAny = t.destination || t.entry_exit || t.arrival || t.departure;
|
||||
const hasAll = t.destination && t.entry_exit && t.arrival && t.departure;
|
||||
|
||||
if (hasAny && !hasAll) {
|
||||
const missing = [];
|
||||
if (!t.destination) missing.push('Región de Destino');
|
||||
if (!t.entry_exit) missing.push('Método de Entrada');
|
||||
if (!t.arrival) missing.push('Arribo');
|
||||
if (!t.departure) missing.push('Salida');
|
||||
|
||||
toast.error('Sección de Transportes incompleta', {
|
||||
description: `Para guardar esta sección, debes completar: ${missing.join(', ')}.`
|
||||
});
|
||||
saving = false;
|
||||
activeTab = 'general';
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Construir el payload unificado
|
||||
const payload: any = {
|
||||
// Datos generales
|
||||
@@ -511,14 +533,14 @@
|
||||
generalFormData.end_date;
|
||||
if (hasDatesValue) {
|
||||
payload.pedimento_dates = {
|
||||
entry_date: generalFormData.entry_date || null,
|
||||
start_date: generalFormData.start_date || null,
|
||||
pedimento_date: generalFormData.pedimento_date || null,
|
||||
payment_date: generalFormData.payment_date || null,
|
||||
rectification_payment_date: generalFormData.rectification_payment_date || null,
|
||||
extraction_date: generalFormData.extraction_date || null,
|
||||
original_date: generalFormData.original_date || null,
|
||||
end_date: generalFormData.end_date || null
|
||||
entry_date: dateToISO(generalFormData.entry_date),
|
||||
start_date: dateToISO(generalFormData.start_date),
|
||||
pedimento_date: dateToISO(generalFormData.pedimento_date),
|
||||
payment_date: dateToISO(generalFormData.payment_date),
|
||||
rectification_payment_date: dateToISO(generalFormData.rectification_payment_date),
|
||||
extraction_date: dateToISO(generalFormData.extraction_date),
|
||||
original_date: dateToISO(generalFormData.original_date),
|
||||
end_date: dateToISO(generalFormData.end_date)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -543,8 +565,8 @@
|
||||
payload.pedimento_transport_means = {
|
||||
destination: generalFormData.pedimento_transport_means.destination || null,
|
||||
entry_exit: generalFormData.pedimento_transport_means.entry_exit || null,
|
||||
arrival: generalFormData.pedimento_transport_means.arrival || null,
|
||||
departure: generalFormData.pedimento_transport_means.departure || null
|
||||
arrival: generalFormData.pedimento_transport_means.arrival || '',
|
||||
departure: generalFormData.pedimento_transport_means.departure || ''
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1051,7 +1073,9 @@
|
||||
|
||||
// Fallback normal: intentar mostrar algo legible
|
||||
let displayError = '';
|
||||
if (errorStr.includes('{')) {
|
||||
if (errorStr.includes('Error interno de validación') || errorStr.includes('validation error')) {
|
||||
displayError = 'Revisa los datos ingresados. Algunos campos obligatorios podrían estar vacíos o tener un formato incorrecto.';
|
||||
} else if (errorStr.includes('{')) {
|
||||
// Si parece JSON, intentar formatearlo un poco o mostrar mensaje genérico
|
||||
try {
|
||||
const errObj = JSON.parse(errorStr);
|
||||
@@ -1059,7 +1083,7 @@
|
||||
const values = Object.values(errObj).flat();
|
||||
displayError = values.join(', ');
|
||||
} catch {
|
||||
displayError = 'Error al guardar (ver consola)';
|
||||
displayError = 'Error al guardar. Por favor, revisa que todos los campos obligatorios estén completos.';
|
||||
}
|
||||
} else {
|
||||
displayError = errorStr;
|
||||
|
||||
Reference in New Issue
Block a user