Skip to content

Commit

Permalink
fix: only show manage quizzes if admin
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoEscaleira committed Mar 7, 2024
1 parent 6800417 commit 0f8092a
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useState } from "react";
import { useLazyQuery } from "@apollo/client";
import { Drawer, IconButton, List, ListItem, ListItemPrefix, Typography } from "@material-tailwind/react";
import {Menu, Home, Play, FileQuestion, X, CircleUserRound, Power, LibraryBig} from "lucide-react";
import { Menu, Home, Play, FileQuestion, X, CircleUserRound, Power, LibraryBig } from "lucide-react";
import { Link, useLocation } from "react-router-dom";
import { toast } from "react-toastify";
import useBreakpoint from "use-breakpoint";
import { LoginForm } from "@components/Login/LoginForm.tsx";
import { Roles } from "@generated/graphql.ts";
import { useUserStore } from "@state/userStore.ts";
import { BREAKPOINTS } from "@utils/constants.ts";
import { LOGOUT_USER } from "@utils/queries/Logout.ts";
Expand All @@ -17,6 +18,7 @@ export function Header() {
const { breakpoint } = useBreakpoint(BREAKPOINTS);
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
const { user, isLoggedIn, resetUser } = useUserStore();
const isAdmin = user.role === Roles.Admin;

const [makeLogout] = useLazyQuery(LOGOUT_USER);

Expand Down Expand Up @@ -110,14 +112,16 @@ export function Header() {
Profile
</ListItem>
</Link>
<Link to="/quizzes" onClick={toggleDrawer}>
<ListItem>
<ListItemPrefix>
<LibraryBig />
</ListItemPrefix>
Manage Quizzes
</ListItem>
</Link>
{isAdmin && (
<Link to="/quizzes" onClick={toggleDrawer}>
<ListItem>
<ListItemPrefix>
<LibraryBig />
</ListItemPrefix>
Manage Quizzes
</ListItem>
</Link>
)}
<ListItem
onClick={async () => {
await makeLogout();
Expand Down

0 comments on commit 0f8092a

Please sign in to comment.