Skip to content

Commit

Permalink
Review updates for enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
jaalah committed Feb 12, 2024
1 parent 8d08a40 commit 3e8efc4
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions packages/manager/src/queries/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResourcePage<Account>, 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,
}
);
Expand All @@ -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<ResourcePage<Account>, APIError[]>(
[queryKey, 'childAccounts', 'paginated', params, filter],
Expand All @@ -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;
Expand All @@ -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<Account, APIError[]>(
[queryKey, 'childAccounts', 'childAccount', euuid],
() => getChildAccount({ euuid }),
{
enabled:
(Boolean(profile?.user_type === 'parent') && !profile?.restricted) ||
Boolean(grants?.global?.child_account_access) ||
hasExplicitAuthToken,
enabled,
}
);
};
Expand Down

0 comments on commit 3e8efc4

Please sign in to comment.