diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js index 1da061fc741e..33ad99f32326 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.editMoneyRequest(transaction, report.reportID, {billable: value})} /> )} diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 67c2a51015a7..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}`]; @@ -1985,6 +1985,19 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC ); } +/** + * @param {object} transaction + * @param {Number} transactionThreadReportID + * @param {Object} transactionChanges + */ +function editMoneyRequest(transaction, transactionThreadReportID, transactionChanges) { + if (TransactionUtils.isDistanceRequest(transaction)) { + editDistanceMoneyRequest(transaction.transactionID, transactionThreadReportID, transactionChanges); + } else { + editRegularMoneyRequest(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, + editMoneyRequest, }; diff --git a/src/pages/EditRequestDistancePage.js b/src/pages/EditRequestDistancePage.js index 0fca8aee4be9..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.updateDistanceRequest(transaction.transactionID, 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 194cd2855dbd..95313bea142d 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.editMoneyRequest(transaction, report.reportID, transactionChanges); Navigation.dismissModal(report.reportID); } diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 794c57ed31c3..7d8a8a4202e7 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.editMoneyRequest(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.editMoneyRequest(transaction, thread.reportID, {amount: 20000, comment: 'Double the amount!'}); return waitForBatchedUpdates(); }) .then(