From ea890a89cd32dee78ed182349f9bda7b9eb71dab Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Fri, 17 Nov 2023 20:49:25 +0530 Subject: [PATCH 1/2] fix: Distance - The title 'Distance' changing to 'Merchant' when toggling on Billable. Signed-off-by: Krishna Gupta --- .../ReportActionItem/MoneyRequestView.js | 3 +-- src/libs/actions/IOU.js | 16 ++++++++++++++-- src/pages/EditRequestDistancePage.js | 2 +- src/pages/EditRequestPage.js | 6 +----- tests/actions/IOUTest.js | 4 ++-- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js index 1da061fc741e..f7a6f10be88e 100644 --- a/src/components/ReportActionItem/MoneyRequestView.js +++ b/src/components/ReportActionItem/MoneyRequestView.js @@ -281,14 +281,13 @@ function MoneyRequestView({report, parentReport, policyCategories, shouldShowHor /> )} - {shouldShowBillable && ( {translate('common.billable')} IOU.editMoneyRequest(transaction.transactionID, report.reportID, {billable: value})} + onToggle={(value) => IOU.editMoneyOrDistanceRequest(transaction, report.reportID, {billable: value})} /> )} diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 67c2a51015a7..24ed59aed17d 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1985,6 +1985,19 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC ); } +/** + * @param {object} transaction + * @param {Number} transactionThreadReportID + * @param {Object} transactionChanges + */ +function editMoneyOrDistanceRequest(transaction, transactionThreadReportID, transactionChanges) { + if (TransactionUtils.isDistanceRequest(transaction)) { + updateDistanceRequest(transaction.transactionID, transactionThreadReportID, transactionChanges); + } else { + editMoneyRequest(transaction.transactionID, transactionThreadReportID, transactionChanges); + } +} + /** * @param {String} transactionID * @param {Object} reportAction - the money request reportAction we are deleting @@ -2962,7 +2975,6 @@ function getIOUReportID(iou, route) { export { createDistanceRequest, - editMoneyRequest, deleteMoneyRequest, splitBill, splitBillAndOpenReport, @@ -2992,8 +3004,8 @@ export { setMoneyRequestReceipt, setUpDistanceTransaction, navigateToNextPage, - updateDistanceRequest, replaceReceipt, detachReceipt, getIOUReportID, + editMoneyOrDistanceRequest, }; diff --git a/src/pages/EditRequestDistancePage.js b/src/pages/EditRequestDistancePage.js index 0fca8aee4be9..410f65943a19 100644 --- a/src/pages/EditRequestDistancePage.js +++ b/src/pages/EditRequestDistancePage.js @@ -102,7 +102,7 @@ function EditRequestDistancePage({report, route, transaction, transactionBackup} } transactionWasSaved.current = true; - IOU.updateDistanceRequest(transaction.transactionID, report.reportID, {waypoints}); + IOU.editMoneyOrDistanceRequest(transaction, report.reportID, {waypoints}); // If the client is offline, then the modal can be closed as well (because there are no errors or other feedback to show them // until they come online again and sync with the server). diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 194cd2855dbd..d113059da8fc 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -119,11 +119,7 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT // Update the transaction object and close the modal function editMoneyRequest(transactionChanges) { - if (TransactionUtils.isDistanceRequest(transaction)) { - IOU.updateDistanceRequest(transaction.transactionID, report.reportID, transactionChanges); - } else { - IOU.editMoneyRequest(transaction.transactionID, report.reportID, transactionChanges); - } + IOU.editMoneyOrDistanceRequest(transaction, report.reportID, transactionChanges); Navigation.dismissModal(report.reportID); } diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 794c57ed31c3..c6037ffede25 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -1478,7 +1478,7 @@ describe('actions/IOU', () => { return waitForBatchedUpdates(); }) .then(() => { - IOU.editMoneyRequest(transaction.transactionID, thread.reportID, {amount: 20000, comment: 'Double the amount!'}); + IOU.editMoneyOrDistanceRequest(transaction, thread.reportID, {amount: 20000, comment: 'Double the amount!'}); return waitForBatchedUpdates(); }) .then( @@ -1613,7 +1613,7 @@ describe('actions/IOU', () => { }) .then(() => { fetch.fail(); - IOU.editMoneyRequest(transaction.transactionID, thread.reportID, {amount: 20000, comment: 'Double the amount!'}); + IOU.editMoneyOrDistanceRequest(transaction, thread.reportID, {amount: 20000, comment: 'Double the amount!'}); return waitForBatchedUpdates(); }) .then( From 3e59d001bfe7ef605e6ce3779bd62d4b6a669cda Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Sat, 18 Nov 2023 02:58:56 +0530 Subject: [PATCH 2/2] update: edit money function names. Signed-off-by: Krishna Gupta --- src/components/ReportActionItem/MoneyRequestView.js | 2 +- src/libs/actions/IOU.js | 12 ++++++------ src/pages/EditRequestDistancePage.js | 2 +- src/pages/EditRequestPage.js | 2 +- tests/actions/IOUTest.js | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js index f7a6f10be88e..33ad99f32326 100644 --- a/src/components/ReportActionItem/MoneyRequestView.js +++ b/src/components/ReportActionItem/MoneyRequestView.js @@ -287,7 +287,7 @@ function MoneyRequestView({report, parentReport, policyCategories, shouldShowHor IOU.editMoneyOrDistanceRequest(transaction, report.reportID, {billable: value})} + onToggle={(value) => IOU.editMoneyRequest(transaction, report.reportID, {billable: value})} /> )} diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 24ed59aed17d..6347f45549c7 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -687,7 +687,7 @@ function createDistanceRequest(report, participant, comment, created, transactio * @param {Object} [transactionChanges.waypoints] * */ -function updateDistanceRequest(transactionID, transactionThreadReportID, transactionChanges) { +function editDistanceMoneyRequest(transactionID, transactionThreadReportID, transactionChanges) { const optimisticData = []; const successData = []; const failureData = []; @@ -1771,7 +1771,7 @@ function setDraftSplitTransaction(transactionID, transactionChanges = {}) { * @param {Number} transactionThreadReportID * @param {Object} transactionChanges */ -function editMoneyRequest(transactionID, transactionThreadReportID, transactionChanges) { +function editRegularMoneyRequest(transactionID, transactionThreadReportID, transactionChanges) { // STEP 1: Get all collections we're updating const transactionThread = allReports[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; @@ -1990,11 +1990,11 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC * @param {Number} transactionThreadReportID * @param {Object} transactionChanges */ -function editMoneyOrDistanceRequest(transaction, transactionThreadReportID, transactionChanges) { +function editMoneyRequest(transaction, transactionThreadReportID, transactionChanges) { if (TransactionUtils.isDistanceRequest(transaction)) { - updateDistanceRequest(transaction.transactionID, transactionThreadReportID, transactionChanges); + editDistanceMoneyRequest(transaction.transactionID, transactionThreadReportID, transactionChanges); } else { - editMoneyRequest(transaction.transactionID, transactionThreadReportID, transactionChanges); + editRegularMoneyRequest(transaction.transactionID, transactionThreadReportID, transactionChanges); } } @@ -3007,5 +3007,5 @@ export { replaceReceipt, detachReceipt, getIOUReportID, - editMoneyOrDistanceRequest, + editMoneyRequest, }; diff --git a/src/pages/EditRequestDistancePage.js b/src/pages/EditRequestDistancePage.js index 410f65943a19..375d56935135 100644 --- a/src/pages/EditRequestDistancePage.js +++ b/src/pages/EditRequestDistancePage.js @@ -102,7 +102,7 @@ function EditRequestDistancePage({report, route, transaction, transactionBackup} } transactionWasSaved.current = true; - IOU.editMoneyOrDistanceRequest(transaction, report.reportID, {waypoints}); + IOU.editMoneyRequest(transaction, report.reportID, {waypoints}); // If the client is offline, then the modal can be closed as well (because there are no errors or other feedback to show them // until they come online again and sync with the server). diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index d113059da8fc..95313bea142d 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -119,7 +119,7 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT // Update the transaction object and close the modal function editMoneyRequest(transactionChanges) { - IOU.editMoneyOrDistanceRequest(transaction, report.reportID, transactionChanges); + IOU.editMoneyRequest(transaction, report.reportID, transactionChanges); Navigation.dismissModal(report.reportID); } diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index c6037ffede25..7d8a8a4202e7 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -1478,7 +1478,7 @@ describe('actions/IOU', () => { return waitForBatchedUpdates(); }) .then(() => { - IOU.editMoneyOrDistanceRequest(transaction, thread.reportID, {amount: 20000, comment: 'Double the amount!'}); + IOU.editMoneyRequest(transaction, thread.reportID, {amount: 20000, comment: 'Double the amount!'}); return waitForBatchedUpdates(); }) .then( @@ -1613,7 +1613,7 @@ describe('actions/IOU', () => { }) .then(() => { fetch.fail(); - IOU.editMoneyOrDistanceRequest(transaction, thread.reportID, {amount: 20000, comment: 'Double the amount!'}); + IOU.editMoneyRequest(transaction, thread.reportID, {amount: 20000, comment: 'Double the amount!'}); return waitForBatchedUpdates(); }) .then(