Layout.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { Link } from '@inertiajs/react';
  2. import { type PropsWithChildren } from 'react';
  3. import { Heading } from '@/common/Heading';
  4. import { cn } from '@/common/helpers/cn';
  5. import { type NavItem } from '@/common/types';
  6. import { appearance } from '@/routes';
  7. import { edit as editPassword } from '@/routes/password';
  8. import { edit } from '@/routes/profile';
  9. import { Button } from '@/shadcn/button';
  10. import { Separator } from '@/shadcn/separator';
  11. const sidebarNavItems: NavItem[] = [
  12. {
  13. title: 'Profile',
  14. href: edit(),
  15. icon: null,
  16. },
  17. {
  18. title: 'Password',
  19. href: editPassword(),
  20. icon: null,
  21. },
  22. {
  23. title: 'Appearance',
  24. href: appearance(),
  25. icon: null,
  26. },
  27. ];
  28. export default function SettingsLayout({ children }: PropsWithChildren) {
  29. // When server-side rendering, we only render the layout on the client...
  30. if (typeof window === 'undefined') {
  31. return null;
  32. }
  33. const currentPath = window.location.pathname;
  34. return (
  35. <div className="px-4 py-6">
  36. <Heading title="Settings" description="Manage your profile and account settings" />
  37. <div className="flex flex-col lg:flex-row lg:space-x-12">
  38. <aside className="w-full max-w-xl lg:w-48">
  39. <nav className="flex flex-col space-y-1 space-x-0">
  40. {sidebarNavItems.map((item, index) => (
  41. <Button
  42. key={`${typeof item.href === 'string' ? item.href : item.href.url}-${index}`}
  43. size="sm"
  44. variant="ghost"
  45. asChild
  46. className={cn('w-full justify-start', {
  47. 'bg-muted': currentPath === (typeof item.href === 'string' ? item.href : item.href.url),
  48. })}
  49. >
  50. <Link href={item.href} prefetch>
  51. {item.icon && <item.icon className="h-4 w-4" />}
  52. {item.title}
  53. </Link>
  54. </Button>
  55. ))}
  56. </nav>
  57. </aside>
  58. <Separator className="my-6 lg:hidden" />
  59. <div className="flex-1 md:max-w-2xl">
  60. <section className="max-w-xl space-y-12">{children}</section>
  61. </div>
  62. </div>
  63. </div>
  64. );
  65. }