"use client"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@app/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger } from "@app/components/ui/popover"; import { cn } from "@app/lib/cn"; import { ListUserOrgsResponse } from "@server/routers/org"; import { Check, ChevronDown, ChevronsUpDown } from "lucide-react"; import { usePathname, useRouter } from "next/navigation"; import { useMemo, useState } from "react"; import { useTranslations } from "next-intl"; import { Button } from "@app/components/ui/button"; type LauncherOrgSelectorProps = { orgId?: string; orgs?: ListUserOrgsResponse["orgs"]; }; export function LauncherOrgSelector({ orgId, orgs }: LauncherOrgSelectorProps) { const [open, setOpen] = useState(false); const router = useRouter(); const pathname = usePathname(); const t = useTranslations(); const selectedOrg = orgs?.find((org) => org.orgId === orgId); const sortedOrgs = useMemo(() => { if (!orgs?.length) { return orgs ?? []; } return [...orgs].sort((a, b) => { const aPrimary = Boolean(a.isPrimaryOrg); const bPrimary = Boolean(b.isPrimaryOrg); if (aPrimary && !bPrimary) { return -1; } if (!aPrimary && bPrimary) { return 1; } return 0; }); }, [orgs]); return ( {t("orgNotFound2")} {sortedOrgs.map((org) => ( { setOpen(false); const newPath = pathname.includes( "/settings/" ) ? pathname.replace( /^\/[^/]+/, `/${org.orgId}` ) : `/${org.orgId}`; router.push(newPath); }} >
{org.name} {org.orgId}
))}
); }