From 2901606b08de668df7b39b5146f3fcc771e46bfe Mon Sep 17 00:00:00 2001 From: Jonathan Summers-Muir Date: Mon, 4 Mar 2024 14:43:41 +0800 Subject: [PATCH] feat/ add log out button, and user details into user popover (#21724) * Update NavigationBar.tsx * small nits * only show email if it's different from username * Update apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx Co-authored-by: Jonathan Summers-Muir --------- Co-authored-by: Alaister Young Co-authored-by: Alaister Young --- .../layouts/AccountLayout/AccountLayout.tsx | 2 +- .../layouts/AccountLayout/WithSidebar.tsx | 2 +- .../NavigationBar/NavigationBar.tsx | 100 ++++++++++++------ 3 files changed, 72 insertions(+), 32 deletions(-) diff --git a/apps/studio/components/layouts/AccountLayout/AccountLayout.tsx b/apps/studio/components/layouts/AccountLayout/AccountLayout.tsx index eb8c4f24e1b..ecbef0713e5 100644 --- a/apps/studio/components/layouts/AccountLayout/AccountLayout.tsx +++ b/apps/studio/components/layouts/AccountLayout/AccountLayout.tsx @@ -130,7 +130,7 @@ const AccountLayout = ({ children, title, breadcrumbs }: PropsWithChildren } - if (label === 'Logout') { + if (label === 'Log out') { icon = } diff --git a/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx b/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx index 0b5f7fd8edd..3d0da5bbfdd 100644 --- a/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx +++ b/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx @@ -17,7 +17,6 @@ import { DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, - DropdownMenuSub, DropdownMenuTrigger, Separator, Theme, @@ -40,6 +39,7 @@ import { } from './NavigationBar.utils' import { NavigationIconButton } from './NavigationIconButton' import NavigationIconLink from './NavigationIconLink' +import { useSignOut } from 'lib/auth' export const ICON_SIZE = 20 export const ICON_STROKE_WIDTH = 1.5 @@ -54,6 +54,8 @@ const NavigationBar = () => { const { setIsOpen } = useCommandMenu() const snap = useAppStateSnapshot() + const signOut = useSignOut() + const navLayoutV2 = useFlag('navigationLayoutV2') const isNewAPIDocsEnabled = useIsAPIDocsSidePanelEnabled() const [userDropdownOpen, setUserDropdownOpenState] = useState(false) @@ -229,18 +231,24 @@ const NavigationBar = () => { 'transition-all' )} > - - {profile?.username} - - - {profile?.primary_email} - + {profile && IS_PLATFORM && ( + <> + + {profile.username} + + {profile.primary_email !== profile.username && ( + + {profile.primary_email} + + )} + + )} @@ -248,27 +256,48 @@ const NavigationBar = () => { {IS_PLATFORM && ( <> - {} - - - -

Account preferences

- -
- snap.setShowFeaturePreviewModal(true)} - onSelect={() => snap.setShowFeaturePreviewModal(true)} - > - -

Feature previews

-
+
+ {profile && ( + <> + + {profile.username} + + {profile.primary_email !== profile.username && ( + + {profile.primary_email} + + )} + + )} +
+ + + + + Account preferences + + + snap.setShowFeaturePreviewModal(true)} + onSelect={() => snap.setShowFeaturePreviewModal(true)} + > + + Feature previews + + + )} - Theme + Theme { @@ -286,6 +315,17 @@ const NavigationBar = () => { ))} + + + { + await signOut() + await router.push('/sign-in') + }} + > + Log out + +