mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
60 lines
2.5 KiB
TypeScript
60 lines
2.5 KiB
TypeScript
'use client'
|
|
import { HTMLAttributes } from "react"
|
|
import Link from "next/link"
|
|
|
|
import { cn } from "@/lib/utils"
|
|
import { usePathname } from "next/navigation"
|
|
import { useSession } from "next-auth/react"
|
|
|
|
export function MainNav({ className, ...props }: HTMLAttributes<HTMLElement>) {
|
|
const pathname = usePathname()
|
|
const { data: session } = useSession()
|
|
|
|
const getMenuActiveStyle = (path: string) => {
|
|
if (pathname?.startsWith(path) && (pathname !== '' && pathname !== '/') && (path !== '' && path !== '/')) {
|
|
return 'font-semibold text-primary border-b-[3px] border-his'
|
|
} else {
|
|
if (path === pathname) {
|
|
return 'font-semibold text-primary border-b-[3px] border-his'
|
|
}
|
|
}
|
|
return 'text-muted-foreground'
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<nav className={cn("hidden md:flex items-center space-x-4 lg:space-x-6 h-16", className)} {...props}>
|
|
<Link
|
|
href="/" prefetch
|
|
className={`text-sm font-medium transition-colors hover:text-his hover:border-b-[3px] border-his pt-6 pb-5 ${getMenuActiveStyle('/')}`}
|
|
>
|
|
<i className="ti ti-layers-linked text-base mr-0.5"></i>
|
|
Overview
|
|
</Link>
|
|
<Link
|
|
href="/history" prefetch
|
|
className={`text-sm font-medium transition-colors hover:text-his hover:border-b-[3px] border-his pt-6 pb-5 ${getMenuActiveStyle('/history')}`}
|
|
>
|
|
<i className="ti ti-history-toggle text-base mr-0.5"></i>
|
|
History
|
|
</Link>
|
|
<Link
|
|
href="/task" prefetch
|
|
className={`text-sm font-medium transition-colors hover:text-his hover:border-b-[3px] border-his pt-6 pb-5 ${getMenuActiveStyle('/task')}`}
|
|
>
|
|
<i className="ti ti-checklist text-base mr-0.5"></i>
|
|
My Task
|
|
</Link>
|
|
{session?.user.detail.role.allow_admin_panel &&
|
|
<Link
|
|
href="/admin" prefetch title="Go to Admin Panel"
|
|
className={`text-sm font-medium transition-colors hover:text-his hover:border-b-[3px] border-his pt-6 pb-5 ${getMenuActiveStyle('/admin')}`}
|
|
>
|
|
<i className="ti ti-spy text-base mr-0.5"></i>
|
|
Admin Panel
|
|
</Link>
|
|
}
|
|
</nav>
|
|
</>
|
|
)
|
|
} |