From 9288741461bd48a305c29598703895b94fa2df63 Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Mon, 8 Jan 2024 16:52:08 -0800 Subject: [PATCH] Add Switch Account button to Account Landing page --- .../src/features/Account/AccountLanding.tsx | 22 ++++++++++++++++++- .../features/Account/SwitchAccountDrawer.tsx | 6 ++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/manager/src/features/Account/AccountLanding.tsx b/packages/manager/src/features/Account/AccountLanding.tsx index bb0543690e9..e6070382aaa 100644 --- a/packages/manager/src/features/Account/AccountLanding.tsx +++ b/packages/manager/src/features/Account/AccountLanding.tsx @@ -11,10 +11,14 @@ import { SafeTabPanel } from 'src/components/Tabs/SafeTabPanel'; import { TabLinkList } from 'src/components/Tabs/TabLinkList'; import { TabPanels } from 'src/components/Tabs/TabPanels'; import { Tabs } from 'src/components/Tabs/Tabs'; +import { useFlags } from 'src/hooks/useFlags'; import { useAccount } from 'src/queries/account'; -import { useGrants } from 'src/queries/profile'; +import { useAccountUser } from 'src/queries/accountUsers'; +import { useGrants, useProfile } from 'src/queries/profile'; import AccountLogins from './AccountLogins'; +import { SwitchAccountButton } from './SwitchAccountButton'; +import { SwitchAccountDrawer } from './SwitchAccountDrawer'; const Billing = React.lazy(() => import('src/features/Billing/BillingDetail').then((module) => ({ @@ -43,6 +47,11 @@ const AccountLanding = () => { const location = useLocation(); const { data: account } = useAccount(); const { data: grants } = useGrants(); + const { data: profile } = useProfile(); + const { data: user } = useAccountUser(profile?.username ?? ''); + + const flags = useFlags(); + const [isDrawerOpen, setIsDrawerOpen] = React.useState(false); const accountAccessGrant = grants?.global?.account_access; const readOnlyAccountAccess = accountAccessGrant === 'read_only'; @@ -107,6 +116,9 @@ const AccountLanding = () => { let idx = 0; const isBillingTabSelected = location.pathname.match(/billing/); + const isAccountSwitchable = + flags.parentChildAccountAccess && + (user?.user_type === 'parent' || user?.user_type === 'child'); const landingHeaderProps: LandingHeaderProps = { breadcrumbProps: { @@ -125,6 +137,9 @@ const AccountLanding = () => { history.replace('/account/billing/make-payment'); } landingHeaderProps.disabledCreateButton = readOnlyAccountAccess; + landingHeaderProps.extraActions = isAccountSwitchable ? ( + setIsDrawerOpen(true)} /> + ) : undefined; } return ( @@ -158,6 +173,11 @@ const AccountLanding = () => { + setIsDrawerOpen(false)} + open={isDrawerOpen} + username={user?.username ?? ''} + /> ); }; diff --git a/packages/manager/src/features/Account/SwitchAccountDrawer.tsx b/packages/manager/src/features/Account/SwitchAccountDrawer.tsx index 830391bd0a4..6875e2bb871 100644 --- a/packages/manager/src/features/Account/SwitchAccountDrawer.tsx +++ b/packages/manager/src/features/Account/SwitchAccountDrawer.tsx @@ -10,7 +10,6 @@ import { Stack } from 'src/components/Stack'; import { useFlags } from 'src/hooks/useFlags'; import { useChildAccounts } from 'src/queries/account'; import { useAccountUser } from 'src/queries/accountUsers'; -import { useProfile } from 'src/queries/profile'; import { authentication } from 'src/utilities/storage'; interface Props { @@ -20,7 +19,7 @@ interface Props { } export const SwitchAccountDrawer = (props: Props) => { - const { onClose, open } = props; + const { onClose, open, username } = props; const flags = useFlags(); @@ -28,8 +27,7 @@ export const SwitchAccountDrawer = (props: Props) => { onClose(); }; - const { data: profile } = useProfile(); - const { data: user } = useAccountUser(profile?.username ?? ''); + const { data: user } = useAccountUser(username ?? ''); // From proxy accounts, make a request on behalf of the parent account to fetch child accounts. const headers =