Skip to content
68 changes: 44 additions & 24 deletions src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

let currentUserAccountID = -1;
let currentUserEmail = '';
Onyx.connect({

Check warning on line 44 in src/libs/NextStepUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 44 in src/libs/NextStepUtils.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
if (!value) {
Expand All @@ -54,20 +54,20 @@
});

let allPolicies: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 57 in src/libs/NextStepUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 57 in src/libs/NextStepUtils.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
});

let allBetas: OnyxEntry<Beta[]>;
Onyx.connect({

Check warning on line 64 in src/libs/NextStepUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 64 in src/libs/NextStepUtils.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.BETAS,
callback: (value) => (allBetas = value),
});

let transactionViolations: OnyxCollection<TransactionViolations>;
Onyx.connect({

Check warning on line 70 in src/libs/NextStepUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -417,7 +417,6 @@
const approvers = getLoginsByAccountIDs([approverAccountID ?? CONST.DEFAULT_NUMBER_ID]);

const reimburserAccountID = getReimburserAccountID(policy);
const hasValidAccount = !!policy?.achAccount?.accountNumber || policy.reimbursementChoice !== CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES;
const type: ReportNextStepDeprecated['type'] = 'neutral';
let optimisticNextStep: ReportNextStepDeprecated | null;

Expand Down Expand Up @@ -690,7 +689,7 @@
break;

// Generates an optimistic nextStep once a report has been approved
case CONST.REPORT.STATUS_NUM.APPROVED:
case CONST.REPORT.STATUS_NUM.APPROVED: {
if (
isInvoiceReport(report) ||
!isPayer(
Expand All @@ -707,33 +706,44 @@
break;
}
// Self review
let payerMessage: Message;
if (
isPayer(
{
accountID: currentUserAccountID,
email: currentUserEmail,
},
report,
)
) {
payerMessage = {text: 'you', type: 'strong'};
} else if (reimburserAccountID === -1) {
payerMessage = {text: 'an admin'};
} else {
payerMessage = {text: getDisplayNameForParticipant({accountID: reimburserAccountID}), type: 'strong'};
}

optimisticNextStep = {
type,
icon: CONST.NEXT_STEP.ICONS.HOURGLASS,
message: [
{
text: 'Waiting for ',
},
reimburserAccountID === -1
? {
text: 'an admin',
}
: {
text: getDisplayNameForParticipant({accountID: reimburserAccountID}),
type: 'strong',
},
payerMessage,
{
text: ' to ',
},
{
text: hasValidAccount ? 'pay' : 'finish setting up',
text: 'pay',
},
{
text: hasValidAccount ? ' %expenses.' : ' a business bank account.',
text: ' %expenses.',
},
],
};
break;
}

// Resets a nextStep
default:
Expand Down Expand Up @@ -779,7 +789,6 @@
const approvers = getLoginsByAccountIDs([approverAccountID ?? CONST.DEFAULT_NUMBER_ID]);

const reimburserAccountID = getReimburserAccountID(policy);
const hasValidAccount = !!policy?.achAccount?.accountNumber || policy?.reimbursementChoice !== CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES;
const type: ReportNextStepDeprecated['type'] = 'neutral';
let optimisticNextStep: ReportNextStepDeprecated | null;

Expand Down Expand Up @@ -1052,7 +1061,7 @@
break;

// Generates an optimistic nextStep once a report has been approved
case CONST.REPORT.STATUS_NUM.APPROVED:
case CONST.REPORT.STATUS_NUM.APPROVED: {
if (
isInvoiceReport(report) ||
!isPayer(
Expand All @@ -1069,33 +1078,44 @@
break;
}
// Self review
let payerMessage: Message;
if (
isPayer(
{
accountID: currentUserAccountIDParam,
email: currentUserEmailParam,
},
report,
)
) {
payerMessage = {text: 'you', type: 'strong'};
} else if (reimburserAccountID === -1) {
payerMessage = {text: 'an admin'};
} else {
payerMessage = {text: getDisplayNameForParticipant({accountID: reimburserAccountID}), type: 'strong'};
}

optimisticNextStep = {
type,
icon: CONST.NEXT_STEP.ICONS.HOURGLASS,
message: [
{
text: 'Waiting for ',
},
reimburserAccountID === -1
? {
text: 'an admin',
}
: {
text: getDisplayNameForParticipant({accountID: reimburserAccountID}),
type: 'strong',
},
payerMessage,
{
text: ' to ',
},
{
text: hasValidAccount ? 'pay' : 'finish setting up',
text: 'pay',
},
{
text: hasValidAccount ? ' %expenses.' : ' a business bank account.',
text: ' %expenses.',
},
],
};
break;
}

// Resets a nextStep
default:
Expand Down
6 changes: 3 additions & 3 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9987,10 +9987,10 @@ describe('actions/IOU', () => {
expect(nextStep?.message).toBeDefined();

// Since the report is fully approved when admin takes control and approves,
// the next step should be about payment, which should mention the admin
// The message should equal "Waiting for Admin User to pay"
// the next step should be about payment, which should mention "you" since the admin is the payer
// The message should equal "Waiting for you to pay %expenses."
const fullMessage = nextStep?.message?.map((part) => part.text).join('');
expect(fullMessage).toBe('Waiting for an admin to pay %expenses.');
expect(fullMessage).toBe('Waiting for you to pay %expenses.');
});
});

Expand Down
27 changes: 15 additions & 12 deletions tests/unit/NextStepUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,22 +478,23 @@ describe('libs/NextStepUtils', () => {
test('self review', () => {
optimisticNextStep.icon = CONST.NEXT_STEP.ICONS.HOURGLASS;

// Waiting for an admin to set up a bank account
// Waiting for you to pay expense(s)
optimisticNextStep.message = [
{
text: 'Waiting for ',
},
{
text: `an admin`,
text: `you`,
type: 'strong',
},
{
text: ' to ',
},
{
text: 'finish setting up',
text: 'pay',
},
{
text: ' a business bank account.',
text: ' %expenses.',
},
];
// TODO: Replace onyx.connect with useOnyx hook (https://github.com/Expensify/App/issues/66365)
Expand All @@ -506,13 +507,14 @@ describe('libs/NextStepUtils', () => {
test('self review with bank account setup', () => {
optimisticNextStep.icon = CONST.NEXT_STEP.ICONS.HOURGLASS;

// Waiting for an admin to pay expense(s)
// Waiting for you to pay expense(s)
optimisticNextStep.message = [
{
text: 'Waiting for ',
},
{
text: `an admin`,
text: `you`,
type: 'strong',
},
{
text: ' to ',
Expand Down Expand Up @@ -732,22 +734,22 @@ describe('libs/NextStepUtils', () => {
test('payer', () => {
optimisticNextStep.icon = CONST.NEXT_STEP.ICONS.HOURGLASS;

// Waiting for an admin to set up a bank account
// Waiting for an admin (you) to pay expense(s)
optimisticNextStep.message = [
{
text: 'Waiting for ',
},
{
text: 'an admin',
text: 'you',
},
{
text: ' to ',
},
{
text: 'finish setting up',
text: 'pay',
},
{
text: ' a business bank account.',
text: ' %expenses.',
},
];
// mock the report as approved
Expand All @@ -768,13 +770,14 @@ describe('libs/NextStepUtils', () => {
test('payer with bank account setup', () => {
optimisticNextStep.icon = CONST.NEXT_STEP.ICONS.HOURGLASS;

// Waiting for an admin to pay expense(s)
// Waiting for you to pay expense(s)
optimisticNextStep.message = [
{
text: 'Waiting for ',
},
{
text: 'an admin',
text: 'you',
type: 'strong',
},
{
text: ' to ',
Expand Down
Loading