From ddb7820c21a5bcc5bf6c6dfec794efa95f0773b4 Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Fri, 5 Jan 2024 22:09:54 -0500 Subject: [PATCH 1/5] add new updateMoneyRequestCategory function --- src/libs/actions/IOU.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index fb4e9f02f1b6..5685f8196425 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1124,6 +1124,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); +} + /** * Edits an existing distance request * @@ -3588,6 +3603,7 @@ export { navigateToNextPage, updateMoneyRequestDate, updateMoneyRequestTag, + updateMoneyRequestCategory, updateMoneyRequestAmountAndCurrency, replaceReceipt, detachReceipt, From bd3759bc4bbf7901bf352826a0b4454e6104061d Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Fri, 5 Jan 2024 22:10:09 -0500 Subject: [PATCH 2/5] update category logic to use saveCategory --- src/pages/EditRequestPage.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index bc05c110ab2f..dcf27fa4719f 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -158,6 +158,15 @@ function EditRequestPage({report, route, policyCategories, policyTags, parentRep [transactionTag, transaction.transactionID, report.reportID], ); + const saveCategory = useCallback( + ({category: newCategory}) => { + let updatedCategory = newCategory === transactionCategory ? '' : newCategory; + IOU.updateMoneyRequestCategory(transaction.transactionID, report.reportID, updatedCategory); + Navigation.dismissModal(); + }, + [transactionCategory, transaction.transactionID, report.reportID], + ); + if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.DESCRIPTION) { return ( { - 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} /> ); } From cecdfc3fb809e23993cb5abe8044baa0cf4a69ca Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Wed, 10 Jan 2024 14:39:34 -0500 Subject: [PATCH 3/5] const instead of let --- src/pages/EditRequestPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index dcf27fa4719f..778bbf71a91d 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -160,7 +160,7 @@ function EditRequestPage({report, route, policyCategories, policyTags, parentRep const saveCategory = useCallback( ({category: newCategory}) => { - let updatedCategory = newCategory === transactionCategory ? '' : newCategory; + const updatedCategory = newCategory === transactionCategory ? '' : newCategory; IOU.updateMoneyRequestCategory(transaction.transactionID, report.reportID, updatedCategory); Navigation.dismissModal(); }, From 4611ebba233fe2bc7f168f8074d50b798fff1888 Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Mon, 15 Jan 2024 11:24:35 -0800 Subject: [PATCH 4/5] remove unused editMoneyRequest function --- src/pages/EditRequestPage.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index d18ca2db8a27..db43154f5a12 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -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)); From db1bbe77372b5f9027788eabd0a7d0d5a96c5e14 Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Mon, 22 Jan 2024 11:18:56 -0800 Subject: [PATCH 5/5] add clarifying comment --- src/pages/EditRequestPage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index db43154f5a12..3eb9d88f1120 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -172,6 +172,7 @@ function EditRequestPage({report, route, policyCategories, policyTags, parentRep 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();