192 lines
6.2 KiB
TypeScript
192 lines
6.2 KiB
TypeScript
import { Link, usePage } from '@inertiajs/react';
|
|
import {
|
|
Building2,
|
|
ClipboardList,
|
|
LayoutGrid,
|
|
Users,
|
|
Scale,
|
|
ShieldAlert,
|
|
FileCheck2,
|
|
PackageCheck,
|
|
Warehouse,
|
|
} from 'lucide-react';
|
|
import AppLogo from '@/components/app-logo';
|
|
import { NavMain } from '@/components/nav-main';
|
|
import { NavUser } from '@/components/nav-user';
|
|
import {
|
|
Sidebar,
|
|
SidebarContent,
|
|
SidebarFooter,
|
|
SidebarHeader,
|
|
SidebarMenu,
|
|
SidebarMenuButton,
|
|
SidebarMenuItem,
|
|
} from '@/components/ui/sidebar';
|
|
import { dashboard } from '@/routes';
|
|
import type { NavItem } from '@/types';
|
|
|
|
const generalNavItems: NavItem[] = [
|
|
{
|
|
title: 'Visão geral',
|
|
href: dashboard(),
|
|
icon: LayoutGrid,
|
|
},
|
|
{ title: 'Conflitos de interesses', href: '/conflitos', icon: ShieldAlert },
|
|
];
|
|
|
|
export function AppSidebar() {
|
|
const { auth, payablesAvailable } = usePage().props;
|
|
const canReadPurchases = [
|
|
'admin',
|
|
'procurement',
|
|
'finance',
|
|
'department_head',
|
|
].includes(auth.user.purchasing_role ?? '');
|
|
const purchasingItems: NavItem[] = [
|
|
{ title: 'Requisições', href: '/requisicoes', icon: ClipboardList },
|
|
...(auth.user.purchasing_role === 'procurement'
|
|
? [
|
|
{
|
|
title: 'Regras de investimento',
|
|
href: '/regras-investimento',
|
|
icon: FileCheck2,
|
|
},
|
|
]
|
|
: []),
|
|
...(canReadPurchases
|
|
? [
|
|
{ title: 'Fornecedores', href: '/fornecedores', icon: Users },
|
|
{ title: 'Cotações', href: '/cotacoes', icon: Scale },
|
|
{
|
|
title: 'Ordens de compra',
|
|
href: '/ordens',
|
|
icon: FileCheck2,
|
|
},
|
|
]
|
|
: []),
|
|
];
|
|
const inventoryItems = [
|
|
...([
|
|
'admin',
|
|
'procurement',
|
|
'finance',
|
|
'warehouse',
|
|
'department_head',
|
|
].includes(auth.user.purchasing_role ?? '')
|
|
? [{ title: 'Recepção', href: '/recepcoes', icon: PackageCheck }]
|
|
: []),
|
|
...([
|
|
'admin',
|
|
'procurement',
|
|
'finance',
|
|
'warehouse',
|
|
'department_head',
|
|
].includes(auth.user.purchasing_role ?? '')
|
|
? [
|
|
{
|
|
title: 'Equipamentos e peças',
|
|
href: '/equipamentos',
|
|
icon: Warehouse,
|
|
},
|
|
]
|
|
: []),
|
|
...(['admin', 'procurement', 'finance', 'warehouse'].includes(
|
|
auth.user.purchasing_role ?? '',
|
|
)
|
|
? [
|
|
{
|
|
title: 'Stock e movimentos',
|
|
href: '/stock',
|
|
icon: Warehouse,
|
|
},
|
|
{
|
|
title: 'Saídas e inventários',
|
|
href: '/stock/operacoes',
|
|
icon: ClipboardList,
|
|
},
|
|
]
|
|
: []),
|
|
];
|
|
const administrationItems =
|
|
auth.user.purchasing_role === 'admin'
|
|
? [
|
|
{
|
|
title: 'Empresa e equipa',
|
|
href: '/empresa',
|
|
icon: Building2,
|
|
},
|
|
]
|
|
: [];
|
|
return (
|
|
<Sidebar collapsible="icon" variant="inset">
|
|
<SidebarHeader>
|
|
<SidebarMenu>
|
|
<SidebarMenuItem>
|
|
<SidebarMenuButton size="lg" asChild>
|
|
<Link href={dashboard()} prefetch>
|
|
<AppLogo />
|
|
</Link>
|
|
</SidebarMenuButton>
|
|
</SidebarMenuItem>
|
|
</SidebarMenu>
|
|
</SidebarHeader>
|
|
|
|
<SidebarContent>
|
|
<NavMain title="Geral" items={generalNavItems} />
|
|
<NavMain title="Compras" items={purchasingItems} />
|
|
{['admin', 'finance'].includes(
|
|
auth.user.purchasing_role ?? '',
|
|
) && (
|
|
<NavMain
|
|
title="Finanças"
|
|
items={[
|
|
{
|
|
title: 'Orçamentos',
|
|
href: '/orcamentos',
|
|
icon: FileCheck2,
|
|
},
|
|
{
|
|
title: 'Regras de investimento',
|
|
href: '/regras-investimento',
|
|
icon: FileCheck2,
|
|
},
|
|
{
|
|
title: 'Facturas',
|
|
href: '/facturas',
|
|
icon: FileCheck2,
|
|
},
|
|
...(payablesAvailable === true
|
|
? [{title: 'Obrigações a fornecedores', href: '/obrigacoes-fornecedores', icon: FileCheck2, fullPage: true}]
|
|
: []),
|
|
{
|
|
title: 'Pagamentos externos',
|
|
href: '/pagamentos',
|
|
icon: FileCheck2,
|
|
},
|
|
]}
|
|
/>
|
|
)}
|
|
{inventoryItems.length > 0 && (
|
|
<NavMain title="Armazém" items={inventoryItems} />
|
|
)}
|
|
{administrationItems.length > 0 && (
|
|
<NavMain
|
|
title="Administração"
|
|
items={administrationItems}
|
|
/>
|
|
)}
|
|
</SidebarContent>
|
|
|
|
<SidebarFooter>
|
|
<Link
|
|
href="/"
|
|
className="px-3 py-2 text-xs text-muted-foreground hover:text-foreground"
|
|
>
|
|
Página inicial
|
|
</Link>
|
|
<NavUser />
|
|
</SidebarFooter>
|
|
</Sidebar>
|
|
);
|
|
}
|