From 14e2702aca1fbeae33befe2e9bce2ba2c5d9071d Mon Sep 17 00:00:00 2001 From: Joao Correia Date: Thu, 20 Feb 2025 10:40:31 +0000 Subject: [PATCH 1/3] add error message and stop loading if something went wrong while loading exam in approval workflow --- src/lib/createWorkflowsOnExamCreation.ts | 2 +- src/pages/approval-workflows/[id]/index.tsx | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib/createWorkflowsOnExamCreation.ts b/src/lib/createWorkflowsOnExamCreation.ts index e2a791af..0f8e1c53 100644 --- a/src/lib/createWorkflowsOnExamCreation.ts +++ b/src/lib/createWorkflowsOnExamCreation.ts @@ -72,7 +72,7 @@ export async function createApprovalWorkflowOnExamCreation(examAuthor: string, e if (totalCount === 0) { // current behaviour: if no workflow was found skip approval process await db.collection(examModule).updateOne( { id: examId }, - { $set: { id: examId, isDiagnostic: false }}, + { $set: { id: examId, access: "private" }}, { upsert: true } ); } diff --git a/src/pages/approval-workflows/[id]/index.tsx b/src/pages/approval-workflows/[id]/index.tsx index 2b512ba0..dfbedc0f 100644 --- a/src/pages/approval-workflows/[id]/index.tsx +++ b/src/pages/approval-workflows/[id]/index.tsx @@ -261,7 +261,7 @@ export default function Home({ user, initialWorkflow, id, workflowAssignees, wor const exam = await getExamById(examModule, examId.trim()); if (!exam) { toast.error( - "Unknown Exam ID! Please make sure you selected the right module and entered the right exam ID", + "Something went wrong while fetching exam!", { toastId: "invalid-exam-id" } ); setViewExamIsLoading(false); @@ -272,6 +272,13 @@ export default function Home({ user, initialWorkflow, id, workflowAssignees, wor payload: { exams: [exam], modules: [examModule] }, }); router.push("/exam"); + } else { + toast.error( + "Something went wrong while fetching exam!", + { toastId: "invalid-exam-id" } + ); + setViewExamIsLoading(false); + return; } } From 4ac11df6ae73294d35cd44f506908644b3fbc32c Mon Sep 17 00:00:00 2001 From: Joao Correia Date: Thu, 20 Feb 2025 11:27:44 +0000 Subject: [PATCH 2/3] fix examId being cleared when editing approval workflow --- src/pages/approval-workflows/[id]/edit.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pages/approval-workflows/[id]/edit.tsx b/src/pages/approval-workflows/[id]/edit.tsx index aec4fd1f..0c549e13 100644 --- a/src/pages/approval-workflows/[id]/edit.tsx +++ b/src/pages/approval-workflows/[id]/edit.tsx @@ -73,13 +73,9 @@ export default function Home({ user, workflow, workflowEntityApprovers }: Props) })); const editableWorkflow: EditableApprovalWorkflow = { + ...workflow, id: workflow._id?.toString() ?? "", - name: workflow.name, - entityId: workflow.entityId, requester: user.id, // should it change to the editor? - startDate: workflow.startDate, - modules: workflow.modules, - status: workflow.status, steps: editableSteps, }; From b388ee399f62141f98b3c2e86498de71df9de7bf Mon Sep 17 00:00:00 2001 From: Joao Correia Date: Thu, 20 Feb 2025 12:12:00 +0000 Subject: [PATCH 3/3] small refactor --- src/pages/approval-workflows/[id]/index.tsx | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/pages/approval-workflows/[id]/index.tsx b/src/pages/approval-workflows/[id]/index.tsx index dfbedc0f..4048df94 100644 --- a/src/pages/approval-workflows/[id]/index.tsx +++ b/src/pages/approval-workflows/[id]/index.tsx @@ -260,10 +260,7 @@ export default function Home({ user, initialWorkflow, id, workflowAssignees, wor if (examModule && examId) { const exam = await getExamById(examModule, examId.trim()); if (!exam) { - toast.error( - "Something went wrong while fetching exam!", - { toastId: "invalid-exam-id" } - ); + toast.error("Something went wrong while fetching exam!"); setViewExamIsLoading(false); return; } @@ -272,13 +269,6 @@ export default function Home({ user, initialWorkflow, id, workflowAssignees, wor payload: { exams: [exam], modules: [examModule] }, }); router.push("/exam"); - } else { - toast.error( - "Something went wrong while fetching exam!", - { toastId: "invalid-exam-id" } - ); - setViewExamIsLoading(false); - return; } }