74 lines
2.1 KiB
TypeScript
74 lines
2.1 KiB
TypeScript
|
|
import { PanelMenu, type MenuItem } from "./PanelMenu";
|
|
import { useLogout } from "../pages/Inventory/panelMenu";
|
|
import { useAuthStore } from "../store/auth";
|
|
|
|
// منوی همبرگری مشترک بین ۴ پنل اصلی سامانه:
|
|
// ۱. مدیریت انبار (/inventory)
|
|
// ۲. مدیریت تدارکات (/)
|
|
// ۳. مدیریت پروژه (/panel/pm)
|
|
// ۴. سازماندهی (/organization)
|
|
export function AppSwitcherMenu({
|
|
activeModule,
|
|
canSwitchToProcurement = true,
|
|
}: {
|
|
activeModule: "warehouse" | "procurement" | "organization";
|
|
canSwitchToProcurement?: boolean;
|
|
}) {
|
|
const logout = useLogout();
|
|
const user = useAuthStore((s) => s.user);
|
|
const isSupervisor = user?.role === "supervisor";
|
|
|
|
// سرپرست پروژه: منحصراً دو پنل «انبار» و «مدیریت پروژه» نمایش داده میشود
|
|
if (isSupervisor) {
|
|
const supervisorItems: MenuItem[] = [
|
|
{
|
|
label: "انبار",
|
|
to: "/inventory",
|
|
active: activeModule === "warehouse",
|
|
},
|
|
{
|
|
label: "مدیریت پروژه",
|
|
to: "/panel/pm",
|
|
},
|
|
{ divider: true },
|
|
{ label: "خروج از حساب", onClick: logout },
|
|
];
|
|
return <PanelMenu title="پنلها" items={supervisorItems} />;
|
|
}
|
|
|
|
const canManage = user?.role === "admin" || user?.role === "procurement_manager" || user?.role === "pm";
|
|
const items: MenuItem[] = [
|
|
{
|
|
label: "انبار",
|
|
to: "/inventory",
|
|
active: activeModule === "warehouse",
|
|
},
|
|
];
|
|
|
|
if (canSwitchToProcurement) {
|
|
items.push({
|
|
label: "تدارکات",
|
|
to: "/",
|
|
active: activeModule === "procurement",
|
|
});
|
|
}
|
|
|
|
items.push({
|
|
label: "مدیریت پروژه",
|
|
to: "/panel/pm",
|
|
});
|
|
|
|
if (canManage) {
|
|
items.push({
|
|
label: "سازماندهی",
|
|
to: "/organization",
|
|
active: activeModule === "organization",
|
|
});
|
|
}
|
|
|
|
items.push({ divider: true });
|
|
items.push({ label: "خروج از حساب", onClick: logout });
|
|
return <PanelMenu title="پنلها" items={items} />;
|
|
}
|