Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions RestroHub-FrontEnd/src/components/admin/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ import {
ChevronsLeft,
ChevronsRight,
ChefHat,
ShieldCheck,
} from 'lucide-react';
import { useAdminTheme } from '@context/AdminThemeContext';
import { FULL_ADMIN_ROLES, hasAnyRole, readStoredRoles } from '../../utils/auth';

const Sidebar = ({ open, setOpen, collapsed, setCollapsed }) => {
const location = useLocation();
const sidebarRef = useRef(null);
const { isDark } = useAdminTheme();
const roles = readStoredRoles();
const limitedAdminRoles = ['MANAGER', 'STAFF'];
const superAdminOnly = ['SUPER_ADMIN'];
const allAdminRoles = [...FULL_ADMIN_ROLES, ...limitedAdminRoles];

const [expandedMenus, setExpandedMenus] = useState({
store: false,
Expand Down Expand Up @@ -61,10 +67,10 @@ const Sidebar = ({ open, setOpen, collapsed, setCollapsed }) => {
{
label: 'Menu',
items: [
{ type: 'link', name: 'Dashboard', path: '/admin/dashboard', icon: LayoutDashboard },
{ type: 'link', name: 'Kitchen Display', path: '/admin/kds', icon: ChefHat },
{ type: 'link', name: 'Menus', path: '/admin/menus', icon: UtensilsCrossed },
{ type: 'link', name: 'Orders', path: '/admin/orders', icon: ShoppingCart },
{ type: 'link', name: 'Dashboard', path: '/admin/dashboard', icon: LayoutDashboard, allowedRoles: FULL_ADMIN_ROLES },
{ type: 'link', name: 'Kitchen Display', path: '/admin/kds', icon: ChefHat, allowedRoles: allAdminRoles },
{ type: 'link', name: 'Menus', path: '/admin/menus', icon: UtensilsCrossed, allowedRoles: FULL_ADMIN_ROLES },
{ type: 'link', name: 'Orders', path: '/admin/orders', icon: ShoppingCart, allowedRoles: allAdminRoles },
],
},
{
Expand All @@ -75,30 +81,55 @@ const Sidebar = ({ open, setOpen, collapsed, setCollapsed }) => {
name: 'Store',
icon: Store,
menuKey: 'store',
allowedRoles: FULL_ADMIN_ROLES,
children: [
{ name: 'Branches', path: '/admin/store/branches', icon: Building2 },
{ name: 'Branches', path: '/admin/store/branches', icon: Building2, allowedRoles: FULL_ADMIN_ROLES },
],
},
{
type: 'expandable',
name: 'Marketing',
icon: Megaphone,
menuKey: 'marketing',
allowedRoles: FULL_ADMIN_ROLES,
children: [
{ name: 'Website', path: '/admin/marketing/website', icon: Globe },
{ name: 'QR Display', path: '/admin/marketing/qr-display', icon: QrCode },
{ name: 'Website', path: '/admin/marketing/website', icon: Globe, allowedRoles: FULL_ADMIN_ROLES },
{ name: 'QR Display', path: '/admin/marketing/qr-display', icon: QrCode, allowedRoles: FULL_ADMIN_ROLES },
],
},
],
},
{
label: 'Payments',
items: [
{ type: 'link', name: 'UPI Links', path: '/admin/upi-links', icon: CreditCard },
{ type: 'link', name: 'UPI Links', path: '/admin/upi-links', icon: CreditCard, allowedRoles: FULL_ADMIN_ROLES },
],
},
{
label: 'Platform',
items: [
{ type: 'link', name: 'Subscriptions', path: '/admin/subscriptions', icon: ShieldCheck, allowedRoles: superAdminOnly },
],
},
];

const canViewItem = (item) => !item.allowedRoles || hasAnyRole(roles, item.allowedRoles);

const visibleNavSections = navSections
.map((section) => ({
...section,
items: section.items
.map((item) => {
if (item.type !== 'expandable') return item;
return {
...item,
children: item.children.filter(canViewItem),
};
})
.filter((item) => canViewItem(item) && (item.type !== 'expandable' || item.children.length > 0)),
}))
.filter((section) => section.items.length > 0);

// ============================================
// SINGLE NAV LINK
// ============================================
Expand Down Expand Up @@ -369,7 +400,7 @@ const Sidebar = ({ open, setOpen, collapsed, setCollapsed }) => {
{/* NAVIGATION */}
{/* ================================= */}
<div className="flex-1 overflow-y-auto overflow-x-hidden px-3 py-4">
{navSections.map((section, sectionIndex) => (
{visibleNavSections.map((section, sectionIndex) => (
<div key={section.label} className={sectionIndex > 0 ? 'mt-4' : ''}>
{/* Section Label */}
{!collapsed ? (
Expand Down Expand Up @@ -458,4 +489,4 @@ const Sidebar = ({ open, setOpen, collapsed, setCollapsed }) => {
);
};

export default Sidebar;
export default Sidebar;
Loading