Skip to content

Commit

Permalink
Merge pull request Expensify#34073 from Expensify/nikki-update-moneyr…
Browse files Browse the repository at this point in the history
…equest-category

Add updateMoneyRequestCategory command
  • Loading branch information
MonilBhavsar authored Jan 23, 2024
2 parents 8390cbf + ba4ce85 commit 9c552ab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
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 @@ -3719,6 +3734,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;
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

0 comments on commit 9c552ab

Please sign in to comment.