@@ -22,7 +22,6 @@ import {
2222 buildOptimisticUnHoldReportAction ,
2323 buildOptimisticUnreportedTransactionAction ,
2424 buildTransactionThread ,
25- findSelfDMReportID ,
2625 getReportTransactions ,
2726 getTransactionDetails ,
2827 hasViolations as hasViolationsReportUtils ,
@@ -701,6 +700,7 @@ function changeTransactionsReport(
701700 policy ?: OnyxEntry < Policy > ,
702701 reportNextStep ?: OnyxEntry < ReportNextStepDeprecated > ,
703702 policyCategories ?: OnyxEntry < PolicyCategories > ,
703+ selfDMReportIDParam ?: string ,
704704) {
705705 const reportID = newReport ?. reportID ?? CONST . REPORT . UNREPORTED_REPORT_ID ;
706706
@@ -720,15 +720,16 @@ function changeTransactionsReport(
720720 const failureData : OnyxUpdate [ ] = [ ] ;
721721 const successData : OnyxUpdate [ ] = [ ] ;
722722
723- const existingSelfDMReportID = findSelfDMReportID ( ) ;
724- let selfDMReport : Report | undefined ;
723+ let selfDMReportID = selfDMReportIDParam ;
724+ let selfDMReport : Report | undefined = allReports ?. [ ` ${ ONYXKEYS . COLLECTION . REPORT } ${ selfDMReportID } ` ] ;
725725 let selfDMCreatedReportAction : ReportAction | undefined ;
726726 const currentUserAccountID = getCurrentUserAccountID ( ) ;
727727
728- if ( ! existingSelfDMReportID && reportID === CONST . REPORT . UNREPORTED_REPORT_ID ) {
728+ if ( ! selfDMReport && reportID === CONST . REPORT . UNREPORTED_REPORT_ID ) {
729729 const currentTime = DateUtils . getDBTime ( ) ;
730730 selfDMReport = buildOptimisticSelfDMReport ( currentTime ) ;
731731 selfDMCreatedReportAction = buildOptimisticCreatedReportAction ( email ?? '' , currentTime ) ;
732+ selfDMReportID = selfDMReport . reportID ;
732733
733734 // Add optimistic updates for self DM report
734735 optimisticData . push (
@@ -811,8 +812,6 @@ function changeTransactionsReport(
811812 for ( const transaction of transactions ) {
812813 const isUnreportedExpense = ! transaction . reportID || transaction . reportID === CONST . REPORT . UNREPORTED_REPORT_ID ;
813814
814- const selfDMReportID = existingSelfDMReportID ?? selfDMReport ?. reportID ;
815-
816815 const oldIOUAction = getIOUActionForReportID ( isUnreportedExpense ? selfDMReportID : transaction . reportID , transaction . transactionID ) ;
817816 if ( ! transaction . reportID || transaction . reportID === reportID ) {
818817 continue ;
@@ -1179,11 +1178,11 @@ function changeTransactionsReport(
11791178 : { } ) ,
11801179 } ;
11811180
1182- if ( ! existingSelfDMReportID && reportID === CONST . REPORT . UNREPORTED_REPORT_ID && selfDMReport && selfDMCreatedReportAction ) {
1181+ if ( reportID === CONST . REPORT . UNREPORTED_REPORT_ID && selfDMReport && selfDMCreatedReportAction ) {
11831182 // Add self DM data to transaction data
11841183 transactionIDToReportActionAndThreadData [ transaction . transactionID ] = {
11851184 ...baseTransactionData ,
1186- selfDMReportID : selfDMReport . reportID ,
1185+ selfDMReportID,
11871186 selfDMCreatedReportActionID : selfDMCreatedReportAction . reportActionID ,
11881187 } ;
11891188 } else {
@@ -1295,7 +1294,7 @@ function changeTransactionsReport(
12951294 }
12961295
12971296 // 9. Update next step for report
1298- const destinationReportID = reportID === CONST . REPORT . UNREPORTED_REPORT_ID ? ( existingSelfDMReportID ?? selfDMReport ?. reportID ) : reportID ;
1297+ const destinationReportID = reportID === CONST . REPORT . UNREPORTED_REPORT_ID ? selfDMReportID : reportID ;
12991298 const destinationReport = destinationReportID
13001299 ? ( allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ destinationReportID } ` ] ??
13011300 ( destinationReportID === newReport ?. reportID ? newReport : undefined ) ??
0 commit comments