diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index bae6d845575b..49b6a3b445e1 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1183,6 +1183,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 * @@ -3779,6 +3794,7 @@ export { updateMoneyRequestMerchant, updateMoneyRequestTag, updateMoneyRequestAmountAndCurrency, + updateMoneyRequestDescription, replaceReceipt, detachReceipt, getIOUReportID, diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index fe43d96001a0..606d3da1ddb9 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -176,18 +176,22 @@ function EditRequestPage({report, route, policyCategories, policyTags, parentRep [transactionTag, transaction.transactionID, report.reportID], ); + const saveComment = useCallback( + ({comment: newComment}) => { + // Only update comment if it has changed + if (newComment.trim() !== transactionDescription) { + IOU.updateMoneyRequestDescription(transaction.transactionID, report.reportID, newComment.trim()); + } + Navigation.dismissModal(); + }, + [transactionDescription, transaction.transactionID, report.reportID], + ); + 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} /> ); }