From 3e8efc4d35a181dfb912510a261c1bf7b71efe9a Mon Sep 17 00:00:00 2001 From: Jaalah Ramos Date: Mon, 12 Feb 2024 14:35:17 -0500 Subject: [PATCH] Review updates for enabled --- packages/manager/src/queries/account.ts | 27 ++++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/manager/src/queries/account.ts b/packages/manager/src/queries/account.ts index ee68f5bed29..82e1a3e2f4a 100644 --- a/packages/manager/src/queries/account.ts +++ b/packages/manager/src/queries/account.ts @@ -60,15 +60,16 @@ export const useChildAccounts = ({ const { data: profile } = useProfile(); const { data: grants } = useGrants(); const hasExplicitAuthToken = Boolean(headers?.Authorization); + const enabled = + (Boolean(profile?.user_type === 'parent') && !profile?.restricted) || + Boolean(grants?.global?.child_account_access) || + hasExplicitAuthToken; return useQuery, APIError[]>( [queryKey, 'childAccounts', 'paginated', params, filter], () => getChildAccounts({ filter, headers, params }), { - enabled: - (Boolean(profile?.user_type === 'parent') && !profile?.restricted) || - Boolean(grants?.global?.child_account_access) || - hasExplicitAuthToken, + enabled, keepPreviousData: true, } ); @@ -82,6 +83,10 @@ export const useChildAccountsInfiniteQuery = ({ const { data: profile } = useProfile(); const { data: grants } = useGrants(); const hasExplicitAuthToken = Boolean(headers?.Authorization); + const enabled = + (Boolean(profile?.user_type === 'parent') && !profile?.restricted) || + Boolean(grants?.global?.child_account_access) || + hasExplicitAuthToken; return useInfiniteQuery, APIError[]>( [queryKey, 'childAccounts', 'paginated', params, filter], @@ -95,10 +100,7 @@ export const useChildAccountsInfiniteQuery = ({ }, }), { - enabled: - (Boolean(profile?.user_type === 'parent') && !profile?.restricted) || - Boolean(grants?.global?.child_account_access) || - hasExplicitAuthToken, + enabled, getNextPageParam: ({ page, pages }) => { if (page === pages) { return undefined; @@ -114,15 +116,16 @@ export const useChildAccount = ({ euuid, headers }: ChildAccountPayload) => { const { data: profile } = useProfile(); const { data: grants } = useGrants(); const hasExplicitAuthToken = Boolean(headers?.Authorization); + const enabled = + (Boolean(profile?.user_type === 'parent') && !profile?.restricted) || + Boolean(grants?.global?.child_account_access) || + hasExplicitAuthToken; return useQuery( [queryKey, 'childAccounts', 'childAccount', euuid], () => getChildAccount({ euuid }), { - enabled: - (Boolean(profile?.user_type === 'parent') && !profile?.restricted) || - Boolean(grants?.global?.child_account_access) || - hasExplicitAuthToken, + enabled, } ); };