Their three commits (730d0bd,5a9b543,387edfb) reached production by push and auto-deployed.387edfbexpects a users.username column that the live database does not have, so POST /api/v1/auth/login was returning HTTP 500. Their schema changes never applied either (projects still has only id, name, description, start_date, pm_user_id, created_at), so nothing depends on the reverted code. This commit sets the tree back to exactlya02b3ea— verified with git diff against it — while keeping history linear: the work itself is preserved on 'pm' at387edfb.
50 lines
2.4 KiB
TypeScript
50 lines
2.4 KiB
TypeScript
import { useLocation } from "react-router-dom";
|
|
import { PanelMenu, type MenuItem } from "./PanelMenu";
|
|
import { useLogout } from "../pages/Inventory/panelMenu";
|
|
import { useAuthStore } from "../store/auth";
|
|
|
|
// منوی همبرگری مشترک بین دو ماژول (پنل انبار / دفتر تدارکات) —
|
|
// دقیقاً مثل منوی دفتر: عنوان «پنلها»، ماژول فعلی با استایل فعال (پر)
|
|
// + «✓ فعلی»، ماژول دیگر بهعنوان سوییچر، و در پایان جداکننده + خروج.
|
|
// مدیر پروژه (1:N): زیر «مدیریت انبار» یک آکاردئون باز میشود که همهی
|
|
// پروژههای تخصیصیافته را نشان میدهد؛ پروژهی فعال با «✓ فعلی» مشخص است و
|
|
// انتخاب هر پروژه فقط «پروژهی فعال» را عوض میکند (نشست/توکن دستنخورده).
|
|
export function AppSwitcherMenu({
|
|
activeModule,
|
|
canSwitchToProcurement = true,
|
|
}: {
|
|
activeModule: "warehouse" | "procurement";
|
|
canSwitchToProcurement?: boolean; // مدیر پروژه به دفتر تدارکات دسترسی ندارد
|
|
}) {
|
|
const logout = useLogout();
|
|
const { pathname } = useLocation();
|
|
const user = useAuthStore((s) => s.user);
|
|
const setActiveProject = useAuthStore((s) => s.setActiveProject);
|
|
const items: MenuItem[] = [];
|
|
|
|
const isPm = user?.role === "pm";
|
|
const pmProjects = isPm ? user?.projects ?? [] : [];
|
|
const projectChildren: MenuItem[] | undefined =
|
|
activeModule === "warehouse" && isPm
|
|
? pmProjects.map((p) => ({
|
|
label: p.name,
|
|
to: pathname, // همان بخش فعلی؛ فقط پروژه عوض میشود
|
|
active: p.id === user?.project_id,
|
|
onClick: () => setActiveProject(p.id),
|
|
}))
|
|
: undefined;
|
|
|
|
if (activeModule === "procurement") {
|
|
items.push({ label: "مدیریت انبار", to: "/inventory" });
|
|
items.push({ label: "مدیریت تدارکات", to: "/", active: true });
|
|
} else {
|
|
items.push({ label: "مدیریت انبار", to: "/inventory", active: true, children: projectChildren });
|
|
if (canSwitchToProcurement) {
|
|
items.push({ label: "مدیریت تدارکات", to: "/" });
|
|
}
|
|
}
|
|
items.push({ divider: true });
|
|
items.push({ label: "خروج از حساب", onClick: logout });
|
|
return <PanelMenu title="پنلها" items={items} />;
|
|
}
|