@@ -3,7 +3,7 @@ import {shouldFailAllRequestsSelector} from '@selectors/Network';
33import { hasSeenTourSelector } from '@selectors/Onboarding' ;
44import { validTransactionDraftsSelector } from '@selectors/TransactionDraft' ;
55import type { ReactNode } from 'react' ;
6- import React , { useCallback , useMemo , useState } from 'react' ;
6+ import React , { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
77import { View } from 'react-native' ;
88import type { OnyxEntry } from 'react-native-onyx' ;
99import type { ValueOf } from 'type-fest' ;
@@ -77,7 +77,7 @@ import type IconAsset from '@src/types/utils/IconAsset';
7777import BrokenConnectionDescription from './BrokenConnectionDescription' ;
7878import Button from './Button' ;
7979import ButtonWithDropdownMenu from './ButtonWithDropdownMenu' ;
80- import type { DropdownOption } from './ButtonWithDropdownMenu/types' ;
80+ import type { ButtonWithDropdownMenuRef , DropdownOption } from './ButtonWithDropdownMenu/types' ;
8181import DecisionModal from './DecisionModal' ;
8282import { useDelegateNoAccessActions , useDelegateNoAccessState } from './DelegateNoAccessModalProvider' ;
8383import HeaderLoadingBar from './HeaderLoadingBar' ;
@@ -149,6 +149,8 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
149149 typeof CONST . REPORT . TRANSACTION_SECONDARY_ACTIONS . HOLD | typeof CONST . REPORT . TRANSACTION_SECONDARY_ACTIONS . REJECT
150150 > | null > ( null ) ;
151151 const [ isDuplicateActive , temporarilyDisableDuplicateAction ] = useThrottledButtonState ( ) ;
152+ const dropdownMenuRef = useRef < ButtonWithDropdownMenuRef > ( null ) ;
153+
152154 const [ dismissedRejectUseExplanation ] = useOnyx ( ONYXKEYS . NVP_DISMISSED_REJECT_USE_EXPLANATION ) ;
153155 const [ dismissedHoldUseExplanation ] = useOnyx ( ONYXKEYS . NVP_DISMISSED_HOLD_USE_EXPLANATION ) ;
154156 const personalDetails = usePersonalDetails ( ) ;
@@ -208,6 +210,15 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
208210 ( isParentReportArchived || ( activePolicyExpenseChat && ( isSelfDM ( parentReport ) || isParentChatReportDM ) ) )
209211 ) ;
210212
213+ const shouldDuplicateCloseModalOnSelect = isDistanceExpenseUnsupportedForDuplicating || hasCustomUnitOutOfPolicyViolation || isPerDiemRequestOnNonDefaultWorkspace ;
214+
215+ useEffect ( ( ) => {
216+ if ( ! isDuplicateActive || shouldDuplicateCloseModalOnSelect ) {
217+ return ;
218+ }
219+ dropdownMenuRef . current ?. setIsMenuVisible ( false ) ;
220+ } , [ isDuplicateActive , shouldDuplicateCloseModalOnSelect ] ) ;
221+
211222 const { wideRHPRouteKeys} = useWideRHPState ( ) ;
212223 const [ shouldFailAllRequests ] = useOnyx ( ONYXKEYS . NETWORK , { selector : shouldFailAllRequestsSelector } ) ;
213224 const [ quickAction ] = useOnyx ( ONYXKEYS . NVP_QUICK_ACTION_GLOBAL_CREATE ) ;
@@ -549,7 +560,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
549560
550561 duplicateTransaction ( [ transaction ] ) ;
551562 } ,
552- shouldCloseModalOnSelect : isDistanceExpenseUnsupportedForDuplicating || hasCustomUnitOutOfPolicyViolation || isPerDiemRequestOnNonDefaultWorkspace ,
563+ shouldCloseModalOnSelect : shouldDuplicateCloseModalOnSelect ,
553564 } ,
554565 [ CONST . REPORT . TRANSACTION_SECONDARY_ACTIONS . VIEW_DETAILS ] : {
555566 value : CONST . REPORT . SECONDARY_ACTIONS . VIEW_DETAILS ,
@@ -660,6 +671,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
660671 { ! ! primaryAction && primaryActionImplementation [ primaryAction ] }
661672 { ! ! applicableSecondaryActions . length && (
662673 < ButtonWithDropdownMenu
674+ ref = { dropdownMenuRef }
663675 success = { false }
664676 onPress = { ( ) => { } }
665677 shouldAlwaysShowDropdownMenu
@@ -682,6 +694,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
682694 { ! ! primaryAction && < View style = { [ styles . flexGrow4 ] } > { primaryActionImplementation [ primaryAction ] } </ View > }
683695 { ! ! applicableSecondaryActions . length && (
684696 < ButtonWithDropdownMenu
697+ ref = { dropdownMenuRef }
685698 success = { false }
686699 onPress = { ( ) => { } }
687700 shouldAlwaysShowDropdownMenu
0 commit comments