From ad8d942e219783fa31b7dd1f17fd2a5689d72cde Mon Sep 17 00:00:00 2001 From: daledah Date: Fri, 28 Mar 2025 15:43:06 +0700 Subject: [PATCH 1/2] fix: call GetAssignedSupportData only on workspace switching --- src/pages/home/HeaderView.tsx | 10 +--------- src/pages/home/sidebar/SidebarLinksData.tsx | 6 +++++- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/pages/home/HeaderView.tsx b/src/pages/home/HeaderView.tsx index f0ac4f3e86e9..975201c584cd 100644 --- a/src/pages/home/HeaderView.tsx +++ b/src/pages/home/HeaderView.tsx @@ -1,5 +1,5 @@ import {useRoute} from '@react-navigation/native'; -import React, {memo, useEffect, useMemo, useState} from 'react'; +import React, {memo, useMemo, useState} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import {useOnyx} from 'react-native-onyx'; @@ -29,7 +29,6 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import {openExternalLink} from '@libs/actions/Link'; import {initializeOpenAIRealtime, stopConnection} from '@libs/actions/OpenAI'; -import {getAssignedSupportData} from '@libs/actions/Policy/Policy'; import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; import Navigation from '@libs/Navigation/Navigation'; import {getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils'; @@ -147,13 +146,6 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked, const policyName = getPolicyName({report, returnEmptyIfNotFound: true}); const policyDescription = getPolicyDescriptionText(policy); const isPersonalExpenseChat = isPolicyExpenseChat && isCurrentUserSubmitter(report?.reportID); - const policyID = report?.policyID; - useEffect(() => { - if (!policyID) { - return; - } - getAssignedSupportData(policyID); - }, [policyID]); const shouldShowSubtitle = () => { if (!subtitle) { diff --git a/src/pages/home/sidebar/SidebarLinksData.tsx b/src/pages/home/sidebar/SidebarLinksData.tsx index 5f049bda3a6f..457dd2db1a19 100644 --- a/src/pages/home/sidebar/SidebarLinksData.tsx +++ b/src/pages/home/sidebar/SidebarLinksData.tsx @@ -5,6 +5,7 @@ import {useOnyx} from 'react-native-onyx'; import type {EdgeInsets} from 'react-native-safe-area-context'; import useActiveWorkspace from '@hooks/useActiveWorkspace'; import useLocalize from '@hooks/useLocalize'; +import usePrevious from '@hooks/usePrevious'; import {useReportIDs} from '@hooks/useReportIDs'; import useThemeStyles from '@hooks/useThemeStyles'; import * as Policy from '@userActions/Policy/Policy'; @@ -27,12 +28,15 @@ function SidebarLinksData({insets}: SidebarLinksDataProps) { const {orderedReportIDs, currentReportID, policyMemberAccountIDs} = useReportIDs(); + const previousActiveWorkspaceID = usePrevious(activeWorkspaceID); + useEffect(() => { - if (!activeWorkspaceID) { + if (!activeWorkspaceID || previousActiveWorkspaceID === activeWorkspaceID) { return; } Policy.openWorkspace(activeWorkspaceID, policyMemberAccountIDs); + Policy.getAssignedSupportData(activeWorkspaceID); // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, [activeWorkspaceID]); From 736baa8995f2c76087f5a95a186372cc8a781173 Mon Sep 17 00:00:00 2001 From: daledah Date: Fri, 28 Mar 2025 15:56:35 +0700 Subject: [PATCH 2/2] fix: lint --- src/pages/home/sidebar/SidebarLinksData.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/home/sidebar/SidebarLinksData.tsx b/src/pages/home/sidebar/SidebarLinksData.tsx index 457dd2db1a19..e47da0e1af9d 100644 --- a/src/pages/home/sidebar/SidebarLinksData.tsx +++ b/src/pages/home/sidebar/SidebarLinksData.tsx @@ -8,7 +8,7 @@ import useLocalize from '@hooks/useLocalize'; import usePrevious from '@hooks/usePrevious'; import {useReportIDs} from '@hooks/useReportIDs'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as Policy from '@userActions/Policy/Policy'; +import {getAssignedSupportData, openWorkspace} from '@libs/actions/Policy/Policy'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import SidebarLinks from './SidebarLinks'; @@ -35,8 +35,8 @@ function SidebarLinksData({insets}: SidebarLinksDataProps) { return; } - Policy.openWorkspace(activeWorkspaceID, policyMemberAccountIDs); - Policy.getAssignedSupportData(activeWorkspaceID); + openWorkspace(activeWorkspaceID, policyMemberAccountIDs); + getAssignedSupportData(activeWorkspaceID); // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, [activeWorkspaceID]);