From de38f1e4f4363e420d7c4543900c0bb98f47ca21 Mon Sep 17 00:00:00 2001 From: truph01 Date: Mon, 11 Nov 2024 09:55:58 +0700 Subject: [PATCH 1/5] fix: Second approver unapproval shows 'Waiting for first approver' in next steps --- src/libs/NextStepUtils.ts | 12 ++++++++---- src/libs/actions/IOU.ts | 12 ++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index 64db07491100..46a98742c5d3 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -11,6 +11,7 @@ import type DeepValueOf from '@src/types/utils/DeepValueOf'; import {getNextApproverAccountID} from './actions/IOU'; import DateUtils from './DateUtils'; import EmailUtils from './EmailUtils'; +import {getLoginsByAccountIDs} from './PersonalDetailsUtils'; import * as PolicyUtils from './PolicyUtils'; import * as ReportUtils from './ReportUtils'; @@ -66,8 +67,8 @@ function parseMessage(messages: Message[] | undefined) { return `${formattedHtml}`; } -function getNextApproverDisplayName(report: OnyxEntry) { - const approverAccountID = getNextApproverAccountID(report); +function getNextApproverDisplayName(report: OnyxEntry, isUnapprove?: boolean) { + const approverAccountID = getNextApproverAccountID(report, isUnapprove); return ReportUtils.getDisplayNameForParticipant(approverAccountID) ?? ReportUtils.getPersonalDetailsForAccountID(approverAccountID).login; } @@ -80,7 +81,7 @@ function getNextApproverDisplayName(report: OnyxEntry) { * @param parameters.isPaidWithExpensify - Whether a report has been paid with Expensify or outside * @returns nextStep */ -function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf): ReportNextStep | null { +function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf, isUnapprove?: boolean): ReportNextStep | null { if (!ReportUtils.isExpenseReport(report)) { return null; } @@ -90,7 +91,9 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf, predictedNextStatus: ValueOf) { +function getNextApproverAccountID(report: OnyxEntry, isUnapproved = false) { const ownerAccountID = report?.ownerAccountID ?? -1; const policy = PolicyUtils.getPolicy(report?.policyID); const approvalChain = ReportUtils.getApprovalChain(policy, ownerAccountID, report?.total ?? 0); const submitToAccountID = PolicyUtils.getSubmitToAccountID(policy, ownerAccountID); + if (isUnapproved) { + if (approvalChain.includes(currentUserEmail)) { + return userAccountID; + } else { + return report?.managerID; + } + } + if (approvalChain.length === 0) { return submitToAccountID; } @@ -7354,7 +7362,7 @@ function unapproveExpenseReport(expenseReport: OnyxEntry) { const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`] ?? null; const optimisticUnapprovedReportAction = ReportUtils.buildOptimisticUnapprovedReportAction(expenseReport.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID); - const optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, CONST.REPORT.STATUS_NUM.SUBMITTED); + const optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, CONST.REPORT.STATUS_NUM.SUBMITTED, true); const optimisticReportActionData: OnyxUpdate = { onyxMethod: Onyx.METHOD.MERGE, From 75b8cbab807c2f3ca741f58f25f604fe265e2c06 Mon Sep 17 00:00:00 2001 From: truph01 Date: Mon, 11 Nov 2024 11:05:17 +0700 Subject: [PATCH 2/5] fix: lint --- src/libs/actions/IOU.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 185cd65ff9e3..71ce740b129f 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7175,9 +7175,9 @@ function getNextApproverAccountID(report: OnyxEntry, isUnappro if (isUnapproved) { if (approvalChain.includes(currentUserEmail)) { return userAccountID; - } else { - return report?.managerID; } + + return report?.managerID; } if (approvalChain.length === 0) { From eda8b74a43da036fc845fe48b5a1de59547869f3 Mon Sep 17 00:00:00 2001 From: truph01 Date: Tue, 12 Nov 2024 22:35:33 +0700 Subject: [PATCH 3/5] fix: lint --- src/libs/actions/IOU.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 56a9b14a4f20..e4e9b4770530 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -6865,7 +6865,6 @@ function isLastApprover(approvalChain: string[]): boolean { } function getNextApproverAccountID(report: OnyxEntry, isUnapproved = false) { - const ownerAccountID = report?.ownerAccountID ?? -1; const policy = PolicyUtils.getPolicy(report?.policyID); const approvalChain = ReportUtils.getApprovalChain(policy, report); const submitToAccountID = PolicyUtils.getSubmitToAccountID(policy, report); From b6b29ad300c1c557839806a141e5556c35e2e088 Mon Sep 17 00:00:00 2001 From: truph01 Date: Sat, 1 Feb 2025 03:32:12 +0700 Subject: [PATCH 4/5] fix: lint --- src/libs/NextStepUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index 67963c7fd7f3..566f1cb9d99f 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -91,7 +91,7 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf Date: Sat, 1 Feb 2025 03:33:55 +0700 Subject: [PATCH 5/5] fix: lint --- src/libs/NextStepUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index 566f1cb9d99f..7854ef2dc022 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -93,7 +93,7 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf