@@ -2,7 +2,7 @@ import {useRoute} from '@react-navigation/native';
22import { delegateEmailSelector , isUserValidatedSelector } from '@selectors/Account' ;
33import { hasSeenTourSelector } from '@selectors/Onboarding' ;
44import truncate from 'lodash/truncate' ;
5- import React , { useContext , useEffect , useRef } from 'react' ;
5+ import React , { useContext } from 'react' ;
66import type { StyleProp , ViewStyle } from 'react-native' ;
77import type { ValueOf } from 'type-fest' ;
88import ButtonWithDropdownMenu from '@components/ButtonWithDropdownMenu' ;
@@ -39,7 +39,7 @@ import useTransactionThreadReport from '@hooks/useTransactionThreadReport';
3939import { search } from '@libs/actions/Search' ;
4040import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID' ;
4141import { getTotalAmountForIOUReportPreviewButton } from '@libs/MoneyRequestReportUtils' ;
42- import type { KYCFlowEvent , TriggerKYCFlow } from '@libs/PaymentUtils' ;
42+ import type { KYCFlowEvent , TriggerKYCFlow , WorkspacePolicyPaymentOption } from '@libs/PaymentUtils' ;
4343import { handleUnvalidatedAccount , selectPaymentType } from '@libs/PaymentUtils' ;
4444import { sortPoliciesByName } from '@libs/PolicyUtils' ;
4545import { hasRequestFromCurrentAccount } from '@libs/ReportActionsUtils' ;
@@ -53,7 +53,6 @@ import CONST from '@src/CONST';
5353import ONYXKEYS from '@src/ONYXKEYS' ;
5454import ROUTES from '@src/ROUTES' ;
5555import type { Route } from '@src/ROUTES' ;
56- import type * as OnyxTypes from '@src/types/onyx' ;
5756import type { PaymentMethodType } from '@src/types/onyx/OriginalMessage' ;
5857
5958const PAYMENT_ICONS = [ 'Send' , 'ThumbsUp' , 'Cash' , 'ArrowRight' , 'Building' ] as const ;
@@ -136,15 +135,6 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
136135
137136 const { showConfirmModal} = useConfirmModal ( ) ;
138137
139- const isSelectionModePaymentRef = useRef ( false ) ;
140-
141- useEffect ( ( ) => {
142- if ( selectedTransactionIDs . length !== 0 ) {
143- return ;
144- }
145- isSelectionModePaymentRef . current = false ;
146- } , [ selectedTransactionIDs . length ] ) ;
147-
148138 const expensifyIcons = useMemoizedLazyExpensifyIcons ( PAYMENT_ICONS ) ;
149139
150140 const { beginExportWithTemplate, showOfflineModal, showDownloadErrorModal} = useExportActions ( {
@@ -229,7 +219,6 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
229219 if ( ! type || ! chatReport ) {
230220 return ;
231221 }
232- isSelectionModePaymentRef . current = true ;
233222
234223 if ( isDelegateAccessRestricted ) {
235224 showDelegateNoAccessModal ( ) ;
@@ -318,25 +307,26 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
318307 ? sortPoliciesByName ( activeAdminPolicies , localeCompare )
319308 : [ ] ;
320309
321- const buildPaymentSubMenuItems = ( onWorkspaceSelected : ( workspacePolicy : OnyxTypes . Policy ) => void ) : PopoverMenuItem [ ] => {
322- if ( ! workspacePolicyOptions . length ) {
323- return Object . values ( paymentButtonOptions ) ;
324- }
325- const result : PopoverMenuItem [ ] = [ ] ;
310+ // Workspace-policy entries carry the policy as data with no onSelected.
311+ // MoneyReportHeaderKYCDropdown picks them up via onSubItemSelected where triggerKYCFlow is in scope
312+ const paymentSubMenuItems : PopoverMenuItem [ ] = [ ] ;
313+ if ( ! workspacePolicyOptions . length ) {
314+ paymentSubMenuItems . push ( ...Object . values ( paymentButtonOptions ) ) ;
315+ } else {
326316 for ( const opt of Object . values ( paymentButtonOptions ) ) {
327- result . push ( opt ) ;
317+ paymentSubMenuItems . push ( opt ) ;
328318 if ( opt . value === CONST . IOU . PAYMENT_TYPE . EXPENSIFY ) {
329319 for ( const wp of workspacePolicyOptions ) {
330- result . push ( {
320+ const workspacePolicyItem : WorkspacePolicyPaymentOption = {
331321 text : translate ( 'iou.payWithPolicy' , truncate ( wp . name , { length : CONST . ADDITIONAL_ALLOWED_CHARACTERS } ) , '' ) ,
332322 icon : expensifyIcons . Building ,
333- onSelected : ( ) => onWorkspaceSelected ( wp ) ,
334- } ) ;
323+ workspacePolicy : wp ,
324+ } ;
325+ paymentSubMenuItems . push ( workspacePolicyItem ) ;
335326 }
336327 }
337328 }
338- return result ;
339- } ;
329+ }
340330
341331 const showDeleteModal = ( ) => {
342332 showConfirmModal ( {
@@ -385,10 +375,7 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
385375 text : translate ( 'iou.approve' ) ,
386376 icon : expensifyIcons . ThumbsUp ,
387377 value : CONST . REPORT . PRIMARY_ACTIONS . APPROVE ,
388- onSelected : ( ) => {
389- isSelectionModePaymentRef . current = true ;
390- confirmApproval ( true ) ;
391- } ,
378+ onSelected : ( ) => confirmApproval ( true ) ,
392379 } ,
393380 ]
394381 : [ ] ) ,
@@ -400,16 +387,7 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
400387 value : CONST . REPORT . PRIMARY_ACTIONS . PAY as string ,
401388 rightIcon : expensifyIcons . ArrowRight ,
402389 backButtonText : translate ( 'iou.settlePayment' , totalAmount ) ,
403- subMenuItems : buildPaymentSubMenuItems ( ( wp ) => {
404- isSelectionModePaymentRef . current = true ;
405- if ( checkForNecessaryAction ( ) ) {
406- return ;
407- }
408- kycWallRef . current ?. continueAction ?.( { policy : wp } ) ;
409- } ) ,
410- onSelected : ( ) => {
411- isSelectionModePaymentRef . current = true ;
412- } ,
390+ subMenuItems : paymentSubMenuItems ,
413391 } ,
414392 ]
415393 : [ ] ) ,
@@ -446,7 +424,6 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
446424 const hasPayInSelectionMode = allExpensesSelected && hasPayAction && hasActualPaymentOptions ;
447425
448426 const onSelectionModePaymentSelect = ( event : KYCFlowEvent , iouPaymentType : PaymentMethodType , triggerKYCFlow : TriggerKYCFlow ) => {
449- isSelectionModePaymentRef . current = true ;
450427 if ( checkForNecessaryAction ( iouPaymentType ) ) {
451428 return ;
452429 }
@@ -473,10 +450,7 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
473450 } ) ;
474451 } ;
475452
476- const selectionModeKYCSuccess = ( type ?: PaymentMethodType ) => {
477- isSelectionModePaymentRef . current = true ;
478- confirmPayment ( { paymentType : type } ) ;
479- } ;
453+ const selectionModeKYCSuccess = ( type ?: PaymentMethodType ) => confirmPayment ( { paymentType : type } ) ;
480454
481455 if ( ! selectedTransactionsOptions . length || transactionThreadReportID ) {
482456 return null ;
@@ -501,6 +475,12 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
501475 chatReportID = { chatReport ?. reportID }
502476 iouReport = { moneyRequestReport }
503477 onPaymentSelect = { onSelectionModePaymentSelect }
478+ onWorkspacePolicySelect = { ( selectedPolicy , triggerKYCFlow ) => {
479+ if ( checkForNecessaryAction ( ) ) {
480+ return ;
481+ }
482+ triggerKYCFlow ( { policy : selectedPolicy } ) ;
483+ } }
504484 onSuccessfulKYC = { selectionModeKYCSuccess }
505485 primaryAction = { primaryAction }
506486 applicableSecondaryActions = { selectedTransactionsOptions }
0 commit comments