Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,21 @@ function updateMoneyRequestTag(transactionID, transactionThreadReportID, tag) {
API.write('UpdateMoneyRequestTag', params, onyxData);
}

/**
* Updates the category of a money request
*
* @param {String} transactionID
* @param {Number} transactionThreadReportID
* @param {String} category
*/
function updateMoneyRequestCategory(transactionID, transactionThreadReportID, category) {
const transactionChanges = {
category,
};
const {params, onyxData} = getUpdateMoneyRequestParams(transactionID, transactionThreadReportID, transactionChanges, true);
API.write('UpdateMoneyRequestCategory', params, onyxData);
}

/**
* Updates the description of a money request
*
Expand Down Expand Up @@ -3692,6 +3707,7 @@ export {
updateMoneyRequestBillable,
updateMoneyRequestMerchant,
updateMoneyRequestTag,
updateMoneyRequestCategory,
updateMoneyRequestAmountAndCurrency,
updateMoneyRequestDescription,
replaceReceipt,
Expand Down
25 changes: 11 additions & 14 deletions src/pages/EditRequestPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@ function EditRequestPage({report, route, policyCategories, policyTags, parentRep
});
}, [parentReportAction, fieldToEdit]);

// Update the transaction object and close the modal
function editMoneyRequest(transactionChanges) {
IOU.editMoneyRequest(transaction, report.reportID, transactionChanges);
Navigation.dismissModal(report.reportID);
}

const saveAmountAndCurrency = useCallback(
({amount, currency: newCurrency}) => {
const newAmount = CurrencyUtils.convertToBackendAmount(Number.parseFloat(amount));
Expand Down Expand Up @@ -176,6 +170,16 @@ function EditRequestPage({report, route, policyCategories, policyTags, parentRep
[transactionTag, transaction.transactionID, report.reportID],
);

const saveCategory = useCallback(
({category: newCategory}) => {
// In case the same category has been selected, reset the category.
const updatedCategory = newCategory === transactionCategory ? '' : newCategory;

@MonilBhavsar MonilBhavsar Jan 22, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we prevent making an API call if newCategory is same as current?
Oops, let's add this comment

// In case the same category has been selected, do reset of the category.

IOU.updateMoneyRequestCategory(transaction.transactionID, report.reportID, updatedCategory);
Navigation.dismissModal();
},
[transactionCategory, transaction.transactionID, report.reportID],
);

const saveComment = useCallback(
({comment: newComment}) => {
// Only update comment if it has changed
Expand Down Expand Up @@ -235,14 +239,7 @@ function EditRequestPage({report, route, policyCategories, policyTags, parentRep
<EditRequestCategoryPage
defaultCategory={transactionCategory}
policyID={lodashGet(report, 'policyID', '')}
onSubmit={(transactionChanges) => {
let updatedCategory = transactionChanges.category;
// In case the same category has been selected, do reset of the category.
if (transactionCategory === updatedCategory) {
updatedCategory = '';
}
editMoneyRequest({category: updatedCategory});
}}
onSubmit={saveCategory}
/>
);
}
Expand Down