From 6fbec597e9072b361a9d425275555e016c734400 Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 19 Feb 2024 11:41:23 +0100 Subject: [PATCH 1/6] Update nextStep on payment cancellation --- src/libs/actions/IOU.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 3482dd0e30ad..b4a876634a72 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -3661,6 +3661,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, @@ -3685,6 +3686,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, From b20bfc39df3c683db28f992583fcb5062772f400 Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 19 Feb 2024 12:07:40 +0100 Subject: [PATCH 2/6] revert message on error --- src/libs/actions/IOU.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index b4a876634a72..d35e6271700d 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -3735,6 +3735,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, From 78f3cac68b217c7883e0c84a42ebbe10f75fe8a2 Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 19 Feb 2024 12:20:26 +0100 Subject: [PATCH 3/6] Display correct message --- src/libs/NextStepUtils.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index 3b42382b10f9..db31ab02a3e5 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -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', }, { @@ -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.', }, ]; } From 870dbfded7446a48c060edd990546a08befe20b8 Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 19 Feb 2024 12:24:49 +0100 Subject: [PATCH 4/6] updte tests --- tests/unit/NextStepUtilsTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/NextStepUtilsTest.ts b/tests/unit/NextStepUtilsTest.ts index 568c641d2ac5..2a13a9d35765 100644 --- a/tests/unit/NextStepUtilsTest.ts +++ b/tests/unit/NextStepUtilsTest.ts @@ -457,7 +457,7 @@ describe('libs/NextStepUtils', () => { text: ' to ', }, { - text: 'review', + text: 'pay', type: 'strong', }, { From 056f940a32f61caf99f81cbdc91ac01322b61c54 Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 19 Feb 2024 12:31:22 +0100 Subject: [PATCH 5/6] more test updates --- tests/unit/NextStepUtilsTest.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/unit/NextStepUtilsTest.ts b/tests/unit/NextStepUtilsTest.ts index 2a13a9d35765..129c9740c8c3 100644 --- a/tests/unit/NextStepUtilsTest.ts +++ b/tests/unit/NextStepUtilsTest.ts @@ -472,10 +472,23 @@ describe('libs/NextStepUtils', () => { test('another owner', () => { report.ownerAccountID = strangeAccountID; - optimisticNextStep.title = 'Finished!'; optimisticNextStep.message = [ { - text: 'No further action required!', + text: 'Waiting for ', + }, + { + text: strangeEmail, + type: 'strong', + }, + { + text: ' to ', + }, + { + text: 'pay', + type: 'strong', + }, + { + text: ' %expenses.', }, ]; From 6b7bf2bbb5ce41abc83de4657366c51ff4f67a27 Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 19 Feb 2024 12:37:48 +0100 Subject: [PATCH 6/6] one more try with tests --- tests/unit/NextStepUtilsTest.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/unit/NextStepUtilsTest.ts b/tests/unit/NextStepUtilsTest.ts index 129c9740c8c3..5f4b1a6ed96b 100644 --- a/tests/unit/NextStepUtilsTest.ts +++ b/tests/unit/NextStepUtilsTest.ts @@ -364,7 +364,7 @@ describe('libs/NextStepUtils', () => { text: ' to ', }, { - text: 'review', + text: 'pay', type: 'strong', }, { @@ -472,12 +472,13 @@ describe('libs/NextStepUtils', () => { test('another owner', () => { report.ownerAccountID = strangeAccountID; + optimisticNextStep.title = 'Next Steps:'; optimisticNextStep.message = [ { text: 'Waiting for ', }, { - text: strangeEmail, + text: 'you', type: 'strong', }, {