Skip to content

Commit c8b112e

Browse files
authored
Merge pull request #55635 from Expensify/dangrous-updatenextstepcopy
Update optimistic next steps for manual and empty reports
2 parents 76d187f + 56c5096 commit c8b112e

File tree

2 files changed

+57
-34
lines changed

2 files changed

+57
-34
lines changed

src/libs/NextStepUtils.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ 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 * as PolicyUtils from './PolicyUtils';
15-
import * as ReportUtils from './ReportUtils';
14+
import {getCorrectedAutoReportingFrequency, getReimburserAccountID} from './PolicyUtils';
15+
import {getDisplayNameForParticipant, getPersonalDetailsForAccountID, isExpenseReport, isInvoiceReport, isPayer} from './ReportUtils';
1616

1717
let currentUserAccountID = -1;
1818
let currentUserEmail = '';
@@ -23,7 +23,7 @@ Onyx.connect({
2323
return;
2424
}
2525

26-
currentUserAccountID = value?.accountID ?? -1;
26+
currentUserAccountID = value?.accountID ?? CONST.DEFAULT_NUMBER_ID;
2727
currentUserEmail = value?.email ?? '';
2828
},
2929
});
@@ -69,7 +69,7 @@ function parseMessage(messages: Message[] | undefined) {
6969
function getNextApproverDisplayName(report: OnyxEntry<Report>) {
7070
const approverAccountID = getNextApproverAccountID(report);
7171

72-
return ReportUtils.getDisplayNameForParticipant(approverAccountID) ?? ReportUtils.getPersonalDetailsForAccountID(approverAccountID).login;
72+
return getDisplayNameForParticipant(approverAccountID) ?? getPersonalDetailsForAccountID(approverAccountID).login;
7373
}
7474

7575
/**
@@ -81,18 +81,18 @@ function getNextApproverDisplayName(report: OnyxEntry<Report>) {
8181
* @returns nextStep
8282
*/
8383
function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<typeof CONST.REPORT.STATUS_NUM>): ReportNextStep | null {
84-
if (!ReportUtils.isExpenseReport(report)) {
84+
if (!isExpenseReport(report)) {
8585
return null;
8686
}
8787

8888
const {policyID = '', ownerAccountID = -1} = report ?? {};
8989
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`] ?? ({} as Policy);
9090
const {harvesting, autoReportingOffset} = policy;
91-
const autoReportingFrequency = PolicyUtils.getCorrectedAutoReportingFrequency(policy);
92-
const ownerDisplayName = ReportUtils.getDisplayNameForParticipant(ownerAccountID);
91+
const autoReportingFrequency = getCorrectedAutoReportingFrequency(policy);
92+
const ownerDisplayName = getDisplayNameForParticipant(ownerAccountID);
9393
const nextApproverDisplayName = getNextApproverDisplayName(report);
9494

95-
const reimburserAccountID = PolicyUtils.getReimburserAccountID(policy);
95+
const reimburserAccountID = getReimburserAccountID(policy);
9696
const hasValidAccount = !!policy?.achAccount?.accountNumber;
9797
const type: ReportNextStep['type'] = 'neutral';
9898
let optimisticNextStep: ReportNextStep | null;
@@ -194,6 +194,29 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
194194
});
195195
}
196196

197+
// Manual submission
198+
if (report?.total !== 0 && !harvesting?.enabled && autoReportingFrequency === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MANUAL) {
199+
optimisticNextStep.message = [
200+
{
201+
text: 'Waiting for ',
202+
},
203+
{
204+
text: `${ownerDisplayName}`,
205+
type: 'strong',
206+
clickToCopyText: ownerAccountID === currentUserAccountID ? currentUserEmail : '',
207+
},
208+
{
209+
text: ' to ',
210+
},
211+
{
212+
text: 'submit',
213+
},
214+
{
215+
text: ' %expenses.',
216+
},
217+
];
218+
}
219+
197220
break;
198221

199222
// Generates an optimistic nextStep once a report has been submitted
@@ -240,8 +263,8 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
240263
// Generates an optimistic nextStep once a report has been approved
241264
case CONST.REPORT.STATUS_NUM.APPROVED:
242265
if (
243-
ReportUtils.isInvoiceReport(report) ||
244-
!ReportUtils.isPayer(
266+
isInvoiceReport(report) ||
267+
!isPayer(
245268
{
246269
accountID: currentUserAccountID,
247270
email: currentUserEmail,
@@ -266,7 +289,7 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
266289
text: 'an admin',
267290
}
268291
: {
269-
text: ReportUtils.getDisplayNameForParticipant(reimburserAccountID),
292+
text: getDisplayNameForParticipant(reimburserAccountID),
270293
type: 'strong',
271294
},
272295
{

tests/unit/NextStepUtilsTest.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {format, lastDayOfMonth, setDate} from 'date-fns';
22
import Onyx from 'react-native-onyx';
33
import DateUtils from '@libs/DateUtils';
4-
import * as NextStepUtils from '@libs/NextStepUtils';
5-
import * as ReportUtils from '@libs/ReportUtils';
4+
import {buildNextStep} from '@libs/NextStepUtils';
5+
import {buildOptimisticExpenseReport} from '@libs/ReportUtils';
66
import CONST from '@src/CONST';
77
import ONYXKEYS from '@src/ONYXKEYS';
88
import type {Policy, Report, ReportNextStep} from '@src/types/onyx';
@@ -40,7 +40,7 @@ describe('libs/NextStepUtils', () => {
4040
icon: CONST.NEXT_STEP.ICONS.HOURGLASS,
4141
message: [],
4242
};
43-
const report = ReportUtils.buildOptimisticExpenseReport('fake-chat-report-id-1', policyID, 1, -500, CONST.CURRENCY.USD) as Report;
43+
const report = buildOptimisticExpenseReport('fake-chat-report-id-1', policyID, 1, -500, CONST.CURRENCY.USD) as Report;
4444

4545
beforeAll(() => {
4646
const policyCollectionDataSet = toCollectionDataSet(ONYXKEYS.COLLECTION.POLICY, [policy], (item) => item.id);
@@ -101,7 +101,7 @@ describe('libs/NextStepUtils', () => {
101101
},
102102
];
103103

104-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
104+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
105105

106106
expect(result).toMatchObject(optimisticNextStep);
107107
});
@@ -142,7 +142,7 @@ describe('libs/NextStepUtils', () => {
142142
enabled: true,
143143
},
144144
}).then(() => {
145-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
145+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
146146

147147
expect(result).toMatchObject(optimisticNextStep);
148148
});
@@ -177,7 +177,7 @@ describe('libs/NextStepUtils', () => {
177177
enabled: true,
178178
},
179179
}).then(() => {
180-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
180+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
181181

182182
expect(result).toMatchObject(optimisticNextStep);
183183
});
@@ -212,7 +212,7 @@ describe('libs/NextStepUtils', () => {
212212
enabled: true,
213213
},
214214
}).then(() => {
215-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
215+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
216216

217217
expect(result).toMatchObject(optimisticNextStep);
218218
});
@@ -248,7 +248,7 @@ describe('libs/NextStepUtils', () => {
248248
enabled: true,
249249
},
250250
}).then(() => {
251-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
251+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
252252

253253
expect(result).toMatchObject(optimisticNextStep);
254254
});
@@ -284,7 +284,7 @@ describe('libs/NextStepUtils', () => {
284284
enabled: true,
285285
},
286286
}).then(() => {
287-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
287+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
288288

289289
expect(result).toMatchObject(optimisticNextStep);
290290
});
@@ -322,7 +322,7 @@ describe('libs/NextStepUtils', () => {
322322
enabled: true,
323323
},
324324
}).then(() => {
325-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
325+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
326326

327327
expect(result).toMatchObject(optimisticNextStep);
328328
});
@@ -357,14 +357,14 @@ describe('libs/NextStepUtils', () => {
357357
enabled: true,
358358
},
359359
}).then(() => {
360-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
360+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
361361

362362
expect(result).toMatchObject(optimisticNextStep);
363363
});
364364
});
365365

366366
test('manual', () => {
367-
// Waiting for userSubmitter to add expense(s).
367+
// Waiting for userSubmitter to submit expense(s).
368368
optimisticNextStep.message = [
369369
{
370370
text: 'Waiting for ',
@@ -377,7 +377,7 @@ describe('libs/NextStepUtils', () => {
377377
text: ' to ',
378378
},
379379
{
380-
text: 'add',
380+
text: 'submit',
381381
},
382382
{
383383
text: ' %expenses.',
@@ -390,7 +390,7 @@ describe('libs/NextStepUtils', () => {
390390
enabled: false,
391391
},
392392
}).then(() => {
393-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
393+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN);
394394

395395
expect(result).toMatchObject(optimisticNextStep);
396396
});
@@ -421,7 +421,7 @@ describe('libs/NextStepUtils', () => {
421421
},
422422
];
423423

424-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED);
424+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED);
425425

426426
expect(result).toMatchObject(optimisticNextStep);
427427
});
@@ -453,7 +453,7 @@ describe('libs/NextStepUtils', () => {
453453
accountNumber: '123456789',
454454
},
455455
}).then(() => {
456-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED);
456+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED);
457457

458458
expect(result).toMatchObject(optimisticNextStep);
459459

@@ -495,7 +495,7 @@ describe('libs/NextStepUtils', () => {
495495
},
496496
},
497497
}).then(() => {
498-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.SUBMITTED);
498+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.SUBMITTED);
499499

500500
expect(result).toMatchObject(optimisticNextStep);
501501
});
@@ -532,7 +532,7 @@ describe('libs/NextStepUtils', () => {
532532
},
533533
},
534534
}).then(() => {
535-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.SUBMITTED);
535+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.SUBMITTED);
536536

537537
expect(result).toMatchObject(optimisticNextStep);
538538
});
@@ -549,7 +549,7 @@ describe('libs/NextStepUtils', () => {
549549
return Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {
550550
approvalMode: CONST.POLICY.APPROVAL_MODE.OPTIONAL,
551551
}).then(() => {
552-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.CLOSED);
552+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.CLOSED);
553553

554554
expect(result).toMatchObject(optimisticNextStep);
555555
});
@@ -566,7 +566,7 @@ describe('libs/NextStepUtils', () => {
566566
},
567567
];
568568

569-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED);
569+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED);
570570

571571
expect(result).toMatchObject(optimisticNextStep);
572572
});
@@ -597,7 +597,7 @@ describe('libs/NextStepUtils', () => {
597597
report.stateNum = CONST.REPORT.STATE_NUM.APPROVED;
598598
report.statusNum = CONST.REPORT.STATUS_NUM.APPROVED;
599599

600-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED);
600+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED);
601601

602602
expect(result).toMatchObject(optimisticNextStep);
603603

@@ -633,7 +633,7 @@ describe('libs/NextStepUtils', () => {
633633
accountNumber: '123456789',
634634
},
635635
}).then(() => {
636-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED);
636+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED);
637637

638638
expect(result).toMatchObject(optimisticNextStep);
639639
});
@@ -648,7 +648,7 @@ describe('libs/NextStepUtils', () => {
648648
},
649649
];
650650

651-
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.REIMBURSED);
651+
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.REIMBURSED);
652652

653653
expect(result).toMatchObject(optimisticNextStep);
654654
});

0 commit comments

Comments
 (0)