Skip to content

Commit

Permalink
Merge pull request Expensify#33245 from Expensify/cmartins-updateMone…
Browse files Browse the repository at this point in the history
…yRequestBillable

Use updateMoneyRequestBillable
  • Loading branch information
MariaHCD authored Jan 9, 2024
2 parents 4e25271 + 6e50cc7 commit 85fee5a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down Expand Up @@ -354,7 +367,7 @@ function MoneyRequestView({report, parentReport, parentReportActions, policyCate
<Switch
accessibilityLabel={translate('common.billable')}
isOn={transactionBillable}
onToggle={(value) => IOU.editMoneyRequest(transaction, report.reportID, {billable: value})}
onToggle={saveBillable}
/>
</View>
{hasViolations('billable') && (
Expand Down
16 changes: 16 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -3605,6 +3620,7 @@ export {
setUpDistanceTransaction,
navigateToNextPage,
updateMoneyRequestDate,
updateMoneyRequestBillable,
updateMoneyRequestMerchant,
updateMoneyRequestTag,
updateMoneyRequestAmountAndCurrency,
Expand Down

0 comments on commit 85fee5a

Please sign in to comment.