84 lines
3.0 KiB
TypeScript
84 lines
3.0 KiB
TypeScript
import type { ReactNode } from "react";
|
|
import { Link } from "wouter";
|
|
import Container from "@mui/material/Container";
|
|
import Alert from "@mui/material/Alert";
|
|
import Button from "@mui/material/Button";
|
|
import { usePlatform } from "@/lib/platform";
|
|
import "@/pages/workspace.css";
|
|
export function WorkspaceShell({
|
|
title,
|
|
permission,
|
|
children,
|
|
}: {
|
|
title: string;
|
|
permission?: string;
|
|
children: ReactNode;
|
|
}) {
|
|
const { principal, can, scope } = usePlatform();
|
|
return (
|
|
<section className="workspace-page">
|
|
<Container maxWidth="lg">
|
|
<h1>{title}</h1>
|
|
{!principal ? (
|
|
<Alert severity="info">
|
|
Sign in to continue.{" "}
|
|
<Link href="/workspace">
|
|
<u>Account sign-in</u>
|
|
</Link>
|
|
</Alert>
|
|
) : (
|
|
<>
|
|
<WorkspaceNavigation />
|
|
{permission && !can(permission) ? (
|
|
<Alert severity="warning">
|
|
Your account does not have permission to view this page.
|
|
</Alert>
|
|
) : (
|
|
<div key={scope}>{children}</div>
|
|
)}
|
|
</>
|
|
)}
|
|
</Container>
|
|
</section>
|
|
);
|
|
}
|
|
|
|
export function WorkspaceNavigation() {
|
|
const { can } = usePlatform();
|
|
const links = [
|
|
{ label: "My cart", path: "/cart" },
|
|
{ label: "Addresses", path: "/addresses" },
|
|
{ label: "My orders", path: "/orders" },
|
|
{ label: "Access", path: "/admin/access", permission: "users.read" },
|
|
{ label: "Roles", path: "/admin/roles", permission: "roles.read" },
|
|
{ label: "Catalog", path: "/admin/catalog", permission: "catalog.read" },
|
|
{
|
|
label: "Inventory",
|
|
path: "/admin/inventory",
|
|
permission: "inventory.read",
|
|
},
|
|
{ label: "Coupons", path: "/admin/coupons", permission: "coupons.manage" },
|
|
{ label: "Suppliers", path: "/admin/procurement", permission: "procurement.read" },
|
|
{ label: "Supplier documents", path: "/admin/supplier-documents", permission: "supplier_document.read" },
|
|
{ label: "Materials", path: "/admin/procurement/materials", permission: "procurement.read" },
|
|
{ label: "Purchase orders", path: "/admin/purchase-orders", permission: "procurement.read" },
|
|
{ label: "Material stock", path: "/admin/material-stock", permission: "inventory.read" },
|
|
{ label: "Production BOMs", path: "/admin/boms", permission: "bom.read" },
|
|
{ label: "Packaging BOMs", path: "/admin/packaging-boms", permission: "packaging.read" },
|
|
{ label: "Pricing", path: "/admin/pricing", permission: "pricing.manage" },
|
|
{ label: "All orders", path: "/admin/orders", permission: "orders.read" },
|
|
{ label: "Audit", path: "/admin/audit", permission: "audit.read" },
|
|
];
|
|
return (
|
|
<nav className="workspace-links" aria-label="Workspace navigation">
|
|
{links
|
|
.filter((l) => !l.permission || can(l.permission))
|
|
.map((l) => (
|
|
<Button key={l.path} component={Link} href={l.path}>
|
|
{l.label}
|
|
</Button>
|
|
))}
|
|
</nav>
|
|
);
|
|
}
|