Skip to content

Commit 745e1e7

Browse files
authored
Merge pull request Expensify#72772 from parasharrajat/revert/70283
[CP Staging] Revert Expensify#70283
2 parents 13f6b4b + 93fab11 commit 745e1e7

3 files changed

Lines changed: 15 additions & 352 deletions

File tree

src/libs/ReportUtils.ts

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ import {
186186
getReportActionMessageText,
187187
getReportActionText,
188188
getRetractedMessage,
189-
getSortedReportActions,
190189
getTravelUpdateMessage,
191190
getWorkspaceCurrencyUpdateMessage,
192191
getWorkspaceFrequencyUpdateMessage,
@@ -4328,12 +4327,6 @@ function getNextApproverAccountID(report: OnyxEntry<Report>, isUnapproved = fals
43284327
// eslint-disable-next-line @typescript-eslint/no-deprecated
43294328
const policy = getPolicy(report?.policyID);
43304329

4331-
// If the current user took control, then they are the final approver and we don't have a next approver
4332-
const bypassApprover = getBypassApproverIfTakenControl(report);
4333-
if (bypassApprover === currentUserAccountID) {
4334-
return undefined;
4335-
}
4336-
43374330
const approvalChain = getApprovalChain(policy, report);
43384331
const submitToAccountID = getSubmitToAccountID(policy, report);
43394332

@@ -4351,8 +4344,7 @@ function getNextApproverAccountID(report: OnyxEntry<Report>, isUnapproved = fals
43514344

43524345
const nextApproverEmail = approvalChain.length === 1 ? approvalChain.at(0) : approvalChain.at(approvalChain.indexOf(currentUserEmail ?? '') + 1);
43534346
if (!nextApproverEmail) {
4354-
// If there's no next approver in the chain, return undefined to indicate the current user is the final approver
4355-
return undefined;
4347+
return submitToAccountID;
43564348
}
43574349

43584350
return getAccountIDsByLogins([nextApproverEmail]).at(0);
@@ -11592,42 +11584,6 @@ function isWorkspaceEligibleForReportChange(submitterEmail: string | undefined,
1159211584
return isPaidGroupPolicyPolicyUtils(newPolicy) && !!newPolicy.role;
1159311585
}
1159411586

11595-
/**
11596-
* Checks if someone took control of the report and if that take control is still valid
11597-
* A take control is invalidated if there's a SUBMITTED action after it
11598-
*/
11599-
function getBypassApproverIfTakenControl(expenseReport: OnyxEntry<Report>): number | null {
11600-
if (!expenseReport?.reportID) {
11601-
return null;
11602-
}
11603-
11604-
if (!isProcessingReport(expenseReport)) {
11605-
return null;
11606-
}
11607-
11608-
const reportActions = getAllReportActions(expenseReport.reportID);
11609-
if (!reportActions) {
11610-
return null;
11611-
}
11612-
11613-
// Sort actions by created timestamp to get chronological order
11614-
const sortedActions = getSortedReportActions(Object.values(reportActions ?? {}), true);
11615-
11616-
// Look through actions in reverse chronological order (newest first)
11617-
// If we find a SUBMITTED action, there's no valid take control since any take control would be older
11618-
for (const action of sortedActions) {
11619-
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.SUBMITTED)) {
11620-
return null;
11621-
}
11622-
11623-
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL)) {
11624-
return action.actorAccountID ?? null;
11625-
}
11626-
}
11627-
11628-
return null;
11629-
}
11630-
1163111587
function getApprovalChain(policy: OnyxEntry<Policy>, expenseReport: OnyxEntry<Report>): string[] {
1163211588
const approvalChain: string[] = [];
1163311589
const fullApprovalChain: string[] = [];

src/libs/actions/IOU.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import Log from '@libs/Log';
6868
import isReportOpenInRHP from '@libs/Navigation/helpers/isReportOpenInRHP';
6969
import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute';
7070
import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
71-
import {buildNextStep, buildNextStepNew} from '@libs/NextStepUtils';
71+
import {buildNextStep} from '@libs/NextStepUtils';
7272
import * as NumberUtils from '@libs/NumberUtils';
7373
import {getManagerMcTestParticipant, getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils';
7474
import 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+
1011310119
function 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

Comments
 (0)