Skip to content

Commit

Permalink
Merge pull request #32 from Genesis-Solutions/4.1-hu-codificacion-que…
Browse files Browse the repository at this point in the history
…ries

4.1 hu codificacion queries
  • Loading branch information
FlavioRr committed May 10, 2023
2 parents 9ea1b02 + cf851c1 commit b3e9cf0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
23 changes: 15 additions & 8 deletions GomezMorinFrontEnd/src/components/EditModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,34 @@ import { FormProvider, useForm } from "react-hook-form";
import { Dialog, Transition } from "@headlessui/react";
import { ModeEditOutline } from "@mui/icons-material";
import DropdownInput from "./DropdownInput";
import { updateForms } from "../queries/queryRequestForm";

/**
* A React component that renders a modal with a form
*
*
* @returns {Jsx.Element} - A React JSX element representing a modal with a form
*/
const EditModal = () => {
const EditModal = ({ idForm }) => {
const methods = useForm();
const [isOpen, setIsOpen] = useState(false);

/**
* Handles the submit of the form
*
*
* @param {object} data
*/
const onSubmit = (data) => {

const onSubmit = async (data) => {
try {
await updateForms({ ...data, idForm: idForm });
} catch (err) {
alert(err.response.data.message);
}
setIsOpen(false);
};

/**
* Handles the closing of the modal
*
*
* @returns {void}
*/

Expand All @@ -38,7 +43,7 @@ const EditModal = () => {

/**
* Handles the opening of the modal
*
*
* @returns {void}
*/
const openModal = () => {
Expand Down Expand Up @@ -92,7 +97,9 @@ const EditModal = () => {
<FormProvider {...methods}>
<div className="flex flex-col justify-between h-full gap-4">
<form
onSubmit={methods.handleSubmit(onSubmit)}
onSubmit={methods.handleSubmit((data) =>
onSubmit(data, idForm)
)}
className="flex flex-col justify-between h-full gap-4"
>
<InputForm
Expand Down
6 changes: 4 additions & 2 deletions GomezMorinFrontEnd/src/pages/RequestAll/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const RequestAll = () => {
field: "actions",
headerName: "",
width: 200,
renderCell: () => <EditModal />,
renderCell: ({ row }) => <EditModal idForm={row.id} />,
},
];

Expand All @@ -41,7 +41,9 @@ const RequestAll = () => {
? item.membretatedLetterDoc
: item.nameEvent,
estatus: item.status,
renderCell: () => <EditModal id={item.id} />,
renderCell: ({ id }) => {
return <EditModal idForm={id} />;
},
}));
};

Expand Down
21 changes: 21 additions & 0 deletions GomezMorinFrontEnd/src/queries/queryRequestForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,24 @@ export const getAllForms = async (userId) => {
return Promise.reject(err);
}
};

/**
* Updates the form with the given ID by sending a PATCH request to the server with the specified data.
*
* @param data an object containing the data to update the form with, including the form's folio number, status, and ID.
* @return a Promise that resolves with the updated form data if the request succeeds, or rejects with an error if the request fails.
*/

export const updateForms = async (data) => {
try {
const { folio, tipoDocumento, idForm } = data;
const response = await axios.patch(
`${baseURL}/solicitudes/updateRequest/${idForm}`,
{ folio, tipoDocumento }
);

return response.data;
} catch (err) {
return Promise.reject(err);
}
};

0 comments on commit b3e9cf0

Please sign in to comment.