diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index 6260648c..041aa7a9 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -1,307 +1,206 @@ import clsx from "clsx"; -import { IconType } from "react-icons"; -import { MdSpaceDashboard } from "react-icons/md"; +import {IconType} from "react-icons"; +import {MdSpaceDashboard} from "react-icons/md"; import { - BsFileEarmarkText, - BsClockHistory, - BsPencil, - BsGraphUp, - BsChevronBarRight, - BsChevronBarLeft, - BsShieldFill, - BsCloudFill, - BsCurrencyDollar, - BsClipboardData, + BsFileEarmarkText, + BsClockHistory, + BsPencil, + BsGraphUp, + BsChevronBarRight, + BsChevronBarLeft, + BsShieldFill, + BsCloudFill, + BsCurrencyDollar, + BsClipboardData, } from "react-icons/bs"; -import { RiLogoutBoxFill } from "react-icons/ri"; -import { SlPencil } from "react-icons/sl"; -import { FaAward } from "react-icons/fa"; +import {RiLogoutBoxFill} from "react-icons/ri"; +import {SlPencil} from "react-icons/sl"; +import {FaAward} from "react-icons/fa"; import Link from "next/link"; -import { useRouter } from "next/router"; +import {useRouter} from "next/router"; import axios from "axios"; import FocusLayer from "@/components/FocusLayer"; -import { preventNavigation } from "@/utils/navigation.disabled"; -import { useState } from "react"; +import {preventNavigation} from "@/utils/navigation.disabled"; +import {useEffect, useState} from "react"; import usePreferencesStore from "@/stores/preferencesStore"; -import { Type } from "@/interfaces/user"; -import useTicketsListener from '@/hooks/useTicketsListener'; +import {Type} from "@/interfaces/user"; +import useTicketsListener from "@/hooks/useTicketsListener"; interface Props { - path: string; - navDisabled?: boolean; - focusMode?: boolean; - onFocusLayerMouseEnter?: () => void; - className?: string; - userType?: Type; - userId?: string; + path: string; + navDisabled?: boolean; + focusMode?: boolean; + onFocusLayerMouseEnter?: () => void; + className?: string; + userType?: Type; + userId?: string; } interface NavProps { - Icon: IconType; - label: string; - path: string; - keyPath: string; - disabled?: boolean; - isMinimized?: boolean; - badge?: number; + Icon: IconType; + label: string; + path: string; + keyPath: string; + disabled?: boolean; + isMinimized?: boolean; + badge?: number; } -const Nav = ({ - Icon, - label, - path, - keyPath, - disabled = false, - isMinimized = false, - badge, -}: NavProps) => { - const displayBadge = badge && badge > 0 ? true : false; - return ( - - - {!isMinimized && {label}} - {displayBadge &&
{badge}
} - -); - } +const Nav = ({Icon, label, path, keyPath, disabled = false, isMinimized = false, badge}: NavProps) => { + return ( + + + {!isMinimized && {label}} + {!!badge && badge > 0 && ( +
+ {badge} +
+ )} + + ); +}; -export default function Sidebar({ - path, - navDisabled = false, - focusMode = false, - userType, - onFocusLayerMouseEnter, - className, - userId, -}: Props) { - const router = useRouter(); +export default function Sidebar({path, navDisabled = false, focusMode = false, userType, onFocusLayerMouseEnter, className, userId}: Props) { + const router = useRouter(); - const [isMinimized, toggleMinimize] = usePreferencesStore((state) => [ - state.isSidebarMinimized, - state.toggleSidebarMinimized, - ]); + const [isMinimized, toggleMinimize] = usePreferencesStore((state) => [state.isSidebarMinimized, state.toggleSidebarMinimized]); - const {totalAssignedTickets } = useTicketsListener(userId); + const {totalAssignedTickets} = useTicketsListener(userId); - const logout = async () => { - axios.post("/api/logout").finally(() => { - setTimeout(() => router.reload(), 500); - }); - }; + useEffect(() => console.log(totalAssignedTickets), [totalAssignedTickets]); - const disableNavigation = preventNavigation(navDisabled, focusMode); + const logout = async () => { + axios.post("/api/logout").finally(() => { + setTimeout(() => router.reload(), 500); + }); + }; - return ( -
-
-
-
-
+ const disableNavigation = preventNavigation(navDisabled, focusMode); -
-
- {isMinimized ? ( - - ) : ( - - )} - {!isMinimized && ( - Minimize - )} -
-
{} : logout} - className={clsx( - "hover:text-mti-rose flex cursor-pointer items-center gap-4 rounded-full p-4 text-black transition duration-300 ease-in-out", - isMinimized ? "w-fit" : "w-full min-w-[250px] px-8", - )} - > - - {!isMinimized && ( - Log Out - )} -
-
- {focusMode && ( - - )} -
- ); + return ( +
+
+
+
+
+ +
+
+ {isMinimized ? : } + {!isMinimized && Minimize} +
+
{} : logout} + className={clsx( + "hover:text-mti-rose flex cursor-pointer items-center gap-4 rounded-full p-4 text-black transition duration-300 ease-in-out", + isMinimized ? "w-fit" : "w-full min-w-[250px] px-8", + )}> + + {!isMinimized && Log Out} +
+
+ {focusMode && } +
+ ); }