refactor(modules): moved modules to app to control everything based on there active setting
This commit is contained in:
@@ -12,7 +12,7 @@ import {
|
||||
userAccess,
|
||||
useUserRoles,
|
||||
} from "../../../../../lib/authClient";
|
||||
import { useModuleStore } from "../../-lib/store/useModuleStore";
|
||||
|
||||
import { AdminSideBar } from "./side-components/admin";
|
||||
import { EomSideBar } from "./side-components/eom";
|
||||
import { ForkliftSideBar } from "./side-components/forklift";
|
||||
@@ -24,20 +24,13 @@ import { QualitySideBar } from "./side-components/quality";
|
||||
export function AppSidebar() {
|
||||
const { session } = useAuth();
|
||||
const { userRoles } = useUserRoles();
|
||||
const { modules } = useModuleStore();
|
||||
|
||||
return (
|
||||
<Sidebar collapsible="icon">
|
||||
<SidebarContent>
|
||||
<Header />
|
||||
|
||||
<ProductionSideBar
|
||||
user={session?.user as any}
|
||||
moduleID={
|
||||
modules.filter((n) => n.name === "production")[0]
|
||||
?.module_id as string
|
||||
}
|
||||
/>
|
||||
<ProductionSideBar user={session?.user as any} userRoles={userRoles} />
|
||||
|
||||
{/* userAccess("logistics", ["systemAdmin", "admin","manager","viewer"]) */}
|
||||
<LogisticsSideBar user={session?.user as any} userRoles={userRoles} />
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
import { Barcode, Command, Cylinder, Package, Truck } from "lucide-react";
|
||||
import {
|
||||
Barcode,
|
||||
Cat,
|
||||
Command,
|
||||
Cylinder,
|
||||
Database,
|
||||
Package,
|
||||
Truck,
|
||||
} from "lucide-react";
|
||||
|
||||
import type { UserRoles } from "@/lib/authClient";
|
||||
import {
|
||||
SidebarGroup,
|
||||
@@ -8,7 +17,7 @@ import {
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
} from "../../../../../../components/ui/sidebar";
|
||||
import { useSubModuleStore } from "../../../-lib/store/useSubModuleStore";
|
||||
import { useModuleStore } from "../../../-lib/store/useModuleStore";
|
||||
import type { User } from "../../../-types/users";
|
||||
import { hasPageAccess } from "../../../-utils/userAccess";
|
||||
|
||||
@@ -18,6 +27,8 @@ const iconMap: any = {
|
||||
Cylinder: Cylinder,
|
||||
Barcode: Barcode,
|
||||
Command: Command,
|
||||
Cat: Cat,
|
||||
Database: Database,
|
||||
};
|
||||
|
||||
export function LogisticsSideBar({
|
||||
@@ -27,9 +38,9 @@ export function LogisticsSideBar({
|
||||
user: User | null;
|
||||
userRoles: UserRoles[] | null;
|
||||
}) {
|
||||
const { subModules } = useSubModuleStore();
|
||||
const { modules } = useModuleStore();
|
||||
|
||||
const items = subModules?.filter((m) => m.moduleName === "logistics");
|
||||
const items = modules?.filter((m) => m.category === "logistics");
|
||||
const userUpdate = { ...user, roles: userRoles };
|
||||
|
||||
return (
|
||||
@@ -38,9 +49,10 @@ export function LogisticsSideBar({
|
||||
<SidebarGroupContent>
|
||||
<SidebarMenu>
|
||||
{items.map((item) => {
|
||||
const Icon = iconMap[item.icon];
|
||||
const Icon = iconMap[item.icon === "" ? "Cat" : item.icon];
|
||||
if (!item.active) return;
|
||||
return (
|
||||
<SidebarMenuItem key={item.submodule_id}>
|
||||
<SidebarMenuItem key={item.module_id}>
|
||||
{hasPageAccess(userUpdate as any, item.roles, item.name) && (
|
||||
<>
|
||||
<SidebarMenuButton asChild>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Printer, Tag } from "lucide-react";
|
||||
import { Cat, Printer, Tag } from "lucide-react";
|
||||
import type { UserRoles } from "@/lib/authClient";
|
||||
import {
|
||||
SidebarGroup,
|
||||
SidebarGroupContent,
|
||||
@@ -7,54 +8,53 @@ import {
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
} from "../../../../../../components/ui/sidebar";
|
||||
import { useModuleStore } from "../../../-lib/store/useModuleStore";
|
||||
import type { User } from "../../../-types/users";
|
||||
import { hasPageAccess } from "../../../-utils/userAccess";
|
||||
|
||||
const iconMap: any = {
|
||||
Printer: Printer,
|
||||
Tag: Tag,
|
||||
|
||||
Cat: Cat,
|
||||
};
|
||||
|
||||
export function ProductionSideBar({
|
||||
user,
|
||||
moduleID,
|
||||
userRoles,
|
||||
}: {
|
||||
user: User | null;
|
||||
moduleID: string;
|
||||
userRoles: UserRoles[] | null;
|
||||
}) {
|
||||
const url: string = window.location.host.split(":")[0];
|
||||
const items = [
|
||||
{
|
||||
title: "One Click Print",
|
||||
url: "/lst/app/old/ocp",
|
||||
icon: Printer,
|
||||
role: ["viewer"],
|
||||
module: "ocp",
|
||||
active: true,
|
||||
},
|
||||
{
|
||||
title: "Rfid Readers",
|
||||
url: "/lst/app/old/rfid",
|
||||
icon: Tag,
|
||||
role: ["viewer"],
|
||||
module: "production",
|
||||
active: url === "usday1vms006" || url === "localhost" ? true : false,
|
||||
},
|
||||
];
|
||||
//const url: string = window.location.host.split(":")[0];
|
||||
const { modules } = useModuleStore();
|
||||
|
||||
const items = modules?.filter((m) => m.category === "production");
|
||||
const userUpdate = { ...user, roles: userRoles };
|
||||
|
||||
return (
|
||||
<SidebarGroup>
|
||||
<SidebarGroupLabel>Production</SidebarGroupLabel>
|
||||
<SidebarGroupContent>
|
||||
<SidebarMenu>
|
||||
{items.map((item) => (
|
||||
<SidebarMenuItem key={item.title}>
|
||||
<>
|
||||
{hasPageAccess(user, item.role, moduleID) && item.active && (
|
||||
<SidebarMenuButton asChild>
|
||||
<a href={item.url}>
|
||||
<item.icon />
|
||||
<span>{item.title}</span>
|
||||
</a>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</>
|
||||
</SidebarMenuItem>
|
||||
))}
|
||||
{items.map((item) => {
|
||||
if (!item.active) return;
|
||||
const Icon = iconMap[item.icon === "" ? "Cat" : item.icon];
|
||||
return (
|
||||
<SidebarMenuItem key={item.module_id}>
|
||||
<>
|
||||
{hasPageAccess(userUpdate as any, item.roles, item.name) && (
|
||||
<SidebarMenuButton asChild>
|
||||
<a href={item.link}>
|
||||
<Icon />
|
||||
<span>{item.name}</span>
|
||||
</a>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</>
|
||||
</SidebarMenuItem>
|
||||
);
|
||||
})}
|
||||
</SidebarMenu>
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
|
||||
@@ -77,6 +77,7 @@ export default function Lots() {
|
||||
"technician",
|
||||
"admin",
|
||||
"manager",
|
||||
"supervisor",
|
||||
]);
|
||||
|
||||
if (session?.user && accessRoles) {
|
||||
|
||||
Reference in New Issue
Block a user