diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 1a584a4ff296..1cb2f048f9aa 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -1419,15 +1419,15 @@ function isPolicyAccessible(policy: OnyxEntry): boolean { ); } -function areAllGroupPoliciesExpenseChatDisabled(policies = allPolicies) { - const groupPolicies = Object.values(policies ?? {}).filter((policy) => isPaidGroupPolicy(policy)); +function areAllGroupPoliciesExpenseChatDisabled(policies: OnyxCollection | null) { + const groupPolicies = Object.values(policies ?? {}).filter(isPaidGroupPolicy); if (groupPolicies.length === 0) { return false; } return !groupPolicies.some((policy) => !!policy?.isPolicyExpenseChatEnabled); } -function getGroupPaidPoliciesWithExpenseChatEnabled(policies: OnyxCollection | null = allPolicies) { +function getGroupPaidPoliciesWithExpenseChatEnabled(policies: OnyxCollection | null) { if (isEmptyObject(policies)) { return CONST.EMPTY_ARRAY; } diff --git a/src/pages/Search/EmptySearchView.tsx b/src/pages/Search/EmptySearchView.tsx index 1a3084cd99ed..c892b373531b 100644 --- a/src/pages/Search/EmptySearchView.tsx +++ b/src/pages/Search/EmptySearchView.tsx @@ -97,7 +97,7 @@ function EmptySearchView({similarSearchHash, type, hasResults}: EmptySearchViewP const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true}); const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`, {canBeMissing: true}); - const groupPoliciesWithChatEnabled = getGroupPaidPoliciesWithExpenseChatEnabled(); + const groupPoliciesWithChatEnabled = useMemo(() => getGroupPaidPoliciesWithExpenseChatEnabled(allPolicies), [allPolicies]); const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true}); const [hasSeenTour = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, { diff --git a/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx index e401ded3842b..d2e3e122989c 100644 --- a/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx @@ -170,7 +170,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, ref } = useOnboardingTaskInformation(CONST.ONBOARDING_TASK_TYPE.VIEW_TOUR); const isReportInSearch = isOnSearchMoneyRequestReportPage(); - const groupPoliciesWithChatEnabled = getGroupPaidPoliciesWithExpenseChatEnabled(); + const groupPoliciesWithChatEnabled = getGroupPaidPoliciesWithExpenseChatEnabled(allPolicies as OnyxCollection); /** * There are scenarios where users who have not yet had their group workspace-chats in NewDot (isPolicyExpenseChatEnabled). In those scenarios, things can get confusing if they try to submit/track expenses. To address this, we block them from Creating, Tracking, Submitting expenses from NewDot if they are: