Skip to content

Commit

Permalink
Merge pull request #45315 from Expensify/rodrigo-fix-violation-message
Browse files Browse the repository at this point in the history
Adds different reportAction if submitter when dismissing violation
  • Loading branch information
aldo-expensify authored Jul 16, 2024
2 parents 9ba5d06 + 3d6dbdc commit f83abb0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/libs/API/parameters/DismissViolationParams.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type DismissViolationParams = {
name: string;
transactionIDList: string;
reportActionIDList: string;
};

export default DismissViolationParams;
14 changes: 10 additions & 4 deletions src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {DismissViolationParams, GetRouteParams, MarkAsCashParams} from '@li
import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import * as CollectionUtils from '@libs/CollectionUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import {buildOptimisticDismissedViolationReportAction} from '@libs/ReportUtils';
import {buildOptimisticDismissedViolationReportAction, buildOptimisticUnHoldReportAction, isCurrentUserSubmitter} from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -292,9 +292,14 @@ 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 optimisticDissmidedViolationReportActions = transactionsReportActions.map(() =>
buildOptimisticDismissedViolationReportAction({reason: 'manual', violationName: CONST.VIOLATIONS.DUPLICATED_TRANSACTION}),
);
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});
});

const optimisticData: OnyxUpdate[] = [];
const failureData: OnyxUpdate[] = [];

Expand Down Expand Up @@ -371,6 +376,7 @@ function dismissDuplicateTransactionViolation(transactionIDs: string[], dissmiss
const params: DismissViolationParams = {
name: CONST.VIOLATIONS.DUPLICATED_TRANSACTION,
transactionIDList: transactionIDs.join(','),
reportActionIDList: optimisticDissmidedViolationReportActions.map((action) => action.reportActionID).join(','),
};

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

0 comments on commit f83abb0

Please sign in to comment.