Skip to content

Commit

Permalink
Merge pull request #36798 from Expensify/alberto-cancelNext
Browse files Browse the repository at this point in the history
Update nextStep on payment cancellation

(cherry picked from commit 29b8b95)
  • Loading branch information
Beamanator authored and OSBotify committed Feb 19, 2024
1 parent d674d48 commit 760edc5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
21 changes: 17 additions & 4 deletions src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ function buildNextStep(report: Report | EmptyObject, predictedNextStatus: ValueO
text: 'Waiting for ',
},
{
text: 'you',
text: managerDisplayName,
type: 'strong',
},
{
text: ' to ',
},
{
text: 'review',
text: 'pay',
type: 'strong',
},
{
Expand All @@ -272,10 +272,23 @@ function buildNextStep(report: Report | EmptyObject, predictedNextStatus: ValueO

// Another owner
if (!isOwner) {
optimisticNextStep.title = 'Finished!';
optimisticNextStep.message = [
{
text: 'No further action required!',
text: 'Waiting for ',
},
{
text: 'you',
type: 'strong',
},
{
text: ' to ',
},
{
text: 'pay',
type: 'strong',
},
{
text: ' %expenses.',
},
];
}
Expand Down
16 changes: 16 additions & 0 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3631,6 +3631,7 @@ function cancelPayment(expenseReport: OnyxTypes.Report, chatReport: OnyxTypes.Re
stateNum = approvalMode === CONST.POLICY.APPROVAL_MODE.OPTIONAL ? CONST.REPORT.STATE_NUM.SUBMITTED : CONST.REPORT.STATE_NUM.APPROVED;
statusNum = approvalMode === CONST.POLICY.APPROVAL_MODE.OPTIONAL ? CONST.REPORT.STATUS_NUM.CLOSED : CONST.REPORT.STATUS_NUM.APPROVED;
}
const optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, statusNum);
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -3655,6 +3656,14 @@ function cancelPayment(expenseReport: OnyxTypes.Report, chatReport: OnyxTypes.Re
},
];

if (!isFree) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`,
value: optimisticNextStep,
});
}

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -3696,6 +3705,13 @@ function cancelPayment(expenseReport: OnyxTypes.Report, chatReport: OnyxTypes.Re
},
});
}
if (!isFree) {
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`,
value: NextStepUtils.buildNextStep(expenseReport, CONST.REPORT.STATUS_NUM.REIMBURSED),
});
}

API.write(
WRITE_COMMANDS.CANCEL_PAYMENT,
Expand Down
22 changes: 18 additions & 4 deletions tests/unit/NextStepUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ describe('libs/NextStepUtils', () => {
text: ' to ',
},
{
text: 'review',
text: 'pay',
type: 'strong',
},
{
Expand Down Expand Up @@ -457,7 +457,7 @@ describe('libs/NextStepUtils', () => {
text: ' to ',
},
{
text: 'review',
text: 'pay',
type: 'strong',
},
{
Expand All @@ -472,10 +472,24 @@ describe('libs/NextStepUtils', () => {

test('another owner', () => {
report.ownerAccountID = strangeAccountID;
optimisticNextStep.title = 'Finished!';
optimisticNextStep.title = 'Next Steps:';
optimisticNextStep.message = [
{
text: 'No further action required!',
text: 'Waiting for ',
},
{
text: 'you',
type: 'strong',
},
{
text: ' to ',
},
{
text: 'pay',
type: 'strong',
},
{
text: ' %expenses.',
},
];

Expand Down

0 comments on commit 760edc5

Please sign in to comment.