From 9bd8f5d7fde9b899b6007597d1864fe26ab37b42 Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Thu, 4 Jan 2024 16:29:47 -0500 Subject: [PATCH 1/4] add updatemoneyrequestdescription --- src/libs/actions/IOU.js | 16 ++++++++++++++++ src/pages/EditRequestPage.js | 19 +++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 21997023fbc8..12ad2d007067 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1069,6 +1069,21 @@ function updateMoneyRequestTag(transactionID, transactionThreadReportID, tag) { API.write('UpdateMoneyRequestTag', params, onyxData); } +/** + * Updates the description of a money request + * + * @param {String} transactionID + * @param {Number} transactionThreadReportID + * @param {String} comment + */ +function updateMoneyRequestDescription(transactionID, transactionThreadReportID, comment) { + const transactionChanges = { + comment, + }; + const {params, onyxData} = getUpdateMoneyRequestParams(transactionID, transactionThreadReportID, transactionChanges, true); + API.write('UpdateMoneyRequestDescription', params, onyxData); +} + /** * Edits an existing distance request * @@ -3510,6 +3525,7 @@ export { updateMoneyRequestDate, updateMoneyRequestTag, updateMoneyRequestAmountAndCurrency, + updateMoneyRequestDescription, replaceReceipt, detachReceipt, getIOUReportID, diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 54c5202fb205..1d8b175ae23a 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -162,18 +162,21 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT [transactionTag, transaction.transactionID, report.reportID], ); + const saveComment = useCallback( + ({comment: newComment}) => { + // Update comment only if it has changed + if (newComment.trim() !== transactionDescription) { + IOU.updateMoneyRequestDescription(transaction.transactionID, report.reportID, newComment.trim()); + } + Navigation.dismissModal(); + } + ) + if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.DESCRIPTION) { return ( { - // In case the comment hasn't been changed, do not make the API request. - if (transactionChanges.comment.trim() === transactionDescription) { - Navigation.dismissModal(); - return; - } - editMoneyRequest({comment: transactionChanges.comment.trim()}); - }} + onSubmit={saveComment} /> ); } From e5594e91c22840105889e065f27ca74f49106115 Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Thu, 4 Jan 2024 18:27:32 -0500 Subject: [PATCH 2/4] update comment --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 12ad2d007067..d4ca15929675 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1055,7 +1055,7 @@ function updateMoneyRequestDate(transactionID, transactionThreadReportID, val) { } /** - * Updates the created date of a money request + * Updates the tag of a money request * * @param {String} transactionID * @param {Number} transactionThreadReportID From fc886b72359680e01ae26e4836e0a6fb1af9bbc9 Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Thu, 4 Jan 2024 20:46:09 -0500 Subject: [PATCH 3/4] minor style and clarifications --- src/pages/EditRequestPage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 1d8b175ae23a..c351efcf1bdc 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -164,13 +164,13 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT const saveComment = useCallback( ({comment: newComment}) => { - // Update comment only if it has changed + // Only update comment if it has changed if (newComment.trim() !== transactionDescription) { IOU.updateMoneyRequestDescription(transaction.transactionID, report.reportID, newComment.trim()); } Navigation.dismissModal(); } - ) + ); if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.DESCRIPTION) { return ( From 01b9f03ab67c38979f2c02b07bb91189675f2332 Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Fri, 5 Jan 2024 13:29:45 -0500 Subject: [PATCH 4/4] include dependencies for callback --- src/pages/EditRequestPage.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 1d8b175ae23a..4efbdeb7e841 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -169,8 +169,9 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT IOU.updateMoneyRequestDescription(transaction.transactionID, report.reportID, newComment.trim()); } Navigation.dismissModal(); - } - ) + }, + [transactionDescription, transaction.transactionID, report.reportID], + ); if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.DESCRIPTION) { return (