diff --git a/src/libs/actions/Transaction.ts b/src/libs/actions/Transaction.ts index e38966fd989c..7469c6d515f7 100644 --- a/src/libs/actions/Transaction.ts +++ b/src/libs/actions/Transaction.ts @@ -28,7 +28,7 @@ import { hasViolations as hasViolationsReportUtils, shouldEnableNegative, } from '@libs/ReportUtils'; -import {isOnHold, waypointHasValidAddress} from '@libs/TransactionUtils'; +import {isManagedCardTransaction, isOnHold, waypointHasValidAddress} from '@libs/TransactionUtils'; import ViolationsUtils from '@libs/Violations/ViolationsUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -50,6 +50,7 @@ import type {OnyxData} from '@src/types/onyx/Request'; import type {WaypointCollection} from '@src/types/onyx/Transaction'; import type TransactionState from '@src/types/utils/TransactionStateType'; import {getPolicyTagsData} from './Policy/Tag'; +import {getCurrentUserAccountID} from './Report'; const allTransactions: Record = {}; Onyx.connect({ @@ -722,6 +723,7 @@ function changeTransactionsReport( const existingSelfDMReportID = findSelfDMReportID(); let selfDMReport: Report | undefined; let selfDMCreatedReportAction: ReportAction | undefined; + const currentUserAccountID = getCurrentUserAccountID(); if (!existingSelfDMReportID && reportID === CONST.REPORT.UNREPORTED_REPORT_ID) { const currentTime = DateUtils.getDBTime(); @@ -1051,16 +1053,22 @@ function changeTransactionsReport( ); } - // 5. Optimistically update the transaction thread and all threads in the transaction thread - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${newIOUAction.childReportID}`, - value: { - parentReportID: targetReportID, - parentReportActionID: optimisticMoneyRequestReportActionID, - policyID: reportID !== CONST.REPORT.UNREPORTED_REPORT_ID && newReport ? newReport.policyID : CONST.POLICY.ID_FAKE, - }, - }); + const shouldRemoveOtherParticipants = !isManagedCardTransaction(transaction); + const childReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${newIOUAction.childReportID}`]; + if (childReport) { + const participants = childReport.participants; + // 5. Optimistically update the transaction thread and all threads in the transaction thread + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${newIOUAction.childReportID}`, + value: { + parentReportID: targetReportID, + parentReportActionID: optimisticMoneyRequestReportActionID, + policyID: reportID !== CONST.REPORT.UNREPORTED_REPORT_ID && newReport ? newReport.policyID : CONST.POLICY.ID_FAKE, + participants: isUnreported && shouldRemoveOtherParticipants ? {[currentUserAccountID]: participants?.[currentUserAccountID]} : participants, + }, + }); + } if (oldIOUAction) { failureData.push({