Skip to content

Commit 8f1d240

Browse files
authored
Merge pull request #52297 from truph01/fix/50269
fix: Second approver unapproval shows 'Waiting for first approver' in next steps
2 parents ba9e3fc + 7100109 commit 8f1d240

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/libs/NextStepUtils.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type DeepValueOf from '@src/types/utils/DeepValueOf';
1111
import {getNextApproverAccountID} from './actions/IOU';
1212
import DateUtils from './DateUtils';
1313
import EmailUtils from './EmailUtils';
14+
import {getLoginsByAccountIDs} from './PersonalDetailsUtils';
1415
import {getCorrectedAutoReportingFrequency, getReimburserAccountID} from './PolicyUtils';
1516
import {getDisplayNameForParticipant, getPersonalDetailsForAccountID, isExpenseReport, isInvoiceReport, isPayer} from './ReportUtils';
1617

@@ -66,8 +67,8 @@ function parseMessage(messages: Message[] | undefined) {
6667
return `<next-step>${formattedHtml}</next-step>`;
6768
}
6869

69-
function getNextApproverDisplayName(report: OnyxEntry<Report>) {
70-
const approverAccountID = getNextApproverAccountID(report);
70+
function getNextApproverDisplayName(report: OnyxEntry<Report>, isUnapprove?: boolean) {
71+
const approverAccountID = getNextApproverAccountID(report, isUnapprove);
7172

7273
return getDisplayNameForParticipant({accountID: approverAccountID}) ?? getPersonalDetailsForAccountID(approverAccountID).login;
7374
}
@@ -80,7 +81,7 @@ function getNextApproverDisplayName(report: OnyxEntry<Report>) {
8081
* @param parameters.isPaidWithExpensify - Whether a report has been paid with Expensify or outside
8182
* @returns nextStep
8283
*/
83-
function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<typeof CONST.REPORT.STATUS_NUM>): ReportNextStep | null {
84+
function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<typeof CONST.REPORT.STATUS_NUM>, isUnapprove?: boolean): ReportNextStep | null {
8485
if (!isExpenseReport(report)) {
8586
return null;
8687
}
@@ -90,7 +91,9 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
9091
const {harvesting, autoReportingOffset} = policy;
9192
const autoReportingFrequency = getCorrectedAutoReportingFrequency(policy);
9293
const ownerDisplayName = getDisplayNameForParticipant({accountID: ownerAccountID});
93-
const nextApproverDisplayName = getNextApproverDisplayName(report);
94+
const nextApproverDisplayName = getNextApproverDisplayName(report, isUnapprove);
95+
const approverAccountID = getNextApproverAccountID(report, isUnapprove);
96+
const approvers = getLoginsByAccountIDs([approverAccountID ?? CONST.DEFAULT_NUMBER_ID]);
9497

9598
const reimburserAccountID = getReimburserAccountID(policy);
9699
const hasValidAccount = !!policy?.achAccount?.accountNumber;
@@ -232,6 +235,7 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
232235
{
233236
text: nextApproverDisplayName,
234237
type: 'strong',
238+
clickToCopyText: approvers.at(0),
235239
},
236240
{
237241
text: ' to ',

src/libs/actions/IOU.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8092,11 +8092,19 @@ function isLastApprover(approvalChain: string[]): boolean {
80928092
return approvalChain.at(-1) === currentUserEmail;
80938093
}
80948094

8095-
function getNextApproverAccountID(report: OnyxEntry<OnyxTypes.Report>) {
8095+
function getNextApproverAccountID(report: OnyxEntry<OnyxTypes.Report>, isUnapproved = false) {
80968096
const policy = getPolicy(report?.policyID);
80978097
const approvalChain = getApprovalChain(policy, report);
80988098
const submitToAccountID = getSubmitToAccountID(policy, report);
80998099

8100+
if (isUnapproved) {
8101+
if (approvalChain.includes(currentUserEmail)) {
8102+
return userAccountID;
8103+
}
8104+
8105+
return report?.managerID;
8106+
}
8107+
81008108
if (approvalChain.length === 0) {
81018109
return submitToAccountID;
81028110
}
@@ -8284,7 +8292,7 @@ function unapproveExpenseReport(expenseReport: OnyxEntry<OnyxTypes.Report>) {
82848292
const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`] ?? null;
82858293

82868294
const optimisticUnapprovedReportAction = buildOptimisticUnapprovedReportAction(expenseReport.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID);
8287-
const optimisticNextStep = buildNextStep(expenseReport, CONST.REPORT.STATUS_NUM.SUBMITTED);
8295+
const optimisticNextStep = buildNextStep(expenseReport, CONST.REPORT.STATUS_NUM.SUBMITTED, true);
82888296

82898297
const optimisticReportActionData: OnyxUpdate = {
82908298
onyxMethod: Onyx.METHOD.MERGE,

0 commit comments

Comments
 (0)