Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP Staging] Fix existing expense is removed when dismissing receipt error #44364

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,10 @@ function MoneyRequestView({
if (!transaction?.transactionID) {
return;
}
if (Object.values(transaction?.errors ?? {})?.find((error) => ErrorUtils.isReceiptError(error))) {
if (
transaction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD &&
Object.values(transaction?.errors ?? {})?.find((error) => ErrorUtils.isReceiptError(error))
) {
deleteTransaction(parentReport, parentReportAction);
}
Transaction.clearError(transaction.transactionID);
Expand Down
2 changes: 0 additions & 2 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,6 @@ function buildOnyxDataForMoneyRequest(
// Disabling this line since transaction.filename can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
errors: getReceiptError(transaction.receipt, transaction.filename || transaction.receipt?.filename, isScanRequest, errorKey),
pendingAction: null,
Copy link
Contributor Author

@bernhardoj bernhardoj Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't clear the pending action when fails, otherwise, we don't have the information on whether the action is new or not. That's the pattern we use, for example, when adding a comment/message.

Additional video showing the transaction is deleted when it's a new transaction.

Screen.Recording.2024-06-25.at.11.40.38.mov

pendingFields: clearedPendingFields,
},
},
Expand Down Expand Up @@ -1524,7 +1523,6 @@ function buildOnyxDataForTrackExpense(
// Disabling this line since transaction.filename can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
errors: getReceiptError(transaction.receipt, transaction.filename || transaction.receipt?.filename, isScanRequest),
pendingAction: null,
pendingFields: clearedPendingFields,
},
},
Expand Down
2 changes: 1 addition & 1 deletion tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ describe('actions/IOU', () => {
waitForCollectionCallback: false,
callback: (transaction) => {
Onyx.disconnect(connectionID);
expect(transaction?.pendingAction).toBeFalsy();
expect(transaction?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
expect(transaction?.errors).toBeTruthy();
expect(Object.values(transaction?.errors ?? {})[0]).toEqual(Localize.translateLocal('iou.error.genericCreateFailureMessage'));
resolve();
Expand Down
Loading