@@ -53,14 +53,26 @@ import {
5353 CollapsibleContent ,
5454 CollapsibleTrigger ,
5555} from "@/components/ui/collapsible" ;
56+ import {
57+ Command ,
58+ CommandEmpty ,
59+ CommandGroup ,
60+ CommandInput ,
61+ CommandItem ,
62+ CommandList ,
63+ } from "@/components/ui/command" ;
5664import {
5765 DropdownMenu ,
5866 DropdownMenuContent ,
5967 DropdownMenuItem ,
6068 DropdownMenuLabel ,
61- DropdownMenuSeparator ,
6269 DropdownMenuTrigger ,
6370} from "@/components/ui/dropdown-menu" ;
71+ import {
72+ Popover ,
73+ PopoverContent ,
74+ PopoverTrigger ,
75+ } from "@/components/ui/popover" ;
6476import { Separator } from "@/components/ui/separator" ;
6577import {
6678 SIDEBAR_COOKIE_NAME ,
@@ -565,6 +577,8 @@ function SidebarLogo() {
565577 const [ _activeTeam , setActiveTeam ] = useState <
566578 typeof activeOrganization | null
567579 > ( null ) ;
580+ const [ organizationSelectorOpen , setOrganizationSelectorOpen ] =
581+ useState ( false ) ;
568582
569583 useEffect ( ( ) => {
570584 if ( activeOrganization ) {
@@ -587,8 +601,11 @@ function SidebarLogo() {
587601 >
588602 { /* Organization Logo and Selector */ }
589603 < SidebarMenuItem className = { "w-full" } >
590- < DropdownMenu >
591- < DropdownMenuTrigger asChild >
604+ < Popover
605+ open = { organizationSelectorOpen }
606+ onOpenChange = { setOrganizationSelectorOpen }
607+ >
608+ < PopoverTrigger asChild >
592609 < SidebarMenuButton
593610 size = { isCollapsed ? "sm" : "lg" }
594611 className = { cn (
@@ -637,145 +654,156 @@ function SidebarLogo() {
637654 className = { cn ( "ml-auto" , isCollapsed && "hidden" ) }
638655 />
639656 </ SidebarMenuButton >
640- </ DropdownMenuTrigger >
641- < DropdownMenuContent
642- className = "w-64 rounded-lg max-h-[min(70vh,28rem)] flex flex-col "
657+ </ PopoverTrigger >
658+ < PopoverContent
659+ className = "w-96 p-0 "
643660 align = "start"
644661 side = { isMobile ? "bottom" : "right" }
645662 sideOffset = { 4 }
646663 >
647- < DropdownMenuLabel className = "text-xs text-muted-foreground shrink-0" >
648- Organizations
649- </ DropdownMenuLabel >
650- < div className = "overflow-y-auto overflow-x-hidden min-h-0 -mx-1 px-1" >
651- { organizations ?. map ( ( org ) => {
652- const isDefault = org . members ?. [ 0 ] ?. isDefault ?? false ;
653- return (
654- < div
655- className = "flex flex-row items-center justify-between gap-1"
656- key = { org . name }
657- >
658- < DropdownMenuItem
659- onClick = { async ( ) => {
660- await authClient . organization . setActive ( {
661- organizationId : org . id ,
662- } ) ;
663- window . location . reload ( ) ;
664- } }
665- className = "flex min-w-0 flex-1 gap-2 p-2"
666- >
667- < div className = "flex size-6 shrink-0 items-center justify-center rounded-sm border" >
668- < Logo
669- className = { cn (
670- "transition-all" ,
671- state === "collapsed" ? "size-4" : "size-5" ,
672- ) }
673- logoUrl = { org . logo ?? undefined }
674- />
675- </ div >
676- < span className = "truncate" > { org . name } </ span >
677- </ DropdownMenuItem >
678-
679- < div className = "flex shrink-0 items-center gap-2" >
680- < Button
681- variant = "ghost"
682- size = "icon"
683- className = { cn (
684- "group" ,
685- isDefault
686- ? "hover:bg-yellow-500/10"
687- : "hover:bg-blue-500/10" ,
688- ) }
689- isLoading = { isSettingDefault && ! isDefault }
690- disabled = { isDefault }
691- onClick = { async ( e ) => {
692- if ( isDefault ) return ;
693- e . stopPropagation ( ) ;
694- await setDefaultOrganization ( {
664+ < Command >
665+ < CommandInput
666+ placeholder = "Search organizations..."
667+ className = "h-9"
668+ />
669+ < CommandList className = "max-h-[min(60vh,24rem)]" >
670+ < CommandEmpty > No organizations found.</ CommandEmpty >
671+ < CommandGroup heading = "Organizations" >
672+ { organizations ?. map ( ( org ) => {
673+ const isDefault = org . members ?. [ 0 ] ?. isDefault ?? false ;
674+ return (
675+ < CommandItem
676+ key = { org . id }
677+ value = { org . name }
678+ onSelect = { async ( ) => {
679+ setOrganizationSelectorOpen ( false ) ;
680+ await authClient . organization . setActive ( {
695681 organizationId : org . id ,
696- } )
697- . then ( ( ) => {
698- refetch ( ) ;
699- toast . success ( "Default organization updated" ) ;
700- } )
701- . catch ( ( error ) => {
702- toast . error (
703- error ?. message ||
704- "Error setting default organization" ,
705- ) ;
706- } ) ;
682+ } ) ;
683+ window . location . reload ( ) ;
707684 } }
708- title = {
709- isDefault
710- ? "Default organization"
711- : "Set as default"
712- }
685+ className = "flex items-center justify-between gap-1"
713686 >
714- { isDefault ? (
715- < Star
716- fill = "#eab308"
717- stroke = "#eab308"
718- className = "size-4 text-yellow-500"
719- />
720- ) : (
721- < Star
722- fill = "none"
723- stroke = "currentColor"
724- className = "size-4 text-gray-400 group-hover:text-blue-500 transition-colors"
725- />
726- ) }
727- </ Button >
728- { org . ownerId === session ?. user ?. id && (
729- < >
730- < AddOrganization organizationId = { org . id } />
731- < DialogAction
732- title = "Delete Organization"
733- description = "Are you sure you want to delete this organization?"
734- type = "destructive"
735- onClick = { async ( ) => {
736- await deleteOrganization ( {
687+ < div className = "flex min-w-0 flex-1 items-center gap-2" >
688+ < div className = "flex size-6 shrink-0 items-center justify-center rounded-sm border" >
689+ < Logo
690+ className = { cn (
691+ "transition-all" ,
692+ state === "collapsed" ? "size-4" : "size-5" ,
693+ ) }
694+ logoUrl = { org . logo ?? undefined }
695+ />
696+ </ div >
697+ < span className = "truncate" > { org . name } </ span >
698+ </ div >
699+
700+ < div
701+ className = "flex shrink-0 items-center gap-2"
702+ onClick = { ( e ) => e . stopPropagation ( ) }
703+ onKeyDown = { ( e ) => e . stopPropagation ( ) }
704+ >
705+ < Button
706+ variant = "ghost"
707+ size = "icon"
708+ className = { cn (
709+ "group" ,
710+ isDefault
711+ ? "hover:bg-yellow-500/10"
712+ : "hover:bg-blue-500/10" ,
713+ ) }
714+ isLoading = { isSettingDefault && ! isDefault }
715+ disabled = { isDefault }
716+ onClick = { async ( e ) => {
717+ if ( isDefault ) return ;
718+ e . stopPropagation ( ) ;
719+ await setDefaultOrganization ( {
737720 organizationId : org . id ,
738721 } )
739722 . then ( ( ) => {
740723 refetch ( ) ;
741724 toast . success (
742- "Organization deleted successfully " ,
725+ "Default organization updated " ,
743726 ) ;
744727 } )
745728 . catch ( ( error ) => {
746729 toast . error (
747730 error ?. message ||
748- "Error deleting organization" ,
731+ "Error setting default organization" ,
749732 ) ;
750733 } ) ;
751734 } }
735+ title = {
736+ isDefault
737+ ? "Default organization"
738+ : "Set as default"
739+ }
752740 >
753- < Button
754- variant = "ghost"
755- size = "icon"
756- className = "group hover:bg-red-500/10"
757- isLoading = { isRemoving }
758- >
759- < Trash2 className = "size-4 text-primary group-hover:text-red-500" />
760- </ Button >
761- </ DialogAction >
762- </ >
763- ) }
764- </ div >
765- </ div >
766- ) ;
767- } ) }
768- </ div >
769- { ( user ?. role === "owner" ||
770- user ?. role === "admin" ||
771- isCloud ) && (
772- < >
773- < DropdownMenuSeparator />
774- < AddOrganization />
775- </ >
776- ) }
777- </ DropdownMenuContent >
778- </ DropdownMenu >
741+ { isDefault ? (
742+ < Star
743+ fill = "#eab308"
744+ stroke = "#eab308"
745+ className = "size-4 text-yellow-500"
746+ />
747+ ) : (
748+ < Star
749+ fill = "none"
750+ stroke = "currentColor"
751+ className = "size-4 text-gray-400 group-hover:text-blue-500 transition-colors"
752+ />
753+ ) }
754+ </ Button >
755+ { org . ownerId === session ?. user ?. id && (
756+ < >
757+ < AddOrganization organizationId = { org . id } />
758+ < DialogAction
759+ title = "Delete Organization"
760+ description = "Are you sure you want to delete this organization?"
761+ type = "destructive"
762+ onClick = { async ( ) => {
763+ await deleteOrganization ( {
764+ organizationId : org . id ,
765+ } )
766+ . then ( ( ) => {
767+ refetch ( ) ;
768+ toast . success (
769+ "Organization deleted successfully" ,
770+ ) ;
771+ } )
772+ . catch ( ( error ) => {
773+ toast . error (
774+ error ?. message ||
775+ "Error deleting organization" ,
776+ ) ;
777+ } ) ;
778+ } }
779+ >
780+ < Button
781+ variant = "ghost"
782+ size = "icon"
783+ className = "group hover:bg-red-500/10"
784+ isLoading = { isRemoving }
785+ >
786+ < Trash2 className = "size-4 text-primary group-hover:text-red-500" />
787+ </ Button >
788+ </ DialogAction >
789+ </ >
790+ ) }
791+ </ div >
792+ </ CommandItem >
793+ ) ;
794+ } ) }
795+ </ CommandGroup >
796+ </ CommandList >
797+ { ( user ?. role === "owner" ||
798+ user ?. role === "admin" ||
799+ isCloud ) && (
800+ < div className = "border-t p-1" >
801+ < AddOrganization />
802+ </ div >
803+ ) }
804+ </ Command >
805+ </ PopoverContent >
806+ </ Popover >
779807 </ SidebarMenuItem >
780808
781809 { /* Notification Bell */ }
0 commit comments