Skip to content

Commit 63a20f4

Browse files
authored
Merge pull request #42018 from dominictb/fix/41614
fix: update next step for approver
2 parents b720ae6 + 9bbed8f commit 63a20f4

File tree

2 files changed

+37
-43
lines changed

2 files changed

+37
-43
lines changed

src/libs/NextStepUtils.ts

+23-24
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import * as PolicyUtils from './PolicyUtils';
1616
import * as ReportUtils from './ReportUtils';
1717

1818
let currentUserAccountID = -1;
19+
let currentUserEmail = '';
1920
Onyx.connect({
2021
key: ONYXKEYS.SESSION,
2122
callback: (value) => {
@@ -24,6 +25,7 @@ Onyx.connect({
2425
}
2526

2627
currentUserAccountID = value?.accountID ?? -1;
28+
currentUserEmail = value?.email ?? '';
2729
},
2830
});
2931

@@ -273,6 +275,27 @@ function buildNextStep(
273275

274276
// Generates an optimistic nextStep once a report has been approved
275277
case CONST.REPORT.STATUS_NUM.APPROVED:
278+
if (
279+
ReportUtils.isInvoiceReport(report) ||
280+
!ReportUtils.isPayer(
281+
{
282+
accountID: currentUserAccountID,
283+
email: currentUserEmail,
284+
},
285+
report as Report,
286+
)
287+
) {
288+
optimisticNextStep = {
289+
type,
290+
title: 'Finished!',
291+
message: [
292+
{
293+
text: 'No further action required!',
294+
},
295+
],
296+
};
297+
break;
298+
}
276299
// Self review
277300
optimisticNextStep = {
278301
type,
@@ -297,30 +320,6 @@ function buildNextStep(
297320
},
298321
],
299322
};
300-
301-
// Another owner
302-
if (!isOwner) {
303-
optimisticNextStep.message = [
304-
{
305-
text: 'Waiting for ',
306-
},
307-
{
308-
text: managerDisplayName,
309-
type: 'strong',
310-
},
311-
{
312-
text: ' to ',
313-
},
314-
{
315-
text: 'pay',
316-
type: 'strong',
317-
},
318-
{
319-
text: ' %expenses.',
320-
},
321-
];
322-
}
323-
324323
break;
325324

326325
// Generates an optimistic nextStep once a report has been paid

tests/unit/NextStepUtilsTest.ts

+14-19
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe('libs/NextStepUtils', () => {
3131
type: 'team',
3232
outputCurrency: CONST.CURRENCY.USD,
3333
isPolicyExpenseChatEnabled: true,
34+
reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL,
3435
};
3536
const optimisticNextStep: ReportNextStep = {
3637
type: 'neutral',
@@ -483,25 +484,12 @@ describe('libs/NextStepUtils', () => {
483484
});
484485

485486
describe('it generates an optimistic nextStep once a report has been approved', () => {
486-
test('self review', () => {
487-
optimisticNextStep.title = 'Next Steps:';
487+
test('non-payer', () => {
488+
report.managerID = strangeAccountID;
489+
optimisticNextStep.title = 'Finished!';
488490
optimisticNextStep.message = [
489491
{
490-
text: 'Waiting for ',
491-
},
492-
{
493-
text: 'you',
494-
type: 'strong',
495-
},
496-
{
497-
text: ' to ',
498-
},
499-
{
500-
text: 'pay',
501-
type: 'strong',
502-
},
503-
{
504-
text: ' %expenses.',
492+
text: 'No further action required!',
505493
},
506494
];
507495

@@ -510,8 +498,7 @@ describe('libs/NextStepUtils', () => {
510498
expect(result).toMatchObject(optimisticNextStep);
511499
});
512500

513-
test('another owner', () => {
514-
report.ownerAccountID = strangeAccountID;
501+
test('payer', () => {
515502
optimisticNextStep.title = 'Next Steps:';
516503
optimisticNextStep.message = [
517504
{
@@ -532,10 +519,18 @@ describe('libs/NextStepUtils', () => {
532519
text: ' %expenses.',
533520
},
534521
];
522+
// mock the report as approved
523+
const originalState = {stateNum: report.stateNum, statusNum: report.statusNum};
524+
report.stateNum = CONST.REPORT.STATE_NUM.APPROVED;
525+
report.statusNum = CONST.REPORT.STATUS_NUM.APPROVED;
535526

536527
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED);
537528

538529
expect(result).toMatchObject(optimisticNextStep);
530+
531+
// restore
532+
report.stateNum = originalState.stateNum;
533+
report.statusNum = originalState.statusNum;
539534
});
540535
});
541536

0 commit comments

Comments
 (0)