diff --git a/src/pages/Datastage.jsx b/src/pages/Datastage.jsx index a028e9f..2860b1a 100644 --- a/src/pages/Datastage.jsx +++ b/src/pages/Datastage.jsx @@ -60,10 +60,8 @@ function RegistrosCargadosModal({ open, onClose, registros }) { } // Procesar datastage (adaptado para mostrar registros cargados) -// Recibe setEnProcesoId como argumento para manejar el estado desde el componente -async function procesarDatastage(item, setDatastages, setSuccess, setError, setRegistrosCargados, setShowRegistrosModal, setEnProcesoId) { +async function procesarDatastage(item, setDatastages, setSuccess, setError, setRegistrosCargados, setShowRegistrosModal) { try { - setEnProcesoId(item.id); const url = `${import.meta.env.VITE_EFC_API_URL}/datastage/datastages/${item.id}/procesar/`; const body = { organizacion: item.organizacion, @@ -75,23 +73,26 @@ async function procesarDatastage(item, setDatastages, setSuccess, setError, setR headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }); + const data = await res.json(); if (res.status === 200) { // PATCH para marcar como procesado en backend await patchProcesadoTrue(item); setDatastages(prev => prev.map(d => d.id === item.id ? { ...d, procesado: true } : d)); - setSuccess('Procesado correctamente'); - const data = await res.json(); + // Mostrar el mensaje con task_id y detail si existen + if (data && data.task_id && data.detail) { + setSuccess(`Procesamiento iniciado.\nTask ID: ${data.task_id}\n${data.detail}`); + } else { + setSuccess('Procesado correctamente'); + } if (data && data.registros_cargados) { setRegistrosCargados(data.registros_cargados); setShowRegistrosModal(true); } } else { - setError('No se pudo procesar el datastage'); + setError(data && data.detail ? data.detail : 'No se pudo procesar el datastage'); } } catch (e) { setError('No se pudo procesar el datastage'); - } finally { - setEnProcesoId(null); } } // Descarga autenticada de archivos datastage @@ -132,8 +133,6 @@ export default function Datastage() { // Animación header const [showAnimation, setShowAnimation] = useState(false); const [hasAnimated, setHasAnimated] = useState(false); - // Estado para mostrar mensaje "En proceso" por cada datastage - const [enProcesoId, setEnProcesoId] = useState(null); useLayoutEffect(() => { setShowAnimation(true); }, []); useEffect(() => { if (showAnimation && !hasAnimated) setTimeout(() => setHasAnimated(true), 800); }, [showAnimation, hasAnimated]); @@ -186,6 +185,46 @@ export default function Datastage() { setLoading(false); }; + // Editar + const handleEdit = async (e) => { + e.preventDefault(); + setLoading(true); + setError(null); + try { + const fd = new FormData(); + fd.append('contribuyente', form.contribuyente); + if (form.archivo) fd.append('archivo', form.archivo); + await patchFormDataWithAuth(`${import.meta.env.VITE_EFC_API_URL}/datastage/datastages/${editingId}/`, fd); + setForm({ archivo: null, contribuyente: '' }); + setEditingId(null); + setShowEditModal(false); + setSuccess('Datastage actualizado exitosamente'); + setShowSuccessModal(true); + load(); + } catch (e) { + setError(e.message); + } + setLoading(false); + }; + + // Eliminar + const handleDelete = async () => { + if (!deleteId) return; + setLoading(true); + setError(null); + try { + await deleteDatastage(deleteId); + if (selected && selected.id === deleteId) setSelected(null); + setShowDeleteModal(false); + setSuccess('Datastage eliminado exitosamente'); + setShowSuccessModal(true); + load(); + } catch (e) { + setError(e.message); + } + setLoading(false); + }; + // Abrir modal de edición const openEditModal = (item) => { setForm({ archivo: null, contribuyente: item.contribuyente }); @@ -369,18 +408,14 @@ export default function Datastage() { @@ -450,18 +485,14 @@ export default function Datastage() {