| 1 | "use client"; |
| 2 | |
| 3 | import { |
| 4 | AppWindow, |
| 5 | Briefcase, |
| 6 | HardDrive, |
| 7 | KeyRound, |
| 8 | KeySquare, |
| 9 | Settings, |
| 10 | Shield, |
| 11 | ShieldCheck, |
| 12 | User2, |
| 13 | UserRound, |
| 14 | Users, |
| 15 | UsersRound, |
| 16 | Webhook, |
| 17 | } from "lucide-react"; |
| 18 | import { Fragment } |
| 19 | import Link from "next/link |
| 20 | import { usePathname } |
| 21 | |
| 22 | import { cn } |
| 23 | |
| 24 | // Icons are components, which cannot cross from a server layout; the layout names one instead. |
| 25 | const icons = { |
| 26 | settings: Settings, |
| 27 | users: Users, |
| 28 | teams: UsersRound, |
| 29 | outside: UserRound, |
| 30 | webhooks: Webhook, |
| 31 | storage: HardDrive, |
| 32 | account: User2, |
| 33 | security: Shield, |
| 34 | keys: KeyRound, |
| 35 | tokens: KeySquare, |
| 36 | organizations: Briefcase, |
| 37 | oauthApps: AppWindow, |
| 38 | authorizedApps: ShieldCheck, |
| 39 | }; |
| 40 | |
| 41 | export type SettingsLink |
| 42 | href: string |
| 43 | label: string |
| 44 | icon: keyof |
| 45 | /** A heading shown above this link on wide screens, starting a group. */ |
| 46 | group?: string |
| 47 | }; |
| 48 | |
| 49 | export function SettingsNav({ |
| 50 | label, |
| 51 | links, |
| 52 | }: { |
| 53 | /** What the settings are for, for screen readers. */ |
| 54 | label: string |
| 55 | links: SettingsLink |
| 56 | }) { |
| 57 | const pathname = |
| 58 | |
| 59 | return ( |
| 60 | <nav |
| 61 | aria-label={label} |
| 62 | className="-mx-1 flex gap-1 overflow-x-auto md:mx-0 md:flex-col" |
| 63 | > |
| 64 | {links.map(( |
| 65 | const Icon = |
| 66 | // A nested page, such as one webhook, lights up its section; the first link is the parent of every section. |
| 67 | const active = |
| 68 | pathname === href |
| 69 | (href !== links[ |
| 70 | return ( |
| 71 | <Fragment key={ |
| 72 | {group && ( |
| 73 | <p className="mt-4 hidden px-3 pb-1 text-xs font-medium text-muted-foreground md:block |
| 74 | {group} |
| 75 | </p> |
| 76 | )} |
| 77 | <Link |
| 78 | href={href} |
| 79 | aria-current={active ? |
| 80 | className={cn( |
| 81 | "flex items-center gap-2 whitespace-nowrap rounded-md px-3 py-2 text-sm text-muted-foreground transition-colors hover:bg-muted hover:text-foreground", |
| 82 | active && "bg-muted font-medium text-foreground" |
| 83 | )} |
| 84 | > |
| 85 | <Icon className=" |
| 86 | {label} |
| 87 | </Link> |
| 88 | </Fragment> |
| 89 | ); |
| 90 | })} |
| 91 | </nav> |
| 92 | ); |
| 93 | } |