SettingsLayout.tsx 1.2 KB

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