@@ -44,7 +44,7 @@ import Log from '@libs/Log';
4444import Navigation from '@libs/Navigation/Navigation' ;
4545import { getManagerMcTestParticipant , getParticipantsOption , getReportOption } from '@libs/OptionsListUtils' ;
4646import { isPaidGroupPolicy } from '@libs/PolicyUtils' ;
47- import { generateReportID , getPolicyExpenseChat , isArchivedReport , isPolicyExpenseChat } from '@libs/ReportUtils' ;
47+ import { findSelfDMReportID , generateReportID , getPolicyExpenseChat , isArchivedReport , isPolicyExpenseChat } from '@libs/ReportUtils' ;
4848import { shouldRestrictUserBillableActions } from '@libs/SubscriptionUtils' ;
4949import { getDefaultTaxCode , hasReceipt } from '@libs/TransactionUtils' ;
5050import ReceiptDropUI from '@pages/iou/ReceiptDropUI' ;
@@ -142,6 +142,8 @@ function IOURequestStepScan({
142142 const canUseMultiDragAndDrop = isBetaEnabled ( CONST . BETAS . NEWDOT_MULTI_FILES_DRAG_AND_DROP ) ;
143143 const shouldAcceptMultipleFiles = canUseMultiDragAndDrop && ! isEditing && ! backTo ;
144144
145+ const selfDMReportID = useMemo ( ( ) => findSelfDMReportID ( ) , [ ] ) ;
146+
145147 const blinkOpacity = useSharedValue ( 0 ) ;
146148 const blinkStyle = useAnimatedStyle ( ( ) => ( {
147149 opacity : blinkOpacity . get ( ) ,
@@ -505,14 +507,24 @@ function IOURequestStepScan({
505507
506508 // If there was no reportID, then that means the user started this flow from the global + menu
507509 // and an optimistic reportID was generated. In that case, the next step is to select the participants for this expense.
508- const activePolicyExpenseChat = getPolicyExpenseChat ( currentUserPersonalDetails . accountID , activePolicy ?. id ) ;
509- if (
510- ( ! initialTransaction ?. participants || initialTransaction ?. participants ?. at ( 0 ) ?. reportID === activePolicyExpenseChat ?. reportID ) &&
511- iouType === CONST . IOU . TYPE . CREATE &&
512- isPaidGroupPolicy ( activePolicy ) &&
513- activePolicy ?. isPolicyExpenseChatEnabled &&
514- ! shouldRestrictUserBillableActions ( activePolicy . id )
515- ) {
510+ if ( iouType === CONST . IOU . TYPE . CREATE && isPaidGroupPolicy ( activePolicy ) && activePolicy ?. isPolicyExpenseChatEnabled && ! shouldRestrictUserBillableActions ( activePolicy . id ) ) {
511+ const activePolicyExpenseChat = getPolicyExpenseChat ( currentUserPersonalDetails . accountID , activePolicy ?. id ) ;
512+
513+ // If the initial transaction has different participants selected that means that the user has changed the participant in the confirmation step
514+ if ( initialTransaction ?. participants && initialTransaction ?. participants ?. at ( 0 ) ?. reportID !== activePolicyExpenseChat ?. reportID ) {
515+ const isTrackExpense = initialTransaction ?. participants ?. at ( 0 ) ?. reportID === selfDMReportID ;
516+
517+ const setParticipantsPromises = files . map ( ( receiptFile ) => setMoneyRequestParticipants ( receiptFile . transactionID , initialTransaction ?. participants ) ) ;
518+ Promise . all ( setParticipantsPromises ) . then ( ( ) => {
519+ if ( isTrackExpense ) {
520+ Navigation . navigate ( ROUTES . MONEY_REQUEST_STEP_CONFIRMATION . getRoute ( CONST . IOU . ACTION . CREATE , CONST . IOU . TYPE . TRACK , initialTransactionID , selfDMReportID ) ) ;
521+ } else {
522+ navigateToConfirmationPage ( iouType === CONST . IOU . TYPE . CREATE , initialTransaction ?. reportID ) ;
523+ }
524+ } ) ;
525+ return ;
526+ }
527+
516528 const setParticipantsPromises = files . map ( ( receiptFile ) => setMoneyRequestParticipantsFromReport ( receiptFile . transactionID , activePolicyExpenseChat ) ) ;
517529 Promise . all ( setParticipantsPromises ) . then ( ( ) =>
518530 Navigation . navigate (
@@ -525,12 +537,6 @@ function IOURequestStepScan({
525537 ) ,
526538 ) ;
527539 } else {
528- // If the initial transaction already has the participants selected, then we can skip the participants step and go straight to the confirmation step.
529- if ( initialTransaction ?. participants && initialTransaction ?. participants . length > 0 ) {
530- const setParticipantsPromises = files . map ( ( receiptFile ) => setMoneyRequestParticipants ( receiptFile . transactionID , initialTransaction ?. participants ) ) ;
531- Promise . all ( setParticipantsPromises ) . then ( ( ) => navigateToConfirmationPage ( true , initialTransaction ?. reportID ) ) ;
532- return ;
533- }
534540 navigateToParticipantPage ( iouType , initialTransactionID , reportID ) ;
535541 }
536542 } ,
@@ -554,6 +560,7 @@ function IOURequestStepScan({
554560 transactionTaxCode ,
555561 transactionTaxAmount ,
556562 policy ,
563+ selfDMReportID ,
557564 ] ,
558565 ) ;
559566
0 commit comments