Skip to content

Commit

Permalink
fix: update edit timestamp consistently in all the actions in interna…
Browse files Browse the repository at this point in the history
…l review
  • Loading branch information
estifraca committed Jan 22, 2025
1 parent c9f6a6f commit fa77bf2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions components/dialog/UgTutorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ const UgTutorDialog: FC<UgTutorDialogProps> = ({ data, reviewerLogin, user }) =>
const upsertOutcomeWithId = async (prevState: FormPassbackState, formData: FormData) => {
return await updateOutcomes(
id,
email,
data.outcomes.map((o) => ({
id: o.id,
degreeCode: o.degreeCode
Expand Down
12 changes: 9 additions & 3 deletions components/table/ApplicationTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ const ApplicationTable: FC<ApplicationTableProps> = ({
}),
columnHelper.accessor('nextAction', {
cell: (info) => (
<NextActionCell nextAction={info.getValue()} applicationId={info.row.original.id} />
<NextActionCell
userEmail={email}
nextAction={info.getValue()}
applicationId={info.row.original.id}
/>
),
header: 'Next Action',
id: SEARCH_PARAM_NEXT_ACTION
Expand Down Expand Up @@ -258,9 +262,10 @@ const WPColourMap: Record<WP, 'green' | 'red' | 'yellow'> = {
[WP.NOT_CALCULATED]: 'yellow'
}

const NextActionCell: FC<{ nextAction: NextAction; applicationId: number }> = ({
const NextActionCell: FC<{ nextAction: NextAction; applicationId: number; userEmail: string }> = ({
nextAction,
applicationId
applicationId,
userEmail
}) => {
return (
<Flex align="center" justify="between" gap="2">
Expand All @@ -271,6 +276,7 @@ const NextActionCell: FC<{ nextAction: NextAction; applicationId: number }> = ({
color="grass"
onClick={async () => {
await updateNextAction(
userEmail,
nextAction === NextAction.INFORM_CANDIDATE
? NextAction.FINAL_CHECK
: NextAction.CANDIDATE_INFORMED,
Expand Down
17 changes: 13 additions & 4 deletions lib/query/forms.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use server'

import prisma from '@/db'
import { getUserFromCycleAndEmail } from '@/lib/query/users'
import {
formAdminSchema,
formCommentSchema,
Expand Down Expand Up @@ -124,6 +123,7 @@ export async function upsertReviewerScoring(

export async function updateOutcomes(
applicationId: number,
userEmail: string,
partialOutcomes: { id: number; degreeCode: string }[],
_: FormPassbackState,
formData: FormData
Expand All @@ -136,7 +136,7 @@ export async function updateOutcomes(
return { id, ...parsedOutcome }
})

await updateNextAction(formData.get('nextAction'), applicationId)
await updateNextAction(userEmail, formData.get('nextAction'), applicationId)

for (const { id, offerCode, offerText, decision } of fullOutcomes) {
await prisma.outcome.update({
Expand Down Expand Up @@ -166,7 +166,7 @@ export async function insertComment(
const result = formCommentSchema.safeParse(Object.fromEntries(formData))
if (!result.success) return { status: 'error', message: result.error.issues[0].message }

await updateNextAction(formData.get('nextAction'), applicationId)
await updateNextAction(authorEmail, formData.get('nextAction'), applicationId)

await prisma.comment.create({
data: {
Expand All @@ -181,12 +181,21 @@ export async function insertComment(
}

export async function updateNextAction(
userEmail: string,
nextActionInput: FormDataEntryValue | string | null,
applicationId: number
) {
if (!nextActionInput || nextActionInput === 'Unchanged') return
await prisma.internalReview.update({
where: { applicationId },
data: {
lastUserEditBy: userEmail,
lastUserEditOn: new Date()
}
})

if (!nextActionInput || nextActionInput === 'Unchanged') return
const nextAction = nextActionField.parse(nextActionInput)

await prisma.application.update({
where: { id: applicationId },
data: {
Expand Down

0 comments on commit fa77bf2

Please sign in to comment.