SettingsLayout.tsx43 lines · main
1import { useRouter } from 'next/router'
2import type { PropsWithChildren } from 'react'
3
4import { ProjectLayout } from '../ProjectLayout'
5import { useGenerateSettingsMenu } from './SettingsMenu.utils'
6import { ProductMenu } from '@/components/ui/ProductMenu'
7import { withAuth } from '@/hooks/misc/withAuth'
8
9/**
10 * Menu-only component for the settings section. Used by the desktop sidebar and by the
11 * mobile sheet submenu. Must not wrap ProjectLayout so that opening the settings submenu
12 * in the mobile sheet does not overwrite registerOpenMenu and break the menu button.
13 */
14export const SettingsProductMenu = () => {
15 const router = useRouter()
16
17 const page = router.pathname.includes('billing')
18 ? router.pathname.split('/')[5]
19 : router.pathname.split('/')[4]
20
21 const menu = useGenerateSettingsMenu()
22
23 return <ProductMenu page={page} menu={menu} />
24}
25
26interface SettingsLayoutProps {
27 title: string
28}
29
30export const SettingsLayout = ({ title, children }: PropsWithChildren<SettingsLayoutProps>) => {
31 return (
32 <ProjectLayout
33 isBlocking={false}
34 product="settings"
35 browserTitle={{ section: title }}
36 productMenu={<SettingsProductMenu />}
37 >
38 {children}
39 </ProjectLayout>
40 )
41}
42
43export default withAuth(SettingsLayout)