From 5cdf67f8ad7103fe81ad7eabfab208e5bd6be9e7 Mon Sep 17 00:00:00 2001 From: Victor Zheng <36215359+victorzheng02@users.noreply.github.com> Date: Wed, 30 Aug 2023 19:39:30 -0400 Subject: [PATCH] ppr purchased and receipts submitted (#161) --- backend/emails/emails.js | 20 +++++++ backend/service/personalpurchases.service.js | 11 +++- .../TicketContent/PPRReporterTable.js | 52 +++++++++++++++++++ frontend/src/pages/Dashboard.js | 13 +++++ 4 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 frontend/src/components/TicketContent/PPRReporterTable.js diff --git a/backend/emails/emails.js b/backend/emails/emails.js index fea4378..00a60c8 100644 --- a/backend/emails/emails.js +++ b/backend/emails/emails.js @@ -217,6 +217,25 @@ const sendEmailUPRApprovedToCoordinator = async (upr) => { }) } +const sendEmailPPRPurchasedAndReceiptsSubmittedToCoordinator = async (ppr) => { + const Subject = `[Purchased And Receipts Submitted] ${ppr.codename}` + const HTMLPart = + getMainMessageHTML( + `Item ${ppr.codename} has been purchased and receipts have been submitted! Please review the expense claim form and reimburse the reporter out of WATonomous' cash account.` + ) + + (await getUPRTicketInfoHTML(ppr)) + + getTicketLinkHTML(ppr.path) + const To = await getEmailToSection(ppr.reporter_id, [ + EMAIL_RECIPIENTS.finance, + EMAIL_RECIPIENTS.coordinator, + ]) + await sendEmail({ + Subject, + HTMLPart, + To, + }) +} + const PurchaseRequestInvalidated = (purchaseRequestDetails) => { const { issue, reporter } = purchaseRequestDetails @@ -544,6 +563,7 @@ module.exports = { sendEmailUPRPurchasedToCoordinator, sendEmailPPRApprovedToReporter, sendEmailPPRCreatedToApprovers, + sendEmailPPRPurchasedAndReceiptsSubmittedToCoordinator, PurchaseRequestInvalidated, PersonalPurchaseApproved, UWFinancePurchaseApproved, diff --git a/backend/service/personalpurchases.service.js b/backend/service/personalpurchases.service.js index 5d9de32..346ce92 100644 --- a/backend/service/personalpurchases.service.js +++ b/backend/service/personalpurchases.service.js @@ -7,6 +7,7 @@ const { const { sendEmailPPRCreatedToApprovers, sendEmailPPRApprovedToReporter, + sendEmailPPRPurchasedAndReceiptsSubmittedToCoordinator, } = require('../emails/emails') const getAllPersonalPurchases = () => { @@ -30,10 +31,16 @@ const createPersonalPurchase = async (body) => { return annotatedPPR } -const updatePersonalPurchase = (id, body) => { - return PersonalPurchase.findByIdAndUpdate(id, body, { +const updatePersonalPurchase = async (id, body) => { + // READY_TO_BUY -> PURCHASED_AND_RECEIPTS_SUBMITTED + const newPurchaseTicket = PersonalPurchase.findByIdAndUpdate(id, body, { new: true, }) + if (body?.status === 'PURCHASED_AND_RECEIPTS_SUBMITTED') { + const annotatedPPR = await getPersonalPurchase(id) + sendEmailPPRPurchasedAndReceiptsSubmittedToCoordinator(annotatedPPR) + } + return newPurchaseTicket } const updateFILinkPersonalPurchase = async (id, new_fi_link) => { diff --git a/frontend/src/components/TicketContent/PPRReporterTable.js b/frontend/src/components/TicketContent/PPRReporterTable.js new file mode 100644 index 0000000..9673043 --- /dev/null +++ b/frontend/src/components/TicketContent/PPRReporterTable.js @@ -0,0 +1,52 @@ +import { Button, Center, Heading, Tooltip, VStack } from '@chakra-ui/react' +import React from 'react' +import { useSetRecoilState } from 'recoil' +import { allTicketsState } from '../../state/atoms' +import { axiosPreset } from '../../axiosConfig' +import { TICKET_ENDPOINTS } from '../../constants' +import { getAllTickets } from '../../utils/globalSetters' + +const PPRReporterTable = ({ currentTicket, supportingDocuments }) => { + const setAllTickets = useSetRecoilState(allTicketsState) + + const transitionToPurchasedAndReceiptsSubmitted = async () => { + const payload = { + status: 'PURCHASED_AND_RECEIPTS_SUBMITTED', + } + await axiosPreset.patch( + `${TICKET_ENDPOINTS.PPR}/${currentTicket._id}`, + payload + ) + await getAllTickets(setAllTickets) + } + + return ( + + Reporter View +
+ + + +
+
+ ) +} + +export default PPRReporterTable diff --git a/frontend/src/pages/Dashboard.js b/frontend/src/pages/Dashboard.js index 7515780..8ca392e 100644 --- a/frontend/src/pages/Dashboard.js +++ b/frontend/src/pages/Dashboard.js @@ -44,6 +44,8 @@ import PPRAdminContentTable from '../components/TicketContent/PPRAdminContentTab import FIAdminContentTable from '../components/TicketContent/FIAdminContentTable' import { getAllTickets } from '../utils/globalSetters' import FileViewer from '../components/FileViewer' +import PPRReporterTable from '../components/TicketContent/PPRReporterTable' + const Dashboard = () => { const navigate = useNavigate() const location = useLocation() @@ -103,6 +105,10 @@ const Dashboard = () => { fetchData() }, [setAllTickets]) + const isReporter = () => { + return auth.currentUser.uid === currentTicket.reporter_id + } + const getUploadedFiles = useCallback(async () => { if (!currentTicket?.code) { return @@ -178,6 +184,13 @@ const Dashboard = () => { return ( <> {auth.isAdmin && } + {isReporter() && + currentTicket.status === 'READY_TO_BUY' && ( + + )} )