From aa11f8aa6a1d1a42c7a45a90439677b887a2fe50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Geonizeli?= Date: Thu, 28 Jul 2022 08:26:27 -0300 Subject: [PATCH] add link to admin painel on user menu --- app/javascript/components/Appbar/Appbar.tsx | 18 +++++++++++++----- app/javascript/utils/notEmpty.ts | 3 +++ 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 app/javascript/utils/notEmpty.ts diff --git a/app/javascript/components/Appbar/Appbar.tsx b/app/javascript/components/Appbar/Appbar.tsx index 995c03a..526022b 100644 --- a/app/javascript/components/Appbar/Appbar.tsx +++ b/app/javascript/components/Appbar/Appbar.tsx @@ -12,9 +12,8 @@ import { DashboardRoutePaths, QuestionRoutePaths, SessionRoutePaths } from '../. import { turnOff } from '../../services/store/unsavedChanges'; import { CurrentUserAvatar } from "../CurrentUserAvatar"; import { localFetch } from '../../utils/localFetch'; - -import unifesoLogoCompact from "../../assets/images/logoImgUnifeso.png"; -import unifesoLogo from "../../assets/images/unifeso-logo-branco.svg"; +import { notEmpty } from '../../utils/notEmpty'; +import { UserRole } from '../../__generated__/graphql-schema'; const UserMenu: FC = () => { const { user } = useCurrentUser(); @@ -61,7 +60,16 @@ const UserMenu: FC = () => { } } - const menuItems = [ + type MenuItem = { + onClick: Function + label: string + } + + const menuItems: MenuItem[] = [ + (user?.roles.includes(UserRole.Admin) && { + onClick: () => { window.location.href = '/admin'}, + label: 'Painel de Administração' + }), { onClick: () => { handleLinkClick(SessionRoutePaths.show) }, label: 'Perfil' @@ -70,7 +78,7 @@ const UserMenu: FC = () => { onClick: handleLogout, label: 'Sair' } - ] + ].filter(notEmpty) return ( <> diff --git a/app/javascript/utils/notEmpty.ts b/app/javascript/utils/notEmpty.ts new file mode 100644 index 0000000..1f46108 --- /dev/null +++ b/app/javascript/utils/notEmpty.ts @@ -0,0 +1,3 @@ +// Use a type predicate function to avoid opting out of strict type checking: https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates +export const notEmpty = (value: T | null | undefined): value is T => + value !== null && value !== undefined