Skip to content

Commit 19638ba

Browse files
authored
Merge pull request Expensify#76609 from parasharrajat/approver/next-status
Fix Next step when approver is changed via Add Approver
2 parents af4f7e2 + 2d857a1 commit 19638ba

3 files changed

Lines changed: 44 additions & 7 deletions

File tree

src/libs/NextStepUtils.ts

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ type BuildNextStepNewParams = {
3434
shouldFixViolations?: boolean;
3535
isUnapprove?: boolean;
3636
isReopen?: boolean;
37+
/**
38+
* Bypass Next Approver ID is used when an approver is bypassed so that we can show the next approver in the chain.
39+
* This is necessary in the case where report actions are not yet updated to determine the bypass action.
40+
*/
41+
bypassNextApproverID?: number;
3742
};
3843

3944
function buildNextStepMessage(nextStep: ReportNextStep, translate: LocaleContextProps['translate'], currentUserAccountID: number): string {
@@ -61,8 +66,19 @@ function buildNextStepMessage(nextStep: ReportNextStep, translate: LocaleContext
6166
}
6267

6368
function buildOptimisticNextStep(params: BuildNextStepNewParams): ReportNextStep | null {
64-
const {report, policy, currentUserAccountIDParam, currentUserEmailParam, hasViolations, isASAPSubmitBetaEnabled, predictedNextStatus, shouldFixViolations, isUnapprove, isReopen} =
65-
params;
69+
const {
70+
report,
71+
policy,
72+
currentUserAccountIDParam,
73+
currentUserEmailParam,
74+
hasViolations,
75+
isASAPSubmitBetaEnabled,
76+
predictedNextStatus,
77+
shouldFixViolations,
78+
isUnapprove,
79+
isReopen,
80+
bypassNextApproverID,
81+
} = params;
6682

6783
if (!isExpenseReport(report)) {
6884
return null;
@@ -77,7 +93,7 @@ function buildOptimisticNextStep(params: BuildNextStepNewParams): ReportNextStep
7793
((report.total !== 0 && report.total !== undefined) ||
7894
(report.unheldTotal !== 0 && report.unheldTotal !== undefined) ||
7995
(report.unheldNonReimbursableTotal !== 0 && report.unheldNonReimbursableTotal !== undefined));
80-
const approverAccountID = getNextApproverAccountID(report, isUnapprove);
96+
const approverAccountID = bypassNextApproverID ?? getNextApproverAccountID(report, isUnapprove);
8197
const reimburserAccountID = getReimburserAccountID(policy);
8298
const hasValidAccount = !!policy?.achAccount?.accountNumber || policy?.reimbursementChoice !== CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES;
8399

@@ -331,8 +347,19 @@ function buildOptimisticNextStepForStrictPolicyRuleViolations() {
331347
* @deprecated This function will be removed soon. You should still use it though but also use buildOptimisticNextStep in parallel.
332348
*/
333349
function buildNextStepNew(params: BuildNextStepNewParams): ReportNextStepDeprecated | null {
334-
const {report, policy, currentUserAccountIDParam, currentUserEmailParam, hasViolations, isASAPSubmitBetaEnabled, predictedNextStatus, shouldFixViolations, isUnapprove, isReopen} =
335-
params;
350+
const {
351+
report,
352+
policy,
353+
currentUserAccountIDParam,
354+
currentUserEmailParam,
355+
hasViolations,
356+
isASAPSubmitBetaEnabled,
357+
predictedNextStatus,
358+
shouldFixViolations,
359+
isUnapprove,
360+
isReopen,
361+
bypassNextApproverID,
362+
} = params;
336363

337364
if (!isExpenseReport(report)) {
338365
return null;
@@ -360,8 +387,10 @@ function buildNextStepNew(params: BuildNextStepNewParams): ReportNextStepDepreca
360387
policyOwnerPersonalDetails?.displayName ??
361388
policyOwnerPersonalDetails?.login ??
362389
getDisplayNameForParticipant({accountID: policy?.ownerAccountID, formatPhoneNumber: formatPhoneNumberPhoneUtils});
363-
const nextApproverDisplayName = getNextApproverDisplayName(report, isUnapprove);
364-
const approverAccountID = getNextApproverAccountID(report, isUnapprove);
390+
const nextApproverDisplayName = bypassNextApproverID
391+
? (getDisplayNameForParticipant({accountID: bypassNextApproverID, formatPhoneNumber: formatPhoneNumberPhoneUtils}) ?? getPersonalDetailsForAccountID(bypassNextApproverID).login)
392+
: getNextApproverDisplayName(report, isUnapprove);
393+
const approverAccountID = bypassNextApproverID ?? getNextApproverAccountID(report, isUnapprove);
365394
const approvers = getLoginsByAccountIDs([approverAccountID ?? CONST.DEFAULT_NUMBER_ID]);
366395

367396
const reimburserAccountID = getReimburserAccountID(policy);

src/libs/ReportUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12381,6 +12381,10 @@ function getBypassApproverAccountIDIfTakenControl(expenseReport: OnyxEntry<Repor
1238112381
return null;
1238212382
}
1238312383

12384+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.REROUTE)) {
12385+
return expenseReport.managerID ?? null;
12386+
}
12387+
1238412388
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL)) {
1238512389
return action.actorAccountID ?? null;
1238612390
}

src/libs/actions/IOU.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14866,6 +14866,7 @@ function assignReportToMe(
1486614866
currentUserEmailParam: email,
1486714867
hasViolations,
1486814868
isASAPSubmitBetaEnabled,
14869+
bypassNextApproverID: accountID,
1486914870
});
1487014871
const optimisticNextStep = buildOptimisticNextStep({
1487114872
report: {...report, managerID: accountID},
@@ -14877,6 +14878,7 @@ function assignReportToMe(
1487714878
currentUserEmailParam: email,
1487814879
hasViolations,
1487914880
isASAPSubmitBetaEnabled,
14881+
bypassNextApproverID: accountID,
1488014882
});
1488114883

1488214884
const onyxData: OnyxData = {
@@ -14980,6 +14982,7 @@ function addReportApprover(
1498014982
currentUserEmailParam: email,
1498114983
hasViolations,
1498214984
isASAPSubmitBetaEnabled,
14985+
bypassNextApproverID: newApproverAccountID,
1498314986
});
1498414987
const optimisticNextStep = buildOptimisticNextStep({
1498514988
report: {...report, managerID: newApproverAccountID},
@@ -14991,6 +14994,7 @@ function addReportApprover(
1499114994
currentUserEmailParam: email,
1499214995
hasViolations,
1499314996
isASAPSubmitBetaEnabled,
14997+
bypassNextApproverID: newApproverAccountID,
1499414998
});
1499514999
const onyxData: OnyxData = {
1499615000
optimisticData: [

0 commit comments

Comments
 (0)