Skip to content

Commit

Permalink
Merge pull request #52060 from FitseTLT/fix-showing-duplicate-resolve…
Browse files Browse the repository at this point in the history
…d-system-message

Fix - Duplicate system message when resolving duplicates selecting "Keep all"
  • Loading branch information
pecanoro authored Nov 7, 2024
2 parents b7a9c9b + e267aa6 commit 5fa03b9
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import * as API from '@libs/API';
import type {DismissViolationParams, GetRouteParams, MarkAsCashParams} from '@libs/API/parameters';
import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import * as CollectionUtils from '@libs/CollectionUtils';
import * as NumberUtils from '@libs/NumberUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import {buildOptimisticDismissedViolationReportAction, buildOptimisticUnHoldReportAction, isCurrentUserSubmitter} from '@libs/ReportUtils';
import {buildOptimisticDismissedViolationReportAction} from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -352,11 +353,7 @@ function dismissDuplicateTransactionViolation(transactionIDs: string[], dissmiss
const currentTransactionViolations = transactionIDs.map((id) => ({transactionID: id, violations: allTransactionViolation?.[id] ?? []}));
const currentTransactions = transactionIDs.map((id) => allTransactions?.[id]);
const transactionsReportActions = currentTransactions.map((transaction) => ReportActionsUtils.getIOUActionForReportID(transaction.reportID ?? '', transaction.transactionID ?? ''));
const isSubmitter = currentTransactions.every((transaction) => isCurrentUserSubmitter(transaction.reportID ?? ''));
const optimisticDissmidedViolationReportActions = transactionsReportActions.map(() => {
if (isSubmitter) {
return buildOptimisticUnHoldReportAction();
}
return buildOptimisticDismissedViolationReportAction({reason: 'manual', violationName: CONST.VIOLATIONS.DUPLICATED_TRANSACTION});
});

Expand Down Expand Up @@ -427,16 +424,17 @@ function dismissDuplicateTransactionViolation(transactionIDs: string[], dissmiss
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${action?.childReportID ?? '-1'}`,
value: {
[optimisticDissmidedViolationReportActions.at(index)?.reportActionID ?? '']: {
pendingAction: null,
},
[optimisticDissmidedViolationReportActions.at(index)?.reportActionID ?? '']: null,
},
}));

// We are creating duplicate resolved report actions for each duplicate transactions and all the report actions
// should be correctly linked with their parent report but the BE is sometimes linking report actions to different
// parent reports than the one we set optimistically, resulting in duplicate report actions. Therefore, we send the BE
// random report action ids and onSuccessData we reset the report actions we added optimistically to avoid duplicate actions.
const params: DismissViolationParams = {
name: CONST.VIOLATIONS.DUPLICATED_TRANSACTION,
transactionIDList: transactionIDs.join(','),
reportActionIDList: optimisticDissmidedViolationReportActions.map((action) => action.reportActionID).join(','),
reportActionIDList: optimisticDissmidedViolationReportActions.map(() => NumberUtils.rand64()).join(','),
};

API.write(WRITE_COMMANDS.DISMISS_VIOLATION, params, {
Expand Down

0 comments on commit 5fa03b9

Please sign in to comment.