diff --git a/resources/js/layouts/settings/layout.tsx b/resources/js/layouts/settings/layout.tsx index 729d711c..8f6c7dcf 100644 --- a/resources/js/layouts/settings/layout.tsx +++ b/resources/js/layouts/settings/layout.tsx @@ -4,6 +4,16 @@ import { index as categoriesIndex } from '@/actions/App/Http/Controllers/Setting import { index as labelsIndex } from '@/actions/App/Http/Controllers/Settings/LabelController'; import Heading from '@/components/heading'; import { Button } from '@/components/ui/button'; +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectLabel, + SelectSeparator, + SelectTrigger, + SelectValue, +} from '@/components/ui/select'; import { Separator } from '@/components/ui/separator'; import { cn, isSameUrl, resolveUrl } from '@/lib/utils'; import { edit as editAccount } from '@/routes/account'; @@ -17,7 +27,7 @@ import { type NavItem, } from '@/types'; import { __ } from '@/utils/i18n'; -import { Link, usePage } from '@inertiajs/react'; +import { Link, router, usePage } from '@inertiajs/react'; import { type PropsWithChildren } from 'react'; const getNavItems = ( @@ -103,6 +113,68 @@ const getNavItems = ( : []), ]; +function renderMobileNavGroups( + items: (NavItem | NavSectionHeader | NavDivider)[], +) { + const elements: React.ReactNode[] = []; + let currentGroupLabel: string | null = null; + let currentGroupItems: NavItem[] = []; + + const flushGroup = () => { + if (currentGroupItems.length === 0) { + return; + } + + const groupKey = currentGroupLabel ?? 'default'; + + if (currentGroupLabel) { + elements.push( + + {__(currentGroupLabel)} + {currentGroupItems.map((item) => ( + + {__(item.title)} + + ))} + , + ); + } else { + elements.push( + ...currentGroupItems.map((item) => ( + + {__(item.title)} + + )), + ); + } + + currentGroupItems = []; + }; + + for (const item of items) { + if (item.type === 'divider') { + flushGroup(); + elements.push(); + currentGroupLabel = null; + } else if (item.type === 'section-header') { + flushGroup(); + currentGroupLabel = item.title; + } else { + currentGroupItems.push(item); + } + } + + flushGroup(); + + return elements; +} + export default function SettingsLayout({ children }: PropsWithChildren) { const { subscriptionsEnabled, auth, features } = usePage().props; @@ -121,6 +193,11 @@ export default function SettingsLayout({ children }: PropsWithChildren) { openBankingEnabled, ); + const activeNavItem = sidebarNavItems.find( + (item): item is NavItem => + item.type === 'nav-item' && isSameUrl(currentPath, item.href), + ); + return (
-