Continuous Integration / config-asf (pull_request) Successful in 7s
Continuous Integration / config-sls (pull_request) Successful in 8s
Continuous Integration / changes (pull_request) Successful in 11s
Continuous Integration / backend-build (pull_request) Successful in 1m46s
Continuous Integration / compile-sites (pull_request) Successful in 1m51s
Continuous Integration / frontend-prepare (pull_request) Successful in 1m57s
Continuous Integration / vulnerability-scan (pull_request) Successful in 2m2s
Continuous Integration / frontend-build (pull_request) Successful in 43s
Continuous Integration / frontend-test (pull_request) Successful in 2m30s
Continuous Integration / backend-test (pull_request) Successful in 2m43s
Continuous Integration / frontend-lint (pull_request) Successful in 2m28s
Continuous Integration / publish-sls-test (pull_request) Skipped
Continuous Integration / publish-sls-production (pull_request) Skipped
Continuous Integration / deploy-sls-test (pull_request) Skipped
Continuous Integration / deploy-sls-production (pull_request) Skipped
Continuous Integration / publish-asf-test (pull_request) Skipped
Continuous Integration / deploy-asf-test (pull_request) Skipped
Continuous Integration / smoke-sls-test (pull_request) Skipped
Continuous Integration / smoke-asf-test (pull_request) Skipped
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
183 lines
8.0 KiB
TypeScript
183 lines
8.0 KiB
TypeScript
import { Link } from '@tanstack/react-router';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { LayoutDashboard, Users, FileText, Package, Mail, Settings, X, Image as ImageIcon } from 'lucide-react';
|
|
import type { LucideIcon } from 'lucide-react';
|
|
import { cn } from '@/lib/utils';
|
|
import { useAuth } from '@/features/auth/context/auth-context';
|
|
import { useAvailabilityStatus } from '@/features/availability/services/useAvailability';
|
|
import { useSystemCapabilities } from '@/features/system/services/useSystemCapabilities';
|
|
import { useContactSettings } from '@/features/contact/services/useContactSettings';
|
|
import { useUnreadContactCount } from '@/features/contact/services/useContactMessages';
|
|
import { LanguageSwitcher } from '@/i18n/LanguageSwitcher';
|
|
import { BrandLogo } from './BrandLogo';
|
|
import { ThemeToggle } from './ThemeToggle';
|
|
import { UserMenu } from './UserMenu';
|
|
|
|
type Role = 'Owner' | 'Administrator' | 'User';
|
|
|
|
interface NavItem {
|
|
to: string;
|
|
labelKey: string;
|
|
icon: LucideIcon;
|
|
testId: string;
|
|
roles?: Role[];
|
|
requiredModule?: string;
|
|
}
|
|
|
|
const ALLOWED_WHEN_UNAVAILABLE = ['/dashboard', '/settings'];
|
|
|
|
const NAV_ITEMS: NavItem[] = [
|
|
{ to: '/dashboard', labelKey: 'nav.dashboard', icon: LayoutDashboard, testId: 'nav-dashboard' },
|
|
{ to: '/users', labelKey: 'nav.users', icon: Users, testId: 'nav-users', roles: ['Owner', 'Administrator'] },
|
|
{ to: '/cms', labelKey: 'nav.cms', icon: FileText, testId: 'nav-cms', roles: ['Owner'], requiredModule: 'Master' },
|
|
{
|
|
to: '/hero',
|
|
labelKey: 'nav.hero',
|
|
icon: ImageIcon,
|
|
testId: 'nav-hero',
|
|
roles: ['Owner', 'Administrator'],
|
|
requiredModule: 'Hero',
|
|
},
|
|
{
|
|
to: '/offerings',
|
|
labelKey: 'nav.offerings',
|
|
icon: Package,
|
|
testId: 'nav-offerings',
|
|
roles: ['Owner', 'Administrator'],
|
|
requiredModule: 'Offerings',
|
|
},
|
|
{
|
|
to: '/messages',
|
|
labelKey: 'nav.messages',
|
|
icon: Mail,
|
|
testId: 'nav-messages',
|
|
roles: ['Owner', 'Administrator'],
|
|
requiredModule: 'Contact',
|
|
},
|
|
];
|
|
|
|
const SETTINGS_ITEM: NavItem = {
|
|
to: '/settings', labelKey: 'nav.settings', icon: Settings, testId: 'nav-settings', roles: ['Owner', 'Administrator'],
|
|
};
|
|
|
|
interface SidebarProps {
|
|
onClose?: () => void;
|
|
}
|
|
|
|
export function Sidebar({ onClose }: SidebarProps = {}) {
|
|
const { t } = useTranslation();
|
|
const { user } = useAuth();
|
|
const { data: availability } = useAvailabilityStatus();
|
|
const { data: capabilities } = useSystemCapabilities();
|
|
|
|
const role = user?.role as Role | undefined;
|
|
// The Berichten entry also needs the management API to exist on this host (a loaded module is not enough:
|
|
// while the host switch is off its routes answer 404). Only asked for roles that may see the entry.
|
|
const mayManageContact = (role === 'Owner' || role === 'Administrator') && !!capabilities?.modules.includes('Contact');
|
|
const { data: contactSettings } = useContactSettings({ enabled: mayManageContact });
|
|
const { data: unreadMessages } = useUnreadContactCount(mayManageContact && !!contactSettings);
|
|
const systemUnavailable = availability?.status === 'NotAvailable';
|
|
const visibleItems = NAV_ITEMS.filter(
|
|
(item) =>
|
|
(!item.roles || (role && item.roles.includes(role))) &&
|
|
(!item.requiredModule || capabilities?.modules.includes(item.requiredModule)) &&
|
|
(item.requiredModule !== 'Contact' || !!contactSettings)
|
|
);
|
|
const showSettings = !SETTINGS_ITEM.roles || (role && SETTINGS_ITEM.roles.includes(role));
|
|
|
|
return (
|
|
<aside
|
|
className="flex h-full w-64 shrink-0 flex-col border-r border-border bg-card"
|
|
data-testid="app-sidebar"
|
|
>
|
|
<div className="flex h-16 items-center justify-between border-b border-border px-6">
|
|
<BrandLogo />
|
|
{onClose && (
|
|
<button
|
|
type="button"
|
|
onClick={onClose}
|
|
aria-label={t('nav.closeMenu')}
|
|
className="rounded-md p-1 text-muted-foreground hover:bg-accent hover:text-accent-foreground md:hidden"
|
|
data-testid="sidebar-close-button"
|
|
>
|
|
<X className="size-4" />
|
|
</button>
|
|
)}
|
|
</div>
|
|
|
|
<nav className="flex-1 space-y-1 overflow-y-auto p-3">
|
|
{visibleItems.map((item) => {
|
|
const Icon = item.icon;
|
|
const blocked = systemUnavailable && !ALLOWED_WHEN_UNAVAILABLE.some(p => item.to.startsWith(p));
|
|
if (blocked) {
|
|
return (
|
|
<span
|
|
key={item.to}
|
|
data-testid={item.testId}
|
|
className="flex cursor-not-allowed items-center gap-3 rounded-md px-3 py-2 text-sm font-medium opacity-40 select-none"
|
|
>
|
|
<Icon className="size-4" />
|
|
{t(item.labelKey)}
|
|
</span>
|
|
);
|
|
}
|
|
return (
|
|
<Link
|
|
key={item.to}
|
|
to={item.to}
|
|
data-testid={item.testId}
|
|
onClick={onClose}
|
|
className="flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground"
|
|
activeProps={{
|
|
className: cn('bg-accent text-accent-foreground'),
|
|
}}
|
|
>
|
|
<Icon className="size-4" />
|
|
{t(item.labelKey)}
|
|
{item.requiredModule === 'Contact' && !!unreadMessages && unreadMessages > 0 && (
|
|
<>
|
|
<span
|
|
className="ml-auto inline-flex min-w-5 items-center justify-center rounded-full bg-primary px-1.5 text-xs font-semibold leading-5 text-primary-foreground"
|
|
aria-hidden="true"
|
|
data-testid="nav-messages-badge"
|
|
>
|
|
{unreadMessages > 99 ? '99+' : unreadMessages}
|
|
</span>
|
|
<span className="sr-only" data-testid="nav-messages-badge-text">
|
|
{t('nav.unreadMessages', { count: unreadMessages })}
|
|
</span>
|
|
</>
|
|
)}
|
|
</Link>
|
|
);
|
|
})}
|
|
</nav>
|
|
|
|
{showSettings && (
|
|
<div className="border-t border-border p-3">
|
|
<Link
|
|
to={SETTINGS_ITEM.to}
|
|
data-testid={SETTINGS_ITEM.testId}
|
|
onClick={onClose}
|
|
className="flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground"
|
|
activeProps={{
|
|
className: cn('bg-accent text-accent-foreground'),
|
|
}}
|
|
>
|
|
<Settings className="size-4" />
|
|
{t(SETTINGS_ITEM.labelKey)}
|
|
</Link>
|
|
</div>
|
|
)}
|
|
|
|
<div className="flex items-center gap-1 border-t border-border p-3">
|
|
<div className="flex-1 min-w-0">
|
|
<UserMenu />
|
|
</div>
|
|
<LanguageSwitcher />
|
|
<ThemeToggle />
|
|
</div>
|
|
</aside>
|
|
);
|
|
}
|