Skip to content

Commit

Permalink
Merge pull request #32769 from Expensify/aldo_update-money-request-tag
Browse files Browse the repository at this point in the history
Add UpdateMoneyRequestTag command
  • Loading branch information
arosiclair authored Jan 4, 2024
2 parents adf68dc + 88472c6 commit d569d32
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
16 changes: 16 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,21 @@ function updateMoneyRequestDate(transactionID, transactionThreadReportID, val) {
API.write('UpdateMoneyRequestDate', params, onyxData);
}

/**
* Updates the created date of a money request
*
* @param {String} transactionID
* @param {Number} transactionThreadReportID
* @param {String} tag
*/
function updateMoneyRequestTag(transactionID, transactionThreadReportID, tag) {
const transactionChanges = {
tag,
};
const {params, onyxData} = getUpdateMoneyRequestParams(transactionID, transactionThreadReportID, transactionChanges, true);
API.write('UpdateMoneyRequestTag', params, onyxData);
}

/**
* Edits an existing distance request
*
Expand Down Expand Up @@ -3493,6 +3508,7 @@ export {
setUpDistanceTransaction,
navigateToNextPage,
updateMoneyRequestDate,
updateMoneyRequestTag,
updateMoneyRequestAmountAndCurrency,
replaceReceipt,
detachReceipt,
Expand Down
23 changes: 14 additions & 9 deletions src/pages/EditRequestPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT
[transaction, report],
);

const saveTag = useCallback(
({tag: newTag}) => {
let updatedTag = newTag;
if (newTag === transactionTag) {
// In case the same tag has been selected, reset the tag.
updatedTag = '';
}
IOU.updateMoneyRequestTag(transaction.transactionID, report.reportID, updatedTag);
Navigation.dismissModal();
},
[transactionTag, transaction.transactionID, report.reportID],
);

if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.DESCRIPTION) {
return (
<EditRequestDescriptionPage
Expand Down Expand Up @@ -238,15 +251,7 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT
defaultTag={transactionTag}
tagName={tagListName}
policyID={lodashGet(report, 'policyID', '')}
onSubmit={(transactionChanges) => {
let updatedTag = transactionChanges.tag;

// In case the same tag has been selected, reset the tag.
if (transactionTag === updatedTag) {
updatedTag = '';
}
editMoneyRequest({tag: updatedTag, tagListName});
}}
onSubmit={saveTag}
/>
);
}
Expand Down

0 comments on commit d569d32

Please sign in to comment.