From 1760c1b8525a97bb6baf4fa0ab7723bd297e6fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20LAGACHE?= <43389096+Asuniia@users.noreply.github.com> Date: Wed, 28 Jan 2026 13:51:14 +0100 Subject: [PATCH] update: new org combobox --- .../organization/organization-combobox.tsx | 183 ++++++++++++++---- 1 file changed, 143 insertions(+), 40 deletions(-) diff --git a/src/components/wrappers/dashboard/organization/organization-combobox.tsx b/src/components/wrappers/dashboard/organization/organization-combobox.tsx index 1a816bc8..e6686fb0 100644 --- a/src/components/wrappers/dashboard/organization/organization-combobox.tsx +++ b/src/components/wrappers/dashboard/organization/organization-combobox.tsx @@ -1,29 +1,39 @@ "use client" -import {ComboBox} from "@/components/wrappers/common/combobox"; -import {useSidebar} from "@/components/ui/sidebar"; -import {useRouter} from "next/navigation"; -import {authClient} from "@/lib/auth/auth-client"; -import {CreateOrganizationModal} from "@/components/wrappers/dashboard/organization/create-organisation-modal"; -import {useState} from "react"; + +import * as React from "react" +import { Building2, Check, ChevronsUpDown, Plus } from "lucide-react" +import { useRouter } from "next/navigation" +import { authClient } from "@/lib/auth/auth-client" +import { cn } from "@/lib/utils" + +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuSeparator, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu" +import { + SidebarMenuButton, + useSidebar, +} from "@/components/ui/sidebar" +import { CreateOrganizationModal } from "@/components/wrappers/dashboard/organization/create-organisation-modal" +import { Skeleton } from "@/components/ui/skeleton" export function OrganizationCombobox() { - const router = useRouter(); - const {state} = useSidebar(); - const {data: organizations, refetch} = authClient.useListOrganizations(); - const {data: activeOrganization, refetch: refetchActiveOrga} = authClient.useActiveOrganization(); - const [openModal, setOpenModal] = useState(false); + const router = useRouter() + const { isMobile, state } = useSidebar() + const { data: organizations, isPending: isPendingList, refetch } = authClient.useListOrganizations() + const { data: activeOrganization, isPending: isPendingActive, refetch: refetchActiveOrga } = authClient.useActiveOrganization() + const [openModal, setOpenModal] = React.useState(false) + const [isOpen, setIsOpen] = React.useState(false) - // if (!organizations) return null; - - // const values = organizations.map(org => ({ value: org.slug, label: org.name })); - const values = organizations?.map(org => ({ value: org.slug, label: org.name })) ?? []; - - - - const onValueChange = async (slug: string) => { - await authClient.organization.setActive({ organizationSlug: slug }); - router.refresh(); - }; + const handleSelect = async (slug: string) => { + if (activeOrganization?.slug === slug) return + await authClient.organization.setActive({ organizationSlug: slug }) + router.refresh() + setIsOpen(false) + } const handleReload = () => { refetch(); @@ -31,23 +41,116 @@ export function OrganizationCombobox() { router.refresh(); }; - return ( - <> - - {state === "expanded" && ( - setOpenModal(true)} - addItemLabel="Create new organization" + const orgs = organizations || [] + + if (isPendingList || isPendingActive) { + return ( + + +
+ + +
+ +
+ ) + } + + + + return ( + <> + - )} + + + +
+ {activeOrganization?.logo ? ( + {activeOrganization.name} + ) : ( + + )} +
+
+ + {activeOrganization?.name || "Select Organization"} + +
+ +
+
+ + {orgs.map((org) => { + const isActive = activeOrganization?.id === org.id; + return ( + handleSelect(org.slug)} + className={cn( + "group gap-1 p-1 cursor-pointer rounded-lg mb-1 last:mb-0 transition-colors", + isActive + ? "bg-orange-500/10 text-orange-600 dark:text-orange-400 border border-orange-500/20" + : "focus:bg-accent hover:bg-accent/50 border border-transparent" + )}> +
+ {org.logo ? ( + {org.name} + ) : ( + + )} +
+
+ {org.name} +
+ {isActive && ( +
+ +
+ )} +
+ ) + })} + + setOpenModal(true)} + > +
+ +
+
Create new organization
+
+
+
- ); -} + ) +} \ No newline at end of file