feat: conditionally hide admin-only nav items for moderator role
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { usePathname } from "next/navigation"
|
import { usePathname } from "next/navigation"
|
||||||
|
import { useSession } from "@/lib/auth-client"
|
||||||
import {
|
import {
|
||||||
UsersIcon,
|
UsersIcon,
|
||||||
CpuIcon,
|
CpuIcon,
|
||||||
@@ -17,7 +18,7 @@ import {
|
|||||||
type NavItem =
|
type NavItem =
|
||||||
| { type: "section"; label: string }
|
| { type: "section"; label: string }
|
||||||
| { type: "divider" }
|
| { type: "divider" }
|
||||||
| { type: "link"; href: string; label: string; icon: React.ElementType }
|
| { type: "link"; href: string; label: string; icon: React.ElementType; adminOnly?: boolean }
|
||||||
|
|
||||||
const navItems: NavItem[] = [
|
const navItems: NavItem[] = [
|
||||||
{ type: "section", label: "Overview" },
|
{ type: "section", label: "Overview" },
|
||||||
@@ -29,7 +30,7 @@ const navItems: NavItem[] = [
|
|||||||
},
|
},
|
||||||
{ type: "divider" },
|
{ type: "divider" },
|
||||||
{ type: "section", label: "Management" },
|
{ type: "section", label: "Management" },
|
||||||
{ type: "link", href: "/manage/users", label: "Users", icon: UsersIcon },
|
{ type: "link", href: "/manage/users", label: "Users", icon: UsersIcon, adminOnly: true },
|
||||||
{
|
{
|
||||||
type: "link",
|
type: "link",
|
||||||
href: "/manage/hardware",
|
href: "/manage/hardware",
|
||||||
@@ -41,6 +42,7 @@ const navItems: NavItem[] = [
|
|||||||
href: "/manage/storage",
|
href: "/manage/storage",
|
||||||
label: "Storage",
|
label: "Storage",
|
||||||
icon: HardDriveIcon,
|
icon: HardDriveIcon,
|
||||||
|
adminOnly: true,
|
||||||
},
|
},
|
||||||
{ type: "link", href: "/manage/games", label: "Games", icon: Gamepad2Icon },
|
{ type: "link", href: "/manage/games", label: "Games", icon: Gamepad2Icon },
|
||||||
{ type: "divider" },
|
{ type: "divider" },
|
||||||
@@ -68,6 +70,9 @@ const navItems: NavItem[] = [
|
|||||||
|
|
||||||
export function ManageSidebar() {
|
export function ManageSidebar() {
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
|
const { data: session } = useSession()
|
||||||
|
const role = session?.user?.role ?? "user"
|
||||||
|
const isAdmin = role === "admin"
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<nav className='md:w-56 shrink-0'>
|
<nav className='md:w-56 shrink-0'>
|
||||||
@@ -78,6 +83,9 @@ export function ManageSidebar() {
|
|||||||
|
|
||||||
<div className='flex md:flex-col gap-1 overflow-x-auto md:overflow-visible pb-2 md:pb-0 md:border-r md:border-border md:pr-3'>
|
<div className='flex md:flex-col gap-1 overflow-x-auto md:overflow-visible pb-2 md:pb-0 md:border-r md:border-border md:pr-3'>
|
||||||
{navItems.map((item, index) => {
|
{navItems.map((item, index) => {
|
||||||
|
// Hide admin-only items for non-admins
|
||||||
|
if (item.type === "link" && item.adminOnly && !isAdmin) return null
|
||||||
|
|
||||||
if (item.type === "section") {
|
if (item.type === "section") {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|||||||
Reference in New Issue
Block a user