import { Component, Show, createEffect, For } from 'solid-js'; import { useNavigate, A } from '@solidjs/router'; import { authState, fetchRuntimeConfig, logout, hasModule } from '~/lib/auth'; // ── Icons (inline SVGs for zero deps) ───────────────────────────────────────── const IconDashboard = () => ( ); const IconJobs = () => ( ); const IconBell = () => ( ); const IconSettings = () => ( ); const IconLogout = () => ( ); const IconCompass = () => ( ); // ── Module → nav item mapping ───────────────────────────────────────────────── const MODULE_NAV_MAP: Record = { COMPANY_DASHBOARD: { label: 'Dashboard', href: '/dashboard', icon: IconDashboard }, JOBSEEKER_DASHBOARD: { label: 'Dashboard', href: '/dashboard', icon: IconDashboard }, CUSTOMER_DASHBOARD: { label: 'Dashboard', href: '/dashboard', icon: IconDashboard }, PROFESSIONAL_DASHBOARD: { label: 'Dashboard', href: '/dashboard', icon: IconDashboard }, JOBS: { label: 'Jobs', href: '/dashboard/jobs', icon: IconJobs }, JOBS_BROWSE: { label: 'Browse Jobs', href: '/dashboard/jobs', icon: IconJobs }, APPLICATIONS: { label: 'Applications', href: '/dashboard/applications', icon: IconJobs }, MY_APPLICATIONS: { label: 'My Applications', href: '/dashboard/applications', icon: IconJobs }, REQUIREMENTS: { label: 'Requirements', href: '/dashboard/requirements', icon: IconJobs }, MARKETPLACE: { label: 'Marketplace', href: '/dashboard/marketplace', icon: IconCompass }, MY_REQUESTS: { label: 'My Requests', href: '/dashboard/requests', icon: IconJobs }, ACCEPTED_LEADS: { label: 'Accepted Leads',href: '/dashboard/leads/accepted', icon: IconJobs }, PORTFOLIO: { label: 'Portfolio', href: '/dashboard/portfolio', icon: IconJobs }, SERVICES: { label: 'Services', href: '/dashboard/services', icon: IconJobs }, WALLET: { label: 'Wallet', href: '/dashboard/wallet', icon: IconCompass }, COMPANY_PROFILE: { label: 'Profile', href: '/dashboard/profile', icon: IconSettings }, JOBSEEKER_PROFILE: { label: 'Profile', href: '/dashboard/profile', icon: IconSettings }, CUSTOMER_PROFILE: { label: 'Profile', href: '/dashboard/profile', icon: IconSettings }, PROFESSIONAL_PROFILE: { label: 'Profile', href: '/dashboard/profile', icon: IconSettings }, PURCHASE_PACKAGES: { label: 'Buy Packages', href: '/dashboard/packages', icon: IconCompass }, NOTIFICATIONS: { label: 'Notifications', href: '/dashboard/notifications', icon: IconBell }, SETTINGS: { label: 'Settings', href: '/dashboard/settings', icon: IconSettings }, EXPLORE_NXTGAUGE: { label: 'Explore Nxtgauge', href: '/dashboard/explore', icon: IconCompass }, }; // ── Dashboard Layout ────────────────────────────────────────────────────────── export default function DashboardLayout(props: { children: any }) { const navigate = useNavigate(); const state = authState(); createEffect(() => { const s = authState(); if (!s.access_token) { navigate('/auth/login', { replace: true }); return; } if (s.runtime_config?.onboarding_required) { navigate('/onboarding', { replace: true }); return; } if (s.runtime_config?.role === 'USER') { navigate('/choose-role', { replace: true }); } }); const rc = () => authState().runtime_config; const navItems = () => { const modules = rc()?.enabled_modules ?? []; const seen = new Set(); return modules .map(m => MODULE_NAV_MAP[m]) .filter(item => { if (!item || seen.has(item.href)) return false; seen.add(item.href); return true; }); }; async function handleLogout() { await logout(); navigate('/auth/login', { replace: true }); } return ( {/* ── Sidebar ── */} {/* ── Main Content ── */} {/* Top bar */} {rc()?.user?.full_name ?? 'User'} {/* Page content */} Loading...}> {props.children} ); }