diff --git a/packages/manager/cypress/e2e/core/parentChild/account-switching.spec.ts b/packages/manager/cypress/e2e/core/parentChild/account-switching.spec.ts index 3d88c570b0d..768cd7071c4 100644 --- a/packages/manager/cypress/e2e/core/parentChild/account-switching.spec.ts +++ b/packages/manager/cypress/e2e/core/parentChild/account-switching.spec.ts @@ -22,6 +22,7 @@ import { mockGetUser, } from 'support/intercepts/account'; import { mockGetEvents, mockGetNotifications } from 'support/intercepts/events'; +import { mockAppendFeatureFlags } from 'support/intercepts/feature-flags'; import { mockAllApiRequests } from 'support/intercepts/general'; import { mockGetRolePermissionsError, @@ -151,6 +152,10 @@ const mockAlternateChildAccountToken = appTokenFactory.build({ const mockErrorMessage = 'An unknown error has occurred.'; describe('Parent/Child account switching', () => { + beforeEach(() => { + // Disable IAM delegation to use legacy child accounts flow for all tests + mockAppendFeatureFlags({ iamDelegation: false }); + }); /* * Tests to confirm that Parent account users can switch to Child accounts as expected. */ diff --git a/packages/manager/src/features/Account/SwitchAccountButton.tsx b/packages/manager/src/features/Account/SwitchAccountButton.tsx index ef6ce0568ef..c1f4a07f1b5 100644 --- a/packages/manager/src/features/Account/SwitchAccountButton.tsx +++ b/packages/manager/src/features/Account/SwitchAccountButton.tsx @@ -19,10 +19,15 @@ export const SwitchAccountButton = (props: ButtonProps) => { }, font: theme.tokens.alias.Typography.Label.Semibold.S, marginTop: theme.tokens.spacing.S4, + ...(isDelegateUserType && { + '&.MuiButton-root': { + textTransform: 'none', + }, + }), })} {...props} > - {isDelegateUserType ? 'Switch back to your account' : 'Switch Account'} + {isDelegateUserType ? 'Switch Back to Your Account' : 'Switch Account'} ); }; diff --git a/packages/manager/src/features/Account/SwitchAccountDrawer.tsx b/packages/manager/src/features/Account/SwitchAccountDrawer.tsx index 37ef1d6dbd4..1699e2aa5e2 100644 --- a/packages/manager/src/features/Account/SwitchAccountDrawer.tsx +++ b/packages/manager/src/features/Account/SwitchAccountDrawer.tsx @@ -159,12 +159,18 @@ export const SwitchAccountDrawer = (props: Props) => { userType: isIAMDelegationEnabled ? 'delegate' : 'proxy', }); onClose(event); - location.replace('/linodes'); + + // Only redirect to /linodes for IAM delegate users + if (isIAMDelegationEnabled) { + location.replace('/linodes'); + } else { + location.reload(); + } } catch { // Error is handled by createTokenError. } }, - [createToken, isProxyUserType, updateCurrentToken, revokeToken] + [createToken, updateCurrentToken, revokeToken, isIAMDelegationEnabled] ); const [isSwitchingChildAccounts, setIsSwitchingChildAccounts] = @@ -243,7 +249,7 @@ export const SwitchAccountDrawer = (props: Props) => { . - {hasError && ( + {hasError ? ( Unable to load data. @@ -260,8 +266,7 @@ export const SwitchAccountDrawer = (props: Props) => { Try again - )} - {!hasError && ( + ) : ( <> { No search results )} + + {isIAMDelegationEnabled && ( + + )} + {!isIAMDelegationEnabled && ( + + )} )} - {isIAMDelegationEnabled && ( - - )} - {!isIAMDelegationEnabled && ( - - )} ); }; diff --git a/packages/manager/src/features/Account/SwitchAccounts/useSwitchToParentAccount.ts b/packages/manager/src/features/Account/SwitchAccounts/useSwitchToParentAccount.ts index f9ea6ec5efb..94a98755342 100644 --- a/packages/manager/src/features/Account/SwitchAccounts/useSwitchToParentAccount.ts +++ b/packages/manager/src/features/Account/SwitchAccounts/useSwitchToParentAccount.ts @@ -55,7 +55,13 @@ export const useSwitchToParentAccount = ({ } onClose?.(); - location.reload(); + + // For switch back to parent, always redirect to /linodes for delegate users + if (isDelegateUserType) { + location.replace('/linodes'); + } else { + location.reload(); + } } catch (error) { setSubmitting(false); throw error; diff --git a/packages/manager/src/features/TopMenu/UserMenu/UserMenu.tsx b/packages/manager/src/features/TopMenu/UserMenu/UserMenu.tsx index 0b712bc1248..9cae73e0e82 100644 --- a/packages/manager/src/features/TopMenu/UserMenu/UserMenu.tsx +++ b/packages/manager/src/features/TopMenu/UserMenu/UserMenu.tsx @@ -83,9 +83,10 @@ export const UserMenu = React.memo(() => { setStorage('is_delegate_user_type', 'true'); } - enqueueSnackbar(`Account switched to ${companyNameOrEmail}.`, { - variant: 'success', - }); + const message = companyNameOrEmail + ? `Account switched to ${companyNameOrEmail}.` + : 'Account switched.'; + enqueueSnackbar(message, { variant: 'success' }); } }, [ isProxyOrDelegateUserType, diff --git a/packages/manager/src/features/TopMenu/UserMenu/UserMenuPopover.tsx b/packages/manager/src/features/TopMenu/UserMenu/UserMenuPopover.tsx index 4c159f880f0..d5b6997d94e 100644 --- a/packages/manager/src/features/TopMenu/UserMenu/UserMenuPopover.tsx +++ b/packages/manager/src/features/TopMenu/UserMenu/UserMenuPopover.tsx @@ -236,8 +236,11 @@ export const UserMenuPopover = (props: UserMenuPopoverProps) => { gap={(theme) => theme.tokens.spacing.S16} minWidth={250} > - theme.tokens.spacing.S8}> - {canSwitchBetweenParentOrProxyAccount && ( + (companyNameOrEmail ? theme.tokens.spacing.S8 : 0)} + > + {canSwitchBetweenParentOrProxyAccount && companyNameOrEmail && ( ({ color: theme.tokens.alias.Content.Text.Primary.Default, @@ -254,8 +257,8 @@ export const UserMenuPopover = (props: UserMenuPopoverProps) => { overflowWrap: 'break-word', })} > - {canSwitchBetweenParentOrProxyAccount && companyNameOrEmail - ? companyNameOrEmail + {canSwitchBetweenParentOrProxyAccount + ? companyNameOrEmail || null : userName} {canSwitchBetweenParentOrProxyAccount && (