74 lines
3.0 KiB
TypeScript
74 lines
3.0 KiB
TypeScript
import type { Role } from '@/types';
|
|
|
|
export type Permission =
|
|
| 'dashboard'
|
|
| 'products.read'
|
|
| 'products.write'
|
|
| 'orders.read'
|
|
| 'orders.write'
|
|
| 'inventory.read'
|
|
| 'inventory.write'
|
|
| 'customers.read'
|
|
| 'customers.write'
|
|
| 'categories.read'
|
|
| 'categories.write'
|
|
| 'categories.delete'
|
|
| 'brands.read'
|
|
| 'brands.write'
|
|
| 'promotions.read'
|
|
| 'promotions.write'
|
|
| 'reviews.read'
|
|
| 'reviews.moderate'
|
|
| 'cms.read'
|
|
| 'cms.write'
|
|
| 'admin-users.read'
|
|
| 'admin-users.write'
|
|
| 'audit.read'
|
|
| 'reporting.read';
|
|
|
|
export function can(role: Role, permission: Permission): boolean {
|
|
if (role === 'admin') return true;
|
|
return false;
|
|
}
|
|
|
|
export interface NavItem {
|
|
href: string;
|
|
label: string;
|
|
icon: string;
|
|
permission: Permission;
|
|
badge?: number;
|
|
parentHref?: string;
|
|
}
|
|
|
|
export const NAV_ITEMS: NavItem[] = [
|
|
{ href: '/', label: 'Dashboard', icon: '📊', permission: 'dashboard' },
|
|
{ href: '/reporting', label: 'Reporting', icon: '📈', permission: 'reporting.read' },
|
|
{ href: '/reporting/dashboard', label: 'Dashboard', icon: '📊', permission: 'reporting.read', parentHref: '/reporting' },
|
|
{ href: '/reporting/sales', label: 'Ventas', icon: '🧾', permission: 'reporting.read', parentHref: '/reporting' },
|
|
{ href: '/reporting/products', label: 'Productos', icon: '📦', permission: 'reporting.read', parentHref: '/reporting' },
|
|
{ href: '/products', label: 'Productos', icon: '📦', permission: 'products.read' },
|
|
{ href: '/orders', label: 'Pedidos', icon: '🧾', permission: 'orders.read' },
|
|
{ href: '/payments', label: 'Pagos', icon: '💳', permission: 'orders.read' },
|
|
{ href: '/inventory', label: 'Inventario', icon: '📊', permission: 'inventory.read' },
|
|
{ href: '/customers', label: 'Clientes', icon: '👥', permission: 'customers.read' },
|
|
{ href: '/categories', label: 'Categorías', icon: '🏷️', permission: 'categories.read' },
|
|
{ href: '/brands', label: 'Marcas', icon: '🏷️', permission: 'brands.read' },
|
|
{ href: '/promotions', label: 'Promociones', icon: '🏷️', permission: 'promotions.read' },
|
|
{ href: '/shipping', label: 'Envíos', icon: '📦', permission: 'orders.read' },
|
|
{ href: '/reviews', label: 'Reseñas', icon: '⭐', permission: 'reviews.read' },
|
|
{ href: '/cms', label: 'CMS', icon: '📄', permission: 'cms.read' },
|
|
{ href: '/users', label: 'Usuarios', icon: '🔐', permission: 'admin-users.read' },
|
|
{ href: '/tax-rates', label: 'IVA', icon: '📊', permission: 'orders.read' },
|
|
{ href: '/audit', label: 'Auditoría', icon: '📋', permission: 'audit.read' },
|
|
{ href: '/logs', label: 'Logs', icon: '🖥️', permission: 'audit.read' },
|
|
{ href: '/settings', label: 'Ajustes', icon: '⚙️', permission: 'dashboard' },
|
|
];
|
|
|
|
export function topNavItems(role: Role): NavItem[] {
|
|
return NAV_ITEMS.filter((item) => !item.parentHref && can(role, item.permission));
|
|
}
|
|
|
|
export function subNavItems(parentHref: string, role: Role): NavItem[] {
|
|
return NAV_ITEMS.filter((item) => item.parentHref === parentHref && can(role, item.permission));
|
|
}
|