add link to admin painel on user menu
This commit is contained in:
@@ -12,9 +12,8 @@ import { DashboardRoutePaths, QuestionRoutePaths, SessionRoutePaths } from '../.
|
|||||||
import { turnOff } from '../../services/store/unsavedChanges';
|
import { turnOff } from '../../services/store/unsavedChanges';
|
||||||
import { CurrentUserAvatar } from "../CurrentUserAvatar";
|
import { CurrentUserAvatar } from "../CurrentUserAvatar";
|
||||||
import { localFetch } from '../../utils/localFetch';
|
import { localFetch } from '../../utils/localFetch';
|
||||||
|
import { notEmpty } from '../../utils/notEmpty';
|
||||||
import unifesoLogoCompact from "../../assets/images/logoImgUnifeso.png";
|
import { UserRole } from '../../__generated__/graphql-schema';
|
||||||
import unifesoLogo from "../../assets/images/unifeso-logo-branco.svg";
|
|
||||||
|
|
||||||
const UserMenu: FC = () => {
|
const UserMenu: FC = () => {
|
||||||
const { user } = useCurrentUser();
|
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) },
|
onClick: () => { handleLinkClick(SessionRoutePaths.show) },
|
||||||
label: 'Perfil'
|
label: 'Perfil'
|
||||||
@@ -70,7 +78,7 @@ const UserMenu: FC = () => {
|
|||||||
onClick: handleLogout,
|
onClick: handleLogout,
|
||||||
label: 'Sair'
|
label: 'Sair'
|
||||||
}
|
}
|
||||||
]
|
].filter(notEmpty)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
3
app/javascript/utils/notEmpty.ts
Normal file
3
app/javascript/utils/notEmpty.ts
Normal file
@@ -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 = <T>(value: T | null | undefined): value is T =>
|
||||||
|
value !== null && value !== undefined
|
||||||
Reference in New Issue
Block a user