From afbac1ecdc5f767cc941da65fc93c02852afa9ff Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Mon, 27 Oct 2025 21:12:30 +0530 Subject: [PATCH 1/2] Refactored getGroupPaidPoliciesWithExpenseChatEnabled --- src/libs/PolicyUtils.ts | 4 ++-- src/pages/Search/EmptySearchView.tsx | 2 +- src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 1a584a4ff296..d5ed28c0736f 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -1419,7 +1419,7 @@ function isPolicyAccessible(policy: OnyxEntry): boolean { ); } -function areAllGroupPoliciesExpenseChatDisabled(policies = allPolicies) { +function areAllGroupPoliciesExpenseChatDisabled(policies: OnyxCollection | null) { const groupPolicies = Object.values(policies ?? {}).filter((policy) => isPaidGroupPolicy(policy)); if (groupPolicies.length === 0) { return false; @@ -1427,7 +1427,7 @@ function areAllGroupPoliciesExpenseChatDisabled(policies = allPolicies) { 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..6b9d25b7671c 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 = getGroupPaidPoliciesWithExpenseChatEnabled(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: From 1d5ddc62ff0cf939246e3c4222fcf73cdf7511f4 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Wed, 29 Oct 2025 18:02:38 +0530 Subject: [PATCH 2/2] Addressed comments --- src/libs/PolicyUtils.ts | 2 +- src/pages/Search/EmptySearchView.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index d5ed28c0736f..1cb2f048f9aa 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -1420,7 +1420,7 @@ function isPolicyAccessible(policy: OnyxEntry): boolean { } function areAllGroupPoliciesExpenseChatDisabled(policies: OnyxCollection | null) { - const groupPolicies = Object.values(policies ?? {}).filter((policy) => isPaidGroupPolicy(policy)); + const groupPolicies = Object.values(policies ?? {}).filter(isPaidGroupPolicy); if (groupPolicies.length === 0) { return false; } diff --git a/src/pages/Search/EmptySearchView.tsx b/src/pages/Search/EmptySearchView.tsx index 6b9d25b7671c..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(allPolicies); + const groupPoliciesWithChatEnabled = useMemo(() => getGroupPaidPoliciesWithExpenseChatEnabled(allPolicies), [allPolicies]); const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true}); const [hasSeenTour = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {