Skip to content

Commit

Permalink
Merge pull request #55801 from Tony-MK/fix/55138
Browse files Browse the repository at this point in the history
fix: Removing the transaction's ID from other duplicate violation data when deleting one of the duplicate expenses.
  • Loading branch information
Julesssss authored Feb 10, 2025
2 parents a06540c + 3c6f219 commit 71ee505
Showing 1 changed file with 51 additions and 8 deletions.
59 changes: 51 additions & 8 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ import {
isPerDiemRequest as isPerDiemRequestTransactionUtils,
isReceiptBeingScanned as isReceiptBeingScannedTransactionUtils,
isScanRequest as isScanRequestTransactionUtils,
removeSettledAndApprovedTransactions,
shouldShowBrokenConnectionViolation,
} from '@libs/TransactionUtils';
import ViolationsUtils from '@libs/Violations/ViolationsUtils';
Expand Down Expand Up @@ -6764,6 +6765,56 @@ function deleteMoneyRequest(transactionID: string | undefined, reportAction: Ony
value: null,
});

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
value: transaction ?? null,
},
];

if (transactionViolations) {
removeSettledAndApprovedTransactions(
transactionViolations.filter((violation) => violation?.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION).flatMap((violation) => violation?.data?.duplicates ?? []),
).forEach((duplicateID) => {
const duplicateTransactionsViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${duplicateID}`];
if (!duplicateTransactionsViolations) {
return;
}

const duplicateViolation = duplicateTransactionsViolations.find((violation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION);
if (!duplicateViolation?.data?.duplicates) {
return;
}

const duplicateTransactionIDs = duplicateViolation.data.duplicates.filter((duplicateTransactionID) => duplicateTransactionID !== transactionID);

const optimisticViolations: OnyxTypes.TransactionViolations = duplicateTransactionsViolations.filter((violation) => violation.name !== CONST.VIOLATIONS.DUPLICATED_TRANSACTION);

if (duplicateTransactionIDs.length > 0) {
optimisticViolations.push({
...duplicateViolation,
data: {
...duplicateViolation.data,
duplicates: duplicateTransactionIDs,
},
});
}

optimisticData.push({
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${duplicateID}`,
value: optimisticViolations.length > 0 ? optimisticViolations : null,
});

failureData.push({
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${duplicateID}`,
value: duplicateTransactionsViolations,
});
});
}

if (shouldDeleteTransactionThread) {
optimisticData.push(
// Use merge instead of set to avoid deleting the report too quickly, which could cause a brief "not found" page to appear.
Expand Down Expand Up @@ -6909,14 +6960,6 @@ function deleteMoneyRequest(transactionID: string | undefined, reportAction: Ony
});
}

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
value: transaction ?? null,
},
];

failureData.push({
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`,
Expand Down

0 comments on commit 71ee505

Please sign in to comment.