'use client' import Link from 'next/link' import { usePathname } from 'next/navigation' import { notFound } from 'next/navigation' import { Button } from '@nextsparkjs/core/components/ui/button' import { SettingsSidebar } from '@nextsparkjs/core/components/settings/layouts/SettingsSidebar' import { MobileTopBar } from '@nextsparkjs/core/components/dashboard/mobile/MobileTopBar' import { MobileBottomNav } from '@nextsparkjs/core/components/dashboard/mobile/MobileBottomNav' import { ArrowLeft } from 'lucide-react' import { useState, useCallback, useEffect } from 'react' import { sel } from '@nextsparkjs/core/selectors' import { useTranslations } from 'next-intl' import { getTemplateOrDefaultClient } from '@nextsparkjs/registries/template-registry.client' import { isSettingsPageEnabled } from '@nextsparkjs/core/lib/config/config-sync' /** * Map of URL paths to settings page keys for validation */ const PATH_TO_PAGE_KEY: Record = { '/dashboard/settings/profile': 'profile', '/dashboard/settings/security': 'security', '/dashboard/settings/password': 'password', '/dashboard/settings/notifications': 'notifications', '/dashboard/settings/api-keys': 'api-keys', '/dashboard/settings/billing': 'billing', '/dashboard/settings/teams': 'teams', '/dashboard/settings/teams/permissions': 'teams', '/dashboard/settings/invoices': 'billing', } function SettingsLayout({ children, }: { children: React.ReactNode }) { const [statusMessage, setStatusMessage] = useState('') const pathname = usePathname() ?? '' const t = useTranslations('settings') // Validate if the current settings page is enabled // This prevents access to disabled pages via direct URL useEffect(() => { const pageKey = PATH_TO_PAGE_KEY[pathname] // If we have a page key mapping, check if it's enabled if (pageKey) { const enabled = isSettingsPageEnabled(pageKey) if (!enabled) { notFound() } } // For paths not in the mapping (like /dashboard/settings itself), allow access }, [pathname]) const handleBackToDashboard = useCallback(() => { setStatusMessage(t('navigation.backToDashboard')) }, [t]) return ( <> {/* MANDATORY: Screen reader announcements */}
{statusMessage}
{/* Mobile only - TopBar */} {/* Mobile only - BottomNav */}
{/* Back Button - Desktop only */} {/* Header - Desktop only */}

{t('layout.title')}

{t('layout.description')}

{/* Main Content */}
{/* Settings Sidebar - Desktop only */} {/* Content Area */}
{children}
) } export default getTemplateOrDefaultClient('app/dashboard/settings/layout.tsx', SettingsLayout)