Skip to content

Commit

Permalink
Merge pull request #36880 from rezkiy37/fix/36878-next-step-when-reim…
Browse files Browse the repository at this point in the history
…bursing

Fix a next step when reimbursing
  • Loading branch information
mountiny authored Feb 20, 2024
2 parents 03c81a6 + 0c84753 commit cb031ac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,22 @@ function parseMessage(messages: Message[] | undefined) {
}

type BuildNextStepParameters = {
isPaidWithWallet?: boolean;
isPaidWithExpensify?: boolean;
};

/**
* Generates an optimistic nextStep based on a current report status and other properties.
*
* @param report
* @param predictedNextStatus - a next expected status of the report
* @param parameters.isPaidWithWallet - Whether a report has been paid with the wallet or outside of Expensify
* @param parameters.isPaidWithExpensify - Whether a report has been paid with Expensify or outside
* @returns nextStep
*/
function buildNextStep(report: Report | EmptyObject, predictedNextStatus: ValueOf<typeof CONST.REPORT.STATUS_NUM>, {isPaidWithWallet}: BuildNextStepParameters = {}): ReportNextStep | null {
function buildNextStep(
report: Report | EmptyObject,
predictedNextStatus: ValueOf<typeof CONST.REPORT.STATUS_NUM>,
{isPaidWithExpensify}: BuildNextStepParameters = {},
): ReportNextStep | null {
if (!ReportUtils.isExpenseReport(report)) {
return null;
}
Expand Down Expand Up @@ -317,7 +321,7 @@ function buildNextStep(report: Report | EmptyObject, predictedNextStatus: ValueO
};

// Paid outside of Expensify
if (isPaidWithWallet === false) {
if (isPaidWithExpensify === false) {
optimisticNextStep.message?.push({text: ' outside of Expensify'});
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3314,7 +3314,7 @@ function getPayMoneyRequestParams(chatReport: OnyxTypes.Report, iouReport: OnyxT
}

const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport.reportID}`] ?? null;
const optimisticNextStep = NextStepUtils.buildNextStep(iouReport, CONST.REPORT.STATUS_NUM.REIMBURSED, {isPaidWithWallet: paymentMethodType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY});
const optimisticNextStep = NextStepUtils.buildNextStep(iouReport, CONST.REPORT.STATUS_NUM.REIMBURSED, {isPaidWithExpensify: paymentMethodType === CONST.IOU.PAYMENT_TYPE.VBBA});

const optimisticData: OnyxUpdate[] = [
{
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/NextStepUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ describe('libs/NextStepUtils', () => {
},
];

const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.REIMBURSED, {isPaidWithWallet: true});
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.REIMBURSED, {isPaidWithExpensify: true});

expect(result).toMatchObject(optimisticNextStep);
});
Expand All @@ -546,7 +546,7 @@ describe('libs/NextStepUtils', () => {
},
];

const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.REIMBURSED, {isPaidWithWallet: false});
const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.REIMBURSED, {isPaidWithExpensify: false});

expect(result).toMatchObject(optimisticNextStep);
});
Expand Down

0 comments on commit cb031ac

Please sign in to comment.