diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js index 37ff163f23c8..b9ecb647f437 100644 --- a/src/components/ReportActionItem/MoneyRequestView.js +++ b/src/components/ReportActionItem/MoneyRequestView.js @@ -179,6 +179,19 @@ function MoneyRequestView({report, parentReport, parentReportActions, policyCate let amountDescription = `${translate('iou.amount')}`; + const saveBillable = useCallback( + (newBillable) => { + // If the value hasn't changed, don't request to save changes on the server and just close the modal + if (newBillable === TransactionUtils.getBillable(transaction)) { + Navigation.dismissModal(); + return; + } + IOU.updateMoneyRequestBillable(transaction.transactionID, report.reportID, newBillable); + Navigation.dismissModal(); + }, + [transaction, report], + ); + if (isCardTransaction) { if (formattedOriginalAmount) { amountDescription += ` • ${translate('iou.original')} ${formattedOriginalAmount}`; @@ -354,7 +367,7 @@ function MoneyRequestView({report, parentReport, parentReportActions, policyCate IOU.editMoneyRequest(transaction, report.reportID, {billable: value})} + onToggle={saveBillable} /> {hasViolations('billable') && ( diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index f2584cb8accd..75ae60970451 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1109,6 +1109,21 @@ function updateMoneyRequestDate(transactionID, transactionThreadReportID, val) { API.write('UpdateMoneyRequestDate', params, onyxData); } +/** + * Updates the billable field of a money request + * + * @param {String} transactionID + * @param {Number} transactionThreadReportID + * @param {String} val + */ +function updateMoneyRequestBillable(transactionID, transactionThreadReportID, val) { + const transactionChanges = { + billable: val, + }; + const {params, onyxData} = getUpdateMoneyRequestParams(transactionID, transactionThreadReportID, transactionChanges, true); + API.write('UpdateMoneyRequestBillable', params, onyxData); +} + /** * Updates the merchant field of a money request * @@ -3605,6 +3620,7 @@ export { setUpDistanceTransaction, navigateToNextPage, updateMoneyRequestDate, + updateMoneyRequestBillable, updateMoneyRequestMerchant, updateMoneyRequestTag, updateMoneyRequestAmountAndCurrency,