@@ -68,7 +68,7 @@ import Log from '@libs/Log';
6868import isReportOpenInRHP from '@libs/Navigation/helpers/isReportOpenInRHP';
6969import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute';
7070import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
71- import {buildNextStep, buildNextStepNew } from '@libs/NextStepUtils';
71+ import {buildNextStep} from '@libs/NextStepUtils';
7272import * as NumberUtils from '@libs/NumberUtils';
7373import {getManagerMcTestParticipant, getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils';
7474import Parser from '@libs/Parser';
@@ -170,7 +170,6 @@ import {
170170 hasOutstandingChildRequest,
171171 hasReportBeenReopened,
172172 hasReportBeenRetracted,
173- hasViolations as hasViolationsReportUtils,
174173 isArchivedReport,
175174 isClosedReport as isClosedReportUtil,
176175 isDraftReport,
@@ -10110,6 +10109,13 @@ function getIOUReportActionToApproveOrPay(chatReport: OnyxEntry<OnyxTypes.Report
1011010109 });
1011110110}
1011210111
10112+ function isLastApprover(approvalChain: string[]): boolean {
10113+ if (approvalChain.length === 0) {
10114+ return true;
10115+ }
10116+ return approvalChain.at(-1) === currentUserEmail;
10117+ }
10118+
1011310119function approveMoneyRequest(expenseReport: OnyxEntry<OnyxTypes.Report>, full?: boolean) {
1011410120 if (!expenseReport) {
1011510121 return;
@@ -10131,23 +10137,13 @@ function approveMoneyRequest(expenseReport: OnyxEntry<OnyxTypes.Report>, full?:
1013110137
1013210138 // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
1013310139 // eslint-disable-next-line @typescript-eslint/no-deprecated
10134- const policy = getPolicy(expenseReport.policyID);
10135- const nextApproverAccountID = getNextApproverAccountID(expenseReport);
10136- const predictedNextStatus = !nextApproverAccountID ? CONST.REPORT.STATUS_NUM.APPROVED : CONST.REPORT.STATUS_NUM.SUBMITTED;
10137- const predictedNextState = !nextApproverAccountID ? CONST.REPORT.STATE_NUM.APPROVED : CONST.REPORT.STATE_NUM.SUBMITTED;
10138- const managerID = !nextApproverAccountID ? expenseReport.managerID : nextApproverAccountID;
10140+ const approvalChain = getApprovalChain(getPolicy(expenseReport.policyID), expenseReport);
1013910141
10140- const hasViolations = hasViolationsReportUtils(expenseReport.reportID, allTransactionViolations);
10141- const isASAPSubmitBetaEnabled = Permissions.isBetaEnabled(CONST.BETAS.ASAP_SUBMIT, allBetas);
10142- const optimisticNextStep = buildNextStepNew({
10143- report: expenseReport,
10144- policy,
10145- currentUserAccountIDParam: userAccountID,
10146- currentUserEmailParam: currentUserEmail,
10147- hasViolations,
10148- isASAPSubmitBetaEnabled,
10149- predictedNextStatus,
10150- });
10142+ const predictedNextStatus = isLastApprover(approvalChain) ? CONST.REPORT.STATUS_NUM.APPROVED : CONST.REPORT.STATUS_NUM.SUBMITTED;
10143+ const predictedNextState = isLastApprover(approvalChain) ? CONST.REPORT.STATE_NUM.APPROVED : CONST.REPORT.STATE_NUM.SUBMITTED;
10144+ const managerID = isLastApprover(approvalChain) ? expenseReport.managerID : getNextApproverAccountID(expenseReport);
10145+
10146+ const optimisticNextStep = buildNextStep(expenseReport, predictedNextStatus);
1015110147 const chatReport = getReportOrDraftReport(expenseReport.chatReportID);
1015210148
1015310149 const optimisticReportActionsData: OnyxUpdate = {
0 commit comments