diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index d413491f1a21b..dc686eea6e137 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -417,7 +417,6 @@ function buildNextStep( 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; @@ -690,7 +689,7 @@ function buildNextStep( 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( @@ -707,6 +706,23 @@ function buildNextStep( 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, @@ -714,26 +730,20 @@ function buildNextStep( { 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: @@ -779,7 +789,6 @@ function buildNextStepNew(params: BuildNextStepNewParams): ReportNextStepDepreca 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; @@ -1052,7 +1061,7 @@ function buildNextStepNew(params: BuildNextStepNewParams): ReportNextStepDepreca 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( @@ -1069,6 +1078,23 @@ function buildNextStepNew(params: BuildNextStepNewParams): ReportNextStepDepreca 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, @@ -1076,26 +1102,20 @@ function buildNextStepNew(params: BuildNextStepNewParams): ReportNextStepDepreca { 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: diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 128520d2dc5f1..40e47c068f97a 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -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.'); }); }); diff --git a/tests/unit/NextStepUtilsTest.ts b/tests/unit/NextStepUtilsTest.ts index ede93245bddc0..49c61c48795d0 100644 --- a/tests/unit/NextStepUtilsTest.ts +++ b/tests/unit/NextStepUtilsTest.ts @@ -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) @@ -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 ', @@ -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 @@ -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 ',