Skip to content

Commit

Permalink
Merge pull request #33997 from Expensify/nikki-update-moneyrequest-de…
Browse files Browse the repository at this point in the history
…scription

Add updateMoneyRequestDescription command
  • Loading branch information
NikkiWines authored Jan 15, 2024
2 parents a459786 + 2d59d22 commit c13c497
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 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 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
*
Expand Down Expand Up @@ -3779,6 +3794,7 @@ export {
updateMoneyRequestMerchant,
updateMoneyRequestTag,
updateMoneyRequestAmountAndCurrency,
updateMoneyRequestDescription,
replaceReceipt,
detachReceipt,
getIOUReportID,
Expand Down
20 changes: 12 additions & 8 deletions src/pages/EditRequestPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<EditRequestDescriptionPage
defaultDescription={transactionDescription}
onSubmit={(transactionChanges) => {
// 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}
/>
);
}
Expand Down

0 comments on commit c13c497

Please sign in to comment.