Skip to content

Commit

Permalink
Merge pull request #67 from Genesis-Solutions/4.2-hu-emailsend
Browse files Browse the repository at this point in the history
4.2 hu emailsend
  • Loading branch information
AndresMaganaPerez committed Jun 1, 2023
2 parents 1247ac6 + 299e897 commit 4335b5f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
16 changes: 15 additions & 1 deletion GomezMorinFrontEnd/src/components/EditModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { updateForms } from "../queries/queryRequestForm";
import { useNavigate } from "react-router-dom";
import { useDispatch } from "react-redux";
import { setRows } from "../states/formSlice";
import { postEmail } from "../queries/queryApi";
/**
* 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 = ({ idForm, folio, estatus, userId }) => {
const EditModal = ({ idForm, folio, estatus, userId, userPtr }) => {
const navigate = useNavigate();
const methods = useForm();
const [isOpen, setIsOpen] = useState(false);
Expand All @@ -26,6 +27,7 @@ const EditModal = ({ idForm, folio, estatus, userId }) => {
id: item._id,
fecha: item.requestDate,
folio: item.folio,
userPtr: item.userPtr,
tipo: item.membretatedLetterDoc ? "Persona moral" : "Persona física",
evento: item.membretatedLetterDoc ? "-" : item.typeEvent,
nombre: item.membretatedLetterDoc
Expand Down Expand Up @@ -54,6 +56,18 @@ const EditModal = ({ idForm, folio, estatus, userId }) => {
alert(err.response.data.message);
}
setIsOpen(false);
if (estatus != data.estatus) {
try {
const emailData = {
title: "Cambio de estatus",
message: `<p>El estatus de la solicitud con folio: ${data.folio} ha sido modificado a ${data.estatus}</p>`,
userId: userPtr,
};
await postEmail(emailData);
} catch (err) {
alert(err.response.data.message);
}
}
};

/**
Expand Down
2 changes: 2 additions & 0 deletions GomezMorinFrontEnd/src/pages/RequestAll/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const RequestAll = () => {
folio={row.folio}
estatus={row.estatus}
userId={userId}
userPtr = {row.userPtr}
/>
),
},
Expand Down Expand Up @@ -63,6 +64,7 @@ const RequestAll = () => {
id: item._id,
fecha: item.requestDate,
folio: item.folio,
userPtr : item.userPtr,
tipo: item.membretatedLetterDoc ? "Persona moral" : "Persona física",
evento: item.membretatedLetterDoc ? "-" : item.typeEvent,
nombre: item.membretatedLetterDoc
Expand Down
27 changes: 27 additions & 0 deletions GomezMorinFrontEnd/src/queries/queryApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import axios from "axios";
const baseUrl = import.meta.env.VITE_BASE_URL;

/**
* Sends an email notification.
*
* @param {Object} data - The data object containing title, userId, and message.
* @returns {Promise<Object>} - A promise that resolves to the response object.
* @throws {Error} - If an error occurs during the API call.
*/
export const postEmail = async (data) => {
const { title, userId, message } = data;
const user = await axios.get(`${baseUrl}/users/${userId}`);
const email = user.data.email;

const body = {
title: title,
textBody: message,
recipientEmail: email,
};
try {
const response = await axios.post(`${baseUrl}/email`, body);
return response;
} catch (err) {
return Promise.reject(err);
}
};

0 comments on commit 4335b5f

Please sign in to comment.