| 1 | import * as React from "react"; |
| 2 | import { ChevronDown, Plus } from "lucide-react"; |
| 3 | |
| 4 | import { |
| 5 | DropdownMenu, |
| 6 | DropdownMenuContent, |
| 7 | DropdownMenuItem, |
| 8 | DropdownMenuLabel, |
| 9 | DropdownMenuSeparator, |
| 10 | DropdownMenuShortcut, |
| 11 | DropdownMenuTrigger, |
| 12 | } from "@/components/ui/dropdown-menu"; |
| 13 | import { |
| 14 | SidebarMenu, |
| 15 | SidebarMenuButton, |
| 16 | SidebarMenuItem, |
| 17 | } from "@/components/ui/sidebar"; |
| 18 | |
| 19 | export function TeamSwitcher({ |
| 20 | teams, |
| 21 | }: { |
| 22 | teams: { |
| 23 | name: string; |
| 24 | logo: React.ElementType; |
| 25 | plan: string; |
| 26 | }[]; |
| 27 | }) { |
| 28 | const [activeTeam, setActiveTeam] = React.useState(teams[0]); |
| 29 | |
| 30 | if (!activeTeam) { |
| 31 | return null; |
| 32 | } |
| 33 | |
| 34 | return ( |
| 35 | <SidebarMenu> |
| 36 | <SidebarMenuItem> |
| 37 | <DropdownMenu> |
| 38 | <DropdownMenuTrigger asChild> |
| 39 | <SidebarMenuButton className="w-fit px-1.5"> |
| 40 | <div className="bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-5 items-center justify-center rounded-md"> |
| 41 | <activeTeam.logo className="size-3" /> |
| 42 | </div> |
| 43 | <span className="truncate font-medium">{activeTeam.name}</span> |
| 44 | <ChevronDown className="opacity-50" /> |
| 45 | </SidebarMenuButton> |
| 46 | </DropdownMenuTrigger> |
| 47 | <DropdownMenuContent |
| 48 | className="w-64 rounded-lg" |
| 49 | align="start" |
| 50 | side="bottom" |
| 51 | sideOffset={4} |
| 52 | > |
| 53 | <DropdownMenuLabel className="text-muted-foreground text-xs"> |
| 54 | Teams |
| 55 | </DropdownMenuLabel> |
| 56 | {teams.map((team, index) => ( |
| 57 | <DropdownMenuItem |
| 58 | key={team.name} |
| 59 | onClick={() => setActiveTeam(team)} |
| 60 | className="gap-2 p-2" |
| 61 | > |
| 62 | <div className="flex size-6 items-center justify-center rounded-xs border"> |
| 63 | <team.logo className="size-4 shrink-0" /> |
| 64 | </div> |
| 65 | {team.name} |
| 66 | <DropdownMenuShortcut>⌘{index + 1}</DropdownMenuShortcut> |
| 67 | </DropdownMenuItem> |
| 68 | ))} |
| 69 | <DropdownMenuSeparator /> |
| 70 | <DropdownMenuItem className="gap-2 p-2"> |
| 71 | <div className="bg-background flex size-6 items-center justify-center rounded-md border"> |
| 72 | <Plus className="size-4" /> |
| 73 | </div> |
| 74 | <div className="text-muted-foreground font-medium">Add team</div> |
| 75 | </DropdownMenuItem> |
| 76 | </DropdownMenuContent> |
| 77 | </DropdownMenu> |
| 78 | </SidebarMenuItem> |
| 79 | </SidebarMenu> |
| 80 | ); |
| 81 | } |