@@ -70,6 +70,7 @@ import {isTrackingSelector} from '@src/selectors/GPSDraftDetails';
7070import type * as OnyxTypes from '@src/types/onyx' ;
7171import type { QuickActionName } from '@src/types/onyx/QuickAction' ;
7272import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
73+ import getEmptyArray from '@src/types/utils/getEmptyArray' ;
7374
7475type PolicySelector = Pick < OnyxTypes . Policy , 'type' | 'role' | 'isPolicyExpenseChatEnabled' | 'pendingAction' | 'avatarURL' | 'name' | 'id' | 'areInvoicesEnabled' > ;
7576
@@ -138,18 +139,30 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, ref
138139 const [ quickAction ] = useOnyx ( ONYXKEYS . NVP_QUICK_ACTION_GLOBAL_CREATE , { canBeMissing : true } ) ;
139140 const [ quickActionReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ quickAction ?. chatReportID } ` , { canBeMissing : true } ) ;
140141 const [ activePolicyID ] = useOnyx ( ONYXKEYS . NVP_ACTIVE_POLICY_ID , { canBeMissing : true } ) ;
141- const [ allReports ] = useOnyx ( ONYXKEYS . COLLECTION . REPORT , { canBeMissing : true } ) ;
142142 const [ allTransactionDrafts ] = useOnyx ( ONYXKEYS . COLLECTION . TRANSACTION_DRAFT , { canBeMissing : true } ) ;
143143 const [ activePolicy ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY } ${ activePolicyID } ` , { canBeMissing : true } ) ;
144144 const [ transactionViolations ] = useOnyx ( ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS , { canBeMissing : true } ) ;
145145 const { isRestrictedToPreferredPolicy, isRestrictedPolicyCreation} = usePreferredPolicy ( ) ;
146+
147+ const workspaceChatsSelector = useCallback (
148+ ( reports : OnyxCollection < OnyxTypes . Report > ) => {
149+ return getWorkspaceChats ( activePolicyID , [ session ?. accountID ?? CONST . DEFAULT_NUMBER_ID ] , reports ) ;
150+ } ,
151+ [ activePolicyID , session ?. accountID ] ,
152+ ) ;
153+
154+ const [ policyChatsForActivePolicy = getEmptyArray < OnyxTypes . Report > ( ) ] = useOnyx ( ONYXKEYS . COLLECTION . REPORT , { canBeMissing : true , selector : workspaceChatsSelector } , [
155+ activePolicyID ,
156+ session ?. accountID ,
157+ ] ) ;
158+
146159 const policyChatForActivePolicy = useMemo ( ( ) => {
147160 if ( isEmptyObject ( activePolicy ) || ! activePolicy ?. isPolicyExpenseChatEnabled ) {
148161 return { } as OnyxTypes . Report ;
149162 }
150- const policyChatsForActivePolicy = getWorkspaceChats ( activePolicyID , [ session ?. accountID ?? CONST . DEFAULT_NUMBER_ID ] , allReports ) ;
151163 return policyChatsForActivePolicy . length > 0 ? policyChatsForActivePolicy . at ( 0 ) : ( { } as OnyxTypes . Report ) ;
152- } , [ activePolicy , activePolicyID , session ?. accountID , allReports ] ) ;
164+ } , [ activePolicy , policyChatsForActivePolicy ] ) ;
165+
153166 const quickActionPolicyID = quickAction ?. action === CONST . QUICK_ACTIONS . TRACK_PER_DIEM && quickAction ?. perDiemPolicyID ? quickAction ?. perDiemPolicyID : quickActionReport ?. policyID ;
154167 const [ quickActionPolicy ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY } ${ quickActionPolicyID } ` , { canBeMissing : true } ) ;
155168 const [ allPolicies ] = useMappedPolicies ( policyMapper ) ;
0 commit comments