From b218fd8cd40f1a335a9951c9b852571280c29a69 Mon Sep 17 00:00:00 2001 From: faisolavolut Date: Mon, 3 Mar 2025 11:21:39 +0700 Subject: [PATCH] fix: enhance approval logic in showApprovel function by adding role checks and removing unnecessary console logs --- utils/conditionalMPR.ts | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/utils/conditionalMPR.ts b/utils/conditionalMPR.ts index 6f615be..16fcbb3 100644 --- a/utils/conditionalMPR.ts +++ b/utils/conditionalMPR.ts @@ -43,24 +43,23 @@ export const showApprovel = ( const isField = data?.organization_category === "Non Field" ? false : true; if (data?.status === "NEED APPROVAL") { if (data?.department_head && !data?.vp_gm_director) { - return { - approve: - action === "reject" - ? "REJECTED" - : isField - ? "APPROVED" - : "NEED APPROVAL", - level: "Level VP", - }; + if (role.dir) { + return { + approve: + action === "reject" + ? "REJECTED" + : isField + ? "APPROVED" + : "NEED APPROVAL", + level: "Level VP", + }; + } else { + return null; + } } else if (data?.vp_gm_director && !data?.ceo) { return null; - return { - approve: action === "reject" ? "REJECTED" : "APPROVED", - level: "Level VP", - }; } } else if (data?.status === "IN PROGRESS") { - console.log(data?.requestor_id, get_user("employee.id")); const isYou = data?.requestor_id === get_user("employee.id"); if (role?.head) return { @@ -88,7 +87,6 @@ export const showApprovel = ( if (role?.head) { return null; } - console.log({ role }); if (isBudget) { if (!data?.hrd_ho_unit_name) { return { @@ -97,6 +95,7 @@ export const showApprovel = ( }; } } else { + // off budget if (data?.department_head && !data?.vp_gm_director) { return { approve: