Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added upr purchased transitions #159

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions backend/emails/emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const currencyFormatter = new Intl.NumberFormat('en-CA', {
})

const getEmailToSection = async (reporter_id, recipients) => {
const emailToSet = new Set(['[email protected]'])
const emailToSet = new Set(['[email protected]', '[email protected]'])

if (recipients.includes(EMAIL_RECIPIENTS.admin)) {
// TODO: use ADMIN_IDENTIFIERS (rename to ADMIN_EMAILS) after migrating to new onboarding data
Expand Down Expand Up @@ -139,6 +139,44 @@ const sendEmailUPRCreatedToApprovers = async (upr) => {
})
}

const sendEmailUPRPurchasedToReporter = async (upr) => {
const Subject = `[Purchased] ${upr.codename}`
const HTMLPart =
getMainMessageHTML(
`Your UW Finance Purchase Request has been purchased! When the item is ready to be picked up, we will let you know.`
) +
(await getUPRTicketInfoHTML(upr)) +
+getTicketLinkHTML(upr.path)
const To = await getEmailToSection(upr.reporter_id, [
EMAIL_RECIPIENTS.reporter,
])

await sendEmail({
Subject,
HTMLPart,
To,
})
}

const sendEmailUPRPurchasedToCoordinator = async (upr) => {
const Subject = `[Purchased] ${upr.codename}`
const HTMLPart =
getMainMessageHTML(
'Thanks for purchasing the item(s)! When the item is ready to be picked up, please update the ticket below.'
) +
(await getUPRTicketInfoHTML(upr)) +
getTicketLinkHTML(upr.path)
const To = await getEmailToSection(upr.reporter_id, [
EMAIL_RECIPIENTS.coordinator,
])

await sendEmail({
Subject,
HTMLPart,
To,
})
}

const sendEmailPPRApprovedToReporter = async (ppr) => {
const Subject = `[Ready to Buy] ${ppr.codename}`
const HTMLPart =
Expand Down Expand Up @@ -500,10 +538,12 @@ const PaidPersonalPurchaseReimbursementClaimInstructions = (
}

module.exports = {
sendEmailPPRCreatedToApprovers,
sendEmailUPRCreatedToApprovers,
sendEmailPPRApprovedToReporter,
sendEmailUPRApprovedToCoordinator,
sendEmailUPRPurchasedToReporter,
sendEmailUPRPurchasedToCoordinator,
sendEmailPPRApprovedToReporter,
sendEmailPPRCreatedToApprovers,
PurchaseRequestInvalidated,
PersonalPurchaseApproved,
UWFinancePurchaseApproved,
Expand Down
14 changes: 0 additions & 14 deletions backend/service/automation.js

This file was deleted.

2 changes: 1 addition & 1 deletion backend/service/sendEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const sendEmail = async ({ To, Subject, HTMLPart }) => {
})
console.log('sendEmail success!')
} catch (err) {
console.log(`Uh oh! bad sendEmail: ${err}`)
console.log(`sendEmail failed: ${err}`)
}
}

Expand Down
28 changes: 24 additions & 4 deletions backend/service/uwfinancepurchases.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const {
const {
sendEmailUPRCreatedToApprovers,
sendEmailUPRApprovedToCoordinator,
sendEmailUPRPurchasedToCoordinator,
sendEmailUPRPurchasedToReporter,
} = require('../emails/emails')

const getAllUWFinancePurchases = () => {
Expand All @@ -30,10 +32,28 @@ const createNewUWFinancePurchase = async (body) => {
return annotatedUPR
}

const updateUWFinancePurchase = (id, body) => {
return UWFinancePurchase.findByIdAndUpdate(id, body, {
new: true,
})
const updateUWFinancePurchase = async (id, body) => {
const existingPurchaseTicket = await getUWFinancePurchase(id)
// SENT_TO_COORDINATOR -> ORDERED
const newPurchaseTicket = await UWFinancePurchase.findByIdAndUpdate(
id,
body,
{
new: true,
}
)
if (
existingPurchaseTicket.status === 'SENT_TO_COORDINATOR' &&
body.status === 'ORDERED'
) {
const annotatedUPR = await getUWFinancePurchase(id)
const emails = [
sendEmailUPRPurchasedToCoordinator(annotatedUPR),
sendEmailUPRPurchasedToReporter(annotatedUPR),
]
await Promise.all(emails)
}
return newPurchaseTicket
}

const updateFILinkUWFinancePurchase = async (id, new_fi_link) => {
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/components/CreateTicketModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ import { TICKET_ENDPOINTS, TICKET_TYPES } from '../constants'
import { useRecoilState } from 'recoil'
import { allTicketsState } from '../state/atoms'
import { getAllTickets } from '../utils/globalSetters'
import { usePreserveParamsNavigate } from '../hooks/hooks'

export function CreateTicketModal({ isOpen, onClose }) {
const [allTickets, setAllTickets] = useRecoilState(allTicketsState)
const [ticketType, setTicketType] = useState('')
const { control, register, handleSubmit, reset } = useForm()
const [isLoading, setIsLoading] = useState(false)
const preserveParamsNavigate = usePreserveParamsNavigate()
const auth = useAuth()

const displayTicketType = () => {
Expand Down Expand Up @@ -99,9 +101,13 @@ export function CreateTicketModal({ isOpen, onClose }) {
} else if (ticketType === TICKET_TYPES.SF) {
payload.status = 'ALLOCATED'
}
await axiosPreset.post(TICKET_ENDPOINTS[ticketType], payload)
const createdTicket = await axiosPreset.post(
TICKET_ENDPOINTS[ticketType],
payload
)
await getAllTickets(setAllTickets)
onClose()
preserveParamsNavigate(`/${ticketType}/${createdTicket.data._id}`)
} catch (err) {
console.log(err)
} finally {
Expand Down
58 changes: 37 additions & 21 deletions frontend/src/components/TicketContent/UPRAdminContentTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ const UPRAdminContentTable = () => {
setChanged(false)
}

const transitionToPurchased = async () => {
const payload = {
status: 'ORDERED',
po_number: currentTicket.po_number,
requisition_number: currentTicket.requisition_number,
}
await axiosPreset.patch(
`${TICKET_ENDPOINTS.UPR}/${currentTicket._id}`,
payload
)
await getAllTickets(setAllTickets)
setChanged(false)
}

return (
<VStack
border="1px solid black"
Expand All @@ -63,27 +77,29 @@ const UPRAdminContentTable = () => {
</Table>

<Center pb="7px">
<Button
colorScheme="blue"
size="sm"
mr="20px"
disabled={
currentTicket?.po_number?.length +
currentTicket?.requisition_number?.length ===
0
}
>
Transition Status
</Button>

<Button
colorScheme="green"
size="sm"
disabled={!changed}
onClick={saveFields}
>
Save Fields
</Button>
{currentTicket.status === 'SENT_TO_COORDINATOR' ? (
<Button
colorScheme="blue"
size="sm"
mr="20px"
onClick={transitionToPurchased}
disabled={
!currentTicket?.po_number ||
!currentTicket?.requisition_number
}
>
Transition To Purchased
</Button>
) : (
<Button
colorScheme="green"
size="sm"
onClick={saveFields}
disabled={!changed}
>
Save Fields
</Button>
)}
</Center>
</VStack>
)
Expand Down
Loading