Skip to content

Commit

Permalink
Merge pull request #54778 from daledah/fix/53998
Browse files Browse the repository at this point in the history
fix: display message when user detach a receipt
  • Loading branch information
arosiclair authored Jan 30, 2025
2 parents 649c720 + b949c63 commit 6118a1f
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/libs/API/parameters/DetachReceiptParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type DetachReceiptParams = {
transactionID: string;
reportActionID: string;
};

export default DetachReceiptParams;
38 changes: 38 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5595,6 +5595,43 @@ function buildOptimisticModifiedExpenseReportAction(
};
}

/**
* Builds an optimistic DETACH_RECEIPT report action with a randomly generated reportActionID.
*/
function buildOptimisticDetachReceipt(reportID: string | undefined, transactionID: string, merchant: string = CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT) {
return {
actionName: CONST.REPORT.ACTIONS.TYPE.MANAGER_DETACH_RECEIPT,
actorAccountID: currentUserAccountID,
automatic: false,
avatar: getCurrentUserAvatar(),
created: DateUtils.getDBTime(),
isAttachmentOnly: false,
originalMessage: {
transactionID,
merchant: `${merchant}`,
},
message: [
{
type: 'COMMENT',
html: `detached a receipt from expense '${merchant}'`,
text: `detached a receipt from expense '${merchant}'`,
whisperedTo: [],
},
],
person: [
{
style: 'strong',
text: currentUserPersonalDetails?.displayName ?? String(currentUserAccountID),
type: 'TEXT',
},
],
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
reportActionID: rand64(),
reportID,
shouldShow: true,
};
}

/**
* Builds an optimistic modified expense action for a tracked expense move with a randomly generated reportActionID.
* @param transactionThreadID - The reportID of the transaction thread
Expand Down Expand Up @@ -8915,6 +8952,7 @@ export {
buildOptimisticAnnounceChat,
buildOptimisticWorkspaceChats,
buildOptimisticCardAssignedReportAction,
buildOptimisticDetachReceipt,
buildParticipantsFromAccountIDs,
buildReportNameFromParticipantNames,
buildTransactionThread,
Expand Down
46 changes: 45 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import {
buildOptimisticCancelPaymentReportAction,
buildOptimisticChatReport,
buildOptimisticCreatedReportAction,
buildOptimisticDetachReceipt,
buildOptimisticDismissedViolationReportAction,
buildOptimisticExpenseReport,
buildOptimisticHoldReportAction,
Expand Down Expand Up @@ -8706,8 +8707,51 @@ function detachReceipt(transactionID: string | undefined) {
},
},
];
const expenseReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transaction?.reportID}`] ?? null;
const updatedReportAction = buildOptimisticDetachReceipt(expenseReport?.reportID, transactionID, transaction?.merchant);

const parameters: DetachReceiptParams = {transactionID};
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${updatedReportAction?.reportID}`,
value: {
[updatedReportAction.reportActionID]: updatedReportAction as OnyxTypes.ReportAction,
},
});
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${updatedReportAction?.reportID}`,
value: {
lastVisibleActionCreated: updatedReportAction.created,
lastReadTime: updatedReportAction.created,
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${updatedReportAction?.reportID}`,
value: {
lastVisibleActionCreated: expenseReport?.lastVisibleActionCreated,
lastReadTime: expenseReport?.lastReadTime,
},
});
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport?.reportID}`,
value: {
[updatedReportAction.reportActionID]: {pendingAction: null},
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport?.reportID}`,
value: {
[updatedReportAction.reportActionID]: {
...(updatedReportAction as OnyxTypes.ReportAction),
errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericEditFailureMessage'),
},
},
});

const parameters: DetachReceiptParams = {transactionID, reportActionID: updatedReportAction.reportActionID};

API.write(WRITE_COMMANDS.DETACH_RECEIPT, parameters, {optimisticData, successData, failureData});
}
Expand Down

0 comments on commit 6118a1f

Please sign in to comment.