@@ -13,6 +13,7 @@ import {useSearchContext} from '@components/Search/SearchContext';
1313import useLocalize from '@hooks/useLocalize' ;
1414import useNetwork from '@hooks/useNetwork' ;
1515import useOnyx from '@hooks/useOnyx' ;
16+ import usePolicy from '@hooks/usePolicy' ;
1617import useThemeStyles from '@hooks/useThemeStyles' ;
1718import { isCurrencySupportedForDirectReimbursement } from '@libs/actions/Policy/Policy' ;
1819import { getCurrentUserAccountID } from '@libs/actions/Report' ;
@@ -110,14 +111,18 @@ function SettlementButton({
110111 const [ fundList = { } ] = useOnyx ( ONYXKEYS . FUND_LIST , { canBeMissing : true } ) ;
111112 const [ policies ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY , { canBeMissing : true } ) ;
112113 const currentUserAccountID = getCurrentUserAccountID ( ) . toString ( ) ;
113- const activeAdminPolicies = getActiveAdminWorkspaces ( ! isOnSearch ? policies : undefined , currentUserAccountID ) . sort ( ( a , b ) => ( a . name || '' ) . localeCompare ( b . name || '' ) ) ;
114+
115+ // Passing `undefined` to ensure we use the Onyx connection from PolicyUtils,
116+ // since `useOnyx` only returns snapshot data on the SearchPage.
117+ // By passing `undefined`, we fall back to the function's default value.
118+ const activeAdminPolicies = getActiveAdminWorkspaces ( undefined , currentUserAccountID ) . sort ( ( a , b ) => ( a . name || '' ) . localeCompare ( b . name || '' ) ) ;
114119 const reportID = iouReport ?. reportID ;
115120
116121 const hasPreferredPaymentMethod = ! ! lastPaymentMethod ;
117122 const isLoadingLastPaymentMethod = isLoadingOnyxValue ( lastPaymentMethodResult ) ;
118123 const policy = policies ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ] ;
119- const isLastPaymentPolicy = ! Object . values ( { ... CONST . PAYMENT_METHODS , ... CONST . IOU . PAYMENT_TYPE } ) . includes ( lastPaymentMethod as PaymentMethod ) ;
120- const lastPaymentPolicy = isLastPaymentPolicy ? policies ?. [ ` ${ ONYXKEYS . COLLECTION . POLICY } ${ lastPaymentMethod } ` ] : undefined ;
124+ const lastPaymentPolicy = usePolicy ( lastPaymentMethod ) ;
125+
121126 const [ bankAccountList = { } ] = useOnyx ( ONYXKEYS . BANK_ACCOUNT_LIST , { canBeMissing : true } ) ;
122127 const bankAccount = bankAccountList [ lastBankAccountID ?? CONST . DEFAULT_NUMBER_ID ] ;
123128 const isExpenseReport = isExpenseReportUtil ( iouReport ) ;
0 commit comments