@@ -12,6 +12,7 @@ import {LockedAccountContext} from '@components/LockedAccountModalProvider';
1212import useLocalize from '@hooks/useLocalize' ;
1313import useNetwork from '@hooks/useNetwork' ;
1414import useOnyx from '@hooks/useOnyx' ;
15+ import usePolicy from '@hooks/usePolicy' ;
1516import useThemeStyles from '@hooks/useThemeStyles' ;
1617import { isCurrencySupportedForDirectReimbursement } from '@libs/actions/Policy/Policy' ;
1718import { getCurrentUserAccountID } from '@libs/actions/Report' ;
@@ -88,6 +89,7 @@ function SettlementButton({
8889 const styles = useThemeStyles ( ) ;
8990 const { translate} = useLocalize ( ) ;
9091 const { isOffline} = useNetwork ( ) ;
92+
9193 // The app would crash due to subscribing to the entire report collection if chatReportID is an empty string. So we should have a fallback ID here.
9294 // eslint-disable-next-line rulesdir/no-default-id-values
9395 const [ chatReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReportID || CONST . DEFAULT_NUMBER_ID } ` , { canBeMissing : true } ) ;
@@ -107,14 +109,18 @@ function SettlementButton({
107109 const [ fundList = { } ] = useOnyx ( ONYXKEYS . FUND_LIST , { canBeMissing : true } ) ;
108110 const [ policies ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY , { canBeMissing : true } ) ;
109111 const currentUserAccountID = getCurrentUserAccountID ( ) . toString ( ) ;
110- const activeAdminPolicies = getActiveAdminWorkspaces ( policies , currentUserAccountID ) . sort ( ( a , b ) => ( a . name || '' ) . localeCompare ( b . name || '' ) ) ;
112+
113+ // Passing `undefined` to ensure we use the Onyx connection from PolicyUtils,
114+ // since `useOnyx` only returns snapshot data on the SearchPage.
115+ // By passing `undefined`, we fall back to the function's default value.
116+ const activeAdminPolicies = getActiveAdminWorkspaces ( undefined , currentUserAccountID ) . sort ( ( a , b ) => ( a . name || '' ) . localeCompare ( b . name || '' ) ) ;
111117 const reportID = iouReport ?. reportID ;
112118
113119 const hasPreferredPaymentMethod = ! ! lastPaymentMethod ;
114120 const isLoadingLastPaymentMethod = isLoadingOnyxValue ( lastPaymentMethodResult ) ;
115121 const policy = policies ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ] ;
116- const isLastPaymentPolicy = ! Object . values ( { ... CONST . PAYMENT_METHODS , ... CONST . IOU . PAYMENT_TYPE } ) . includes ( lastPaymentMethod as PaymentMethod ) ;
117- const lastPaymentPolicy = isLastPaymentPolicy ? policies ?. [ ` ${ ONYXKEYS . COLLECTION . POLICY } ${ lastPaymentMethod } ` ] : undefined ;
122+ const lastPaymentPolicy = usePolicy ( lastPaymentMethod ) ;
123+
118124 const [ bankAccountList = { } ] = useOnyx ( ONYXKEYS . BANK_ACCOUNT_LIST , { canBeMissing : true } ) ;
119125 const bankAccount = bankAccountList [ lastBankAccountID ?? CONST . DEFAULT_NUMBER_ID ] ;
120126 const isExpenseReport = isExpenseReportUtil ( iouReport ) ;
0 commit comments