From 47a6fed046a9e1600d0073bb780d7dad09030172 Mon Sep 17 00:00:00 2001 From: brooke Date: Tue, 6 Aug 2024 11:50:22 -0400 Subject: [PATCH] make UX improvements --- src/auth/logout.tsx | 8 ++--- src/components/global/Search/Search.tsx | 6 +++- .../global/SideNavigation/SideNavigation.tsx | 9 +++-- src/components/global/UserMenu.tsx | 35 +++++++++++++++---- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/auth/logout.tsx b/src/auth/logout.tsx index d5c7250a..f404d0ea 100644 --- a/src/auth/logout.tsx +++ b/src/auth/logout.tsx @@ -1,8 +1,8 @@ -"use server"; +'use server'; -import { signOut } from "@/auth/auth"; +import { signOut } from '@/auth/auth'; export async function logout() { - "use server"; - await signOut({ redirectTo: "/" }); + 'use server'; + await signOut({ redirect: true, redirectTo: '/' }); } diff --git a/src/components/global/Search/Search.tsx b/src/components/global/Search/Search.tsx index c69ba069..bf3f7fe5 100644 --- a/src/components/global/Search/Search.tsx +++ b/src/components/global/Search/Search.tsx @@ -4,6 +4,8 @@ import Fuse, { IFuseOptions } from 'fuse.js'; import debounce from 'lodash/debounce'; // @ts-expect-error import LockIcon from '@leafygreen-ui/icon/dist/Lock'; +// @ts-expect-error +import UnlockIcon from '@leafygreen-ui/icon/dist/Unlock'; import { SearchInput, SearchResult } from '@leafygreen-ui/search-input'; import { useSession } from '@/hooks'; import { components } from '@/utils/components'; @@ -52,6 +54,8 @@ export function Search() { } }, [searchTerm]); + const PrivateIcon = session?.user ? UnlockIcon : LockIcon; + return (
{item.name} - {item.isPrivate && !session?.user && } + {item.isPrivate && }
))} diff --git a/src/components/global/SideNavigation/SideNavigation.tsx b/src/components/global/SideNavigation/SideNavigation.tsx index 61507a80..af81cfa3 100644 --- a/src/components/global/SideNavigation/SideNavigation.tsx +++ b/src/components/global/SideNavigation/SideNavigation.tsx @@ -14,6 +14,8 @@ import AppsIcon from '@leafygreen-ui/icon/dist/Apps'; import LockIcon from '@leafygreen-ui/icon/dist/Lock'; // @ts-expect-error import MenuIcon from '@leafygreen-ui/icon/dist/Menu'; +// @ts-expect-error +import UnlockIcon from '@leafygreen-ui/icon/dist/Unlock'; import IconButton from '@leafygreen-ui/icon-button'; import { PortalContextProvider, @@ -22,7 +24,7 @@ import { import { MongoDBLogo, SupportedColors } from '@leafygreen-ui/logo'; import { color, spacing } from '@leafygreen-ui/tokens'; import { SIDE_NAV_WIDTH } from '@/constants'; -import { useMediaQuery } from '@/hooks'; +import { useMediaQuery, useSession } from '@/hooks'; import { ComponentMeta, Group, groupedComponents } from '@/utils/components'; import { Search } from '../Search/Search'; import { Drawer } from './Drawer'; @@ -31,6 +33,7 @@ import { SideNavLabel } from './SideNavLabel'; import { SideNavList } from './SideNavList'; export function SideNavigation() { + const session = useSession(); const navRef = useRef(null); const [open, setOpen] = React.useState(false); const [isMobile] = useMediaQuery(['(max-width: 640px)'], { @@ -42,6 +45,8 @@ export function SideNavigation() { topLevelPage === 'component' ? activeSubDirOrPage : ''; const { darkMode, theme } = useDarkMode(); + const PrivateIcon = session?.user ? UnlockIcon : LockIcon; + const navContent = ( <> {component.name} {component.isPrivate && ( - ( + undefined, + ); + + useEffect(() => { + if (session?.user) { + setManualSession(session); + } + + if (!session?.user) { + setManualSession(undefined); + } + }, [session]); - return session?.user ? ( + return manualSession?.user ? (
} > - {session.user.name} + {manualSession.user.name} } > - {session.user.name} - {session.user.email} + {manualSession.user.name} + {manualSession.user.email} - } onClick={() => logout()}> + } + onClick={() => { + logout(); + setManualSession(undefined); + }} + > Log out