import { useLocation } from 'react-router-dom'; import { Link } from 'react-router-dom'; import type { ReactElement } from 'react'; import { cn } from '@/lib/utils'; import { useAppSelector } from '@/hooks/redux-hooks'; export interface TabItem { label: string; path: string; } interface PageHeaderProps { title: string; description?: string; tabs?: TabItem[]; } const defaultTabs: TabItem[] = [ { label: 'Overview', path: '/dashboard' }, { label: 'Tenants', path: '/tenants' }, // { label: 'Users', path: '/users' }, // { label: 'Roles', path: '/roles' }, { label: 'Modules', path: '/modules' }, { label: 'Audit Logs', path: '/audit-logs' }, ]; export const PageHeader = ({ title, description, tabs = defaultTabs, }: PageHeaderProps): ReactElement => { const location = useLocation(); const { roles } = useAppSelector((state) => state.auth); // Check if user is super_admin let rolesArray: string[] = []; if (Array.isArray(roles)) { rolesArray = roles; } else if (typeof roles === 'string') { try { rolesArray = JSON.parse(roles); } catch { rolesArray = []; } } const isSuperAdmin = rolesArray.includes('super_admin'); const isActiveTab = (path: string): boolean => { // Exact match for dashboard if (path === '/dashboard') { return location.pathname === '/dashboard'; } // For other paths, check if current path starts with the tab path return location.pathname.startsWith(path); }; return (
{/* Title and Description */}

{title}

{description && (

{description}

)}
{/* Tabs Navigation - Only show for super_admin */} {isSuperAdmin && tabs.length > 0 && (
{tabs.map((tab) => { const isActive = isActiveTab(tab.path); return ( {tab.label} ); })}
)}
); };