import styles, { colors } from "../../styles"; import AccountCircleIcon from "@mui/icons-material/AccountCircle"; import HomeIcon from "@mui/icons-material/Home"; import LogoutIcon from "@mui/icons-material/Logout"; import { useQuery } from "@tanstack/react-query"; import { ClearanceAPI, UserAPI, setAccessToken, setRefreshToken, } from "../API/API"; import DrawerButton from "../DrawerButton/DrawerButton"; import { useDispatch } from "react-redux"; import { auth_toggle } from "../Plugins/Redux/Slices/AuthSlice/AuthSlice"; import { toast } from "react-toastify"; import { useNavigate } from "react-router-dom"; export default function Drawer() { const user = useQuery({ queryKey: ["user"], queryFn: UserAPI }); const clearance = useQuery({ enabled: user.isFetched && !user?.data?.is_teacher && !user?.data?.is_technician, queryKey: ["clearance"], queryFn: ClearanceAPI, }); const dispatch = useDispatch(); const navigate = useNavigate(); return (

{user.data ? user.data.username : user.isError ? "Error loading user" : "Loading user..."}

{user.data && user.data.is_technician ? "Technician" : user.data && user.data.is_teacher ? "Teacher" : "Student"}

{user.isFetched && user.data && !user.data.is_teacher && !user?.data?.is_technician ? ( <>

Status:

{clearance.data?.cleared}

{`(${clearance.data?.uncleared_transactions} pending)`}

) : ( <> )}
{ navigate("/dashboard"); }} icon={ } label={"Dashboard"} /> { navigate("/"); await dispatch(auth_toggle()); await setAccessToken(""); await setRefreshToken(""); toast("Logged out", { position: "top-right", autoClose: 2000, hideProgressBar: false, closeOnClick: true, pauseOnHover: true, draggable: true, progress: undefined, theme: "light", }); }} icon={ } label={"Log out"} />
); }