From 2db3d1405bbea20dfcdfde2c137cbd613090d5e4 Mon Sep 17 00:00:00 2001 From: Meier Lukas Date: Sat, 29 Jul 2023 21:15:55 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Implement=20account=20button=20for?= =?UTF-8?q?=20new=20header?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Modals/AboutModal/AboutModal.tsx | 2 +- .../layout/new-header/AvatarMenu.tsx | 82 +++++++++++++++++++ src/components/layout/new-header/Header.tsx | 18 +--- 3 files changed, 85 insertions(+), 17 deletions(-) create mode 100644 src/components/layout/new-header/AvatarMenu.tsx diff --git a/src/components/Dashboard/Modals/AboutModal/AboutModal.tsx b/src/components/Dashboard/Modals/AboutModal/AboutModal.tsx index bc3ae16a0..c8f22cd33 100644 --- a/src/components/Dashboard/Modals/AboutModal/AboutModal.tsx +++ b/src/components/Dashboard/Modals/AboutModal/AboutModal.tsx @@ -206,7 +206,7 @@ const useInformationTableItems = (newVersionAvailable?: string): InformationTabl let items: InformationTableItem[] = []; - if (i18n !== null) { + if (i18n?.reportNamespaces) { const usedI18nNamespaces = i18n.reportNamespaces.getUsedNamespaces(); const initOptions = i18n.options as ExtendedInitOptions; diff --git a/src/components/layout/new-header/AvatarMenu.tsx b/src/components/layout/new-header/AvatarMenu.tsx new file mode 100644 index 000000000..83c9377a8 --- /dev/null +++ b/src/components/layout/new-header/AvatarMenu.tsx @@ -0,0 +1,82 @@ +import { Avatar, Badge, Menu, UnstyledButton, useMantineTheme } from '@mantine/core'; +import { useDisclosure } from '@mantine/hooks'; +import { + IconDashboard, + IconInfoCircle, + IconLogin, + IconLogout, + IconSun, + IconUserSearch, +} from '@tabler/icons-react'; +import { User } from 'next-auth'; +import { signOut, useSession } from 'next-auth/react'; +import Link from 'next/link'; +import { forwardRef } from 'react'; +import { AboutModal } from '~/components/Dashboard/Modals/AboutModal/AboutModal'; + +export const AvatarMenu = () => { + const newVersionAvailable = '0.13.0'; + const [aboutModalOpened, aboutModal] = useDisclosure(false); + const { data: sessionData } = useSession(); + + return ( + <> + + + + + + + }>Switch theme + }>View Profile + }>Default Dashboard + + } + rightSection={ + newVersionAvailable && ( + + New + + ) + } + onClick={() => aboutModal.open()} + > + About + + {sessionData?.user ? ( + } color="red" onClick={() => signOut()}> + Logout + + ) : ( + } component={Link} href="/auth/login"> + Login + + )} + + + + + + + ); +}; + +type CurrentUserAvatarProps = { + user: User | null; +}; +const CurrentUserAvatar = forwardRef( + ({ user, ...others }, ref) => { + const { primaryColor } = useMantineTheme(); + if (!user) return ; + return ( + + {user.name?.slice(0, 2).toUpperCase()} + + ); + } +); diff --git a/src/components/layout/new-header/Header.tsx b/src/components/layout/new-header/Header.tsx index 5ac92e1fc..eb0796ee2 100644 --- a/src/components/layout/new-header/Header.tsx +++ b/src/components/layout/new-header/Header.tsx @@ -21,6 +21,7 @@ import { signOut } from 'next-auth/react'; import Link from 'next/link'; import { Logo } from '../Logo'; +import { AvatarMenu } from './AvatarMenu'; import { Search } from './search'; type MainHeaderProps = { @@ -41,22 +42,7 @@ export const MainHeader = ({ showExperimental = false, logoHref = '/' }: MainHea - - - - - - - }>Switch theme - }>View Profile - }>Default Dashboard - - } color="red" onClick={() => signOut()}> - Logout - - - - +