@@ -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} from '@libs/NextStepUtils';
71+ import {buildNextStep, buildNextStepNew } from '@libs/NextStepUtils';
7272import * as NumberUtils from '@libs/NumberUtils';
7373import {getManagerMcTestParticipant, getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils';
7474import Parser from '@libs/Parser';
@@ -170,6 +170,7 @@ import {
170170 hasOutstandingChildRequest,
171171 hasReportBeenReopened,
172172 hasReportBeenRetracted,
173+ hasViolations as hasViolationsReportUtils,
173174 isArchivedReport,
174175 isClosedReport as isClosedReportUtil,
175176 isDraftReport,
@@ -10100,13 +10101,6 @@ function getIOUReportActionToApproveOrPay(chatReport: OnyxEntry<OnyxTypes.Report
1010010101 });
1010110102}
1010210103
10103- function isLastApprover(approvalChain: string[]): boolean {
10104- if (approvalChain.length === 0) {
10105- return true;
10106- }
10107- return approvalChain.at(-1) === currentUserEmail;
10108- }
10109-
1011010104function approveMoneyRequest(expenseReport: OnyxEntry<OnyxTypes.Report>, full?: boolean) {
1011110105 if (!expenseReport) {
1011210106 return;
@@ -10128,13 +10122,23 @@ function approveMoneyRequest(expenseReport: OnyxEntry<OnyxTypes.Report>, full?:
1012810122
1012910123 // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
1013010124 // eslint-disable-next-line deprecation/deprecation
10131- const approvalChain = getApprovalChain( getPolicy(expenseReport.policyID), expenseReport );
10132-
10133- const predictedNextStatus = isLastApprover(approvalChain) ? CONST.REPORT.STATUS_NUM.APPROVED : CONST.REPORT.STATUS_NUM.SUBMITTED;
10134- const predictedNextState = isLastApprover(approvalChain) ? CONST.REPORT.STATE_NUM.APPROVED : CONST.REPORT.STATE_NUM.SUBMITTED;
10135- const managerID = isLastApprover(approvalChain) ? expenseReport.managerID : getNextApproverAccountID(expenseReport) ;
10125+ const policy = getPolicy(expenseReport.policyID);
10126+ const nextApproverAccountID = getNextApproverAccountID(expenseReport);
10127+ const predictedNextStatus = !nextApproverAccountID ? CONST.REPORT.STATUS_NUM.APPROVED : CONST.REPORT.STATUS_NUM.SUBMITTED;
10128+ const predictedNextState = !nextApproverAccountID ? CONST.REPORT.STATE_NUM.APPROVED : CONST.REPORT.STATE_NUM.SUBMITTED;
10129+ const managerID = !nextApproverAccountID ? expenseReport.managerID : nextApproverAccountID ;
1013610130
10137- const optimisticNextStep = buildNextStep(expenseReport, predictedNextStatus);
10131+ const hasViolations = hasViolationsReportUtils(expenseReport.reportID, allTransactionViolations);
10132+ const isASAPSubmitBetaEnabled = Permissions.isBetaEnabled(CONST.BETAS.ASAP_SUBMIT, allBetas);
10133+ const optimisticNextStep = buildNextStepNew({
10134+ report: expenseReport,
10135+ policy,
10136+ currentUserAccountIDParam: userAccountID,
10137+ currentUserEmailParam: currentUserEmail,
10138+ hasViolations,
10139+ isASAPSubmitBetaEnabled,
10140+ predictedNextStatus,
10141+ });
1013810142 const chatReport = getReportOrDraftReport(expenseReport.chatReportID);
1013910143
1014010144 const optimisticReportActionsData: OnyxUpdate = {
0 commit comments