Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upcoming: [M3-7475] - Add Switch Account button to Account Landing page #10052

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

Add Switch Account button to Account Landing page for parent and proxy users ([#10052](https://github.com/linode/manager/pull/10052))
22 changes: 14 additions & 8 deletions packages/manager/src/components/LandingHeader/LandingHeader.tsx
mjac0bs marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ export const LandingHeader = ({
? analyticsLabel
: `${title} Landing`;

const sxButton = {
marginLeft: theme.spacing(1),
};

return (
<Grid
alignItems="center"
Expand All @@ -91,7 +87,17 @@ export const LandingHeader = ({
</Grid>
{!shouldHideDocsAndCreateButtons && (
<Grid>
<Grid alignItems="center" container justifyContent="flex-end">
<Grid
sx={{
flex: '1 1 auto',
marginLeft: xsDown ? theme.spacing(1) : undefined,
}}
alignItems="center"
display="flex"
flexWrap={xsDown ? 'wrap' : 'nowrap'}
gap={3}
justifyContent="flex-end"
>
{betaFeedbackLink && (
<span
style={{
Expand Down Expand Up @@ -124,7 +130,6 @@ export const LandingHeader = ({
loading={loading}
onClick={onButtonClick}
onKeyPress={onButtonKeyPress}
sx={sxButton}
{...buttonDataAttrs}
>
{createButtonText ?? `Create ${entity}`}
Expand All @@ -139,6 +144,7 @@ export const LandingHeader = ({
);
};

const Actions = styled('div')(({ theme }) => ({
marginLeft: `${theme.spacing(2)}`,
const Actions = styled('div')(() => ({
display: 'flex',
mjac0bs marked this conversation as resolved.
Show resolved Hide resolved
justifyContent: 'flex-end',
}));
22 changes: 21 additions & 1 deletion packages/manager/src/features/Account/AccountLanding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ({
Expand Down Expand Up @@ -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<boolean>(false);

const accountAccessGrant = grants?.global?.account_access;
const readOnlyAccountAccess = accountAccessGrant === 'read_only';
Expand Down Expand Up @@ -107,6 +116,9 @@ const AccountLanding = () => {
let idx = 0;

const isBillingTabSelected = location.pathname.match(/billing/);
const isAccountSwitchable =
mjac0bs marked this conversation as resolved.
Show resolved Hide resolved
flags.parentChildAccountAccess &&
(user?.user_type === 'parent' || user?.user_type === 'proxy');

const landingHeaderProps: LandingHeaderProps = {
breadcrumbProps: {
Expand All @@ -125,6 +137,9 @@ const AccountLanding = () => {
history.replace('/account/billing/make-payment');
}
landingHeaderProps.disabledCreateButton = readOnlyAccountAccess;
landingHeaderProps.extraActions = isAccountSwitchable ? (
<SwitchAccountButton onClick={() => setIsDrawerOpen(true)} />
) : undefined;
}

return (
Expand Down Expand Up @@ -158,6 +173,11 @@ const AccountLanding = () => {
</TabPanels>
</React.Suspense>
</Tabs>
<SwitchAccountDrawer
onClose={() => setIsDrawerOpen(false)}
open={isDrawerOpen}
username={user?.username ?? ''}
/>
</React.Fragment>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ describe('SwitchAccountDrawer', () => {

it('should display a list of child accounts', async () => {
server.use(
rest.get('*/account/users/*', (req, res, ctx) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small fix here - noticed that I hadn't mocked this request and so if the mock endpoint were to change in user_type in serverHandlers.ts, this test would fail.

return res(ctx.json(accountUserFactory.build({ user_type: 'parent' })));
}),
rest.get('*/account/child-accounts', (req, res, ctx) => {
return res(
ctx.json(
Expand Down