From 6585e25c3264b106ff99967d88c80765023bafe0 Mon Sep 17 00:00:00 2001 From: Cuenta Generica Date: Fri, 14 Nov 2025 17:33:19 -0600 Subject: [PATCH 1/4] Edit Application v1 --- .../components/EditApplicationModal.jsx | 254 +++++++++++++++ .../features/projects/components/archivo.md | 52 ---- .../projects/hooks/useApplicationDetails.js | 69 +++-- .../projects/hooks/useEditApplication.js | 233 ++++++++++++++ .../projects/pages/ApplicationDetails.jsx | 290 ++++++++++-------- .../src/features/projects/projectsService.js | 82 ++++- 6 files changed, 758 insertions(+), 222 deletions(-) create mode 100644 apps/web/src/features/projects/components/EditApplicationModal.jsx delete mode 100644 apps/web/src/features/projects/components/archivo.md create mode 100644 apps/web/src/features/projects/hooks/useEditApplication.js diff --git a/apps/web/src/features/projects/components/EditApplicationModal.jsx b/apps/web/src/features/projects/components/EditApplicationModal.jsx new file mode 100644 index 00000000..35659c93 --- /dev/null +++ b/apps/web/src/features/projects/components/EditApplicationModal.jsx @@ -0,0 +1,254 @@ +import { useEffect } from 'react'; +import useEditApplication from '../hooks/useEditApplication'; +import useFormProjectMetadata from '../hooks/useFormProjectMetadata'; + +/** + * Modal para editar metadata y aprobar una Application + * @param {boolean} isOpen - Si el modal está abierto + * @param {Function} onClose - Callback al cerrar el modal + * @param {string} uuid - UUID de la aplicación + * @param {Object} application - Datos de la aplicación actual + * @param {Function} onSuccess - Callback al aprobar exitosamente + */ +export default function EditApplicationModal({ isOpen, onClose, uuid, application, onSuccess }) { + const { form, fieldErrors, isLoading, handleChange, handleSubmit, initializeForm } = + useEditApplication(uuid, (projectUuid) => { + // ✅ Cerrar modal antes de llamar a onSuccess + onClose(); + + // ✅ Pasar UUID del proyecto al componente padre + onSuccess(projectUuid); + }); + + const { faculties, projectTypes, problemTypes } = useFormProjectMetadata(); + + // Inicializar formulario cuando se abre el modal + useEffect(() => { + if (isOpen && application) { + initializeForm(application); + } + }, [isOpen, application]); + + if (!isOpen) return null; + + const extendedProblemTypes = [...problemTypes, { problem_type_id: "otro", name: "Otro" }]; + + return ( +
+
+ {/* Header */} +
+

+ Editar y Aprobar Proyecto +

+ +
+ + {/* Body */} +
handleSubmit(e, application)} className="p-6 space-y-6"> + {/* Información del proyecto actual */} +
+
+ + + +
+

Proyecto: {application?.title}

+

+ Edita la metadata del proyecto si es necesario. Al guardar, el proyecto será aprobado automáticamente. +

+
+
+
+ + {/* Tipo de proyecto */} +
+ +
+ {projectTypes.map(({ project_type_id, name }) => ( + + ))} +
+ {fieldErrors?.projectType && ( +

{fieldErrors.projectType}

+ )} +
+ + {/* Facultades */} +
+ +
+ {faculties.map(({ faculty_id, name }) => ( + + ))} +
+ {fieldErrors?.faculty && ( +

{fieldErrors.faculty}

+ )} +
+ + {/* Tipo de problemática */} +
+ +
+ {extendedProblemTypes.map(({ problem_type_id, name }) => ( + + ))} +
+ {fieldErrors?.problemType && ( +

{fieldErrors.problemType}

+ )} + + {/* Campo "Otro" */} +{form.problemType.includes('otro') && ( +
+ + + {fieldErrors?.problemTypeOther && ( +

{fieldErrors.problemTypeOther}

+ )} +
+)} + +
+ + {/* Vigencia */} +
+ + + {fieldErrors?.deadline && ( +

{fieldErrors.deadline}

+ )} +
+ + {/* TODO: Razón de edición (placeholder) */} +
+ +