feat(frontend): added in checks for links inside the module

This commit is contained in:
2025-03-06 19:34:10 -06:00
parent 4195b9e8bc
commit c30a48c4b8
4 changed files with 126 additions and 23 deletions

View File

@@ -7,35 +7,45 @@ import {
SidebarMenuButton,
SidebarMenuItem,
} from "../../ui/sidebar";
import {hasPageAccess} from "@/utils/userAccess";
import {User} from "@/types/users";
// this will need to be moved to a links section the db to make it more easy to remove and add
const items = [
{
title: "Silo Adjustments",
url: "#",
icon: Cylinder,
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
module: "logistics",
active: true,
},
{
title: "Bulk orders",
url: "#",
icon: Truck,
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
module: "logistics",
active: true,
},
{
title: "Forecast",
url: "#",
icon: Truck,
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
module: "logistics",
active: true,
},
{
title: "Ocme cycle counts",
url: "#",
icon: Package,
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
module: "logistics",
active: false,
},
];
export function LogisticsSideBar() {
export function LogisticsSideBar({user, moduleID}: {user: User | null; moduleID: string}) {
return (
<SidebarGroup>
<SidebarGroupLabel>Logistics</SidebarGroupLabel>
@@ -43,12 +53,16 @@ export function LogisticsSideBar() {
<SidebarMenu>
{items.map((item) => (
<SidebarMenuItem key={item.title}>
<SidebarMenuButton asChild>
<a href={item.url}>
<item.icon />
<span>{item.title}</span>
</a>
</SidebarMenuButton>
<>
{hasPageAccess(user, item.role, moduleID) && item.active && (
<SidebarMenuButton asChild>
<a href={item.url}>
<item.icon />
<span>{item.title}</span>
</a>
</SidebarMenuButton>
)}
</>
</SidebarMenuItem>
))}
</SidebarMenu>