"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, Plus } 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"; import { useEnvContext } from "@app/hooks/useEnvContext"; import { useUserContext } from "@app/hooks/useUserContext"; import { build } from "@server/build"; 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 { env } = useEnvContext(); const { user } = useUserContext(); const selectedOrg = orgs?.find((org) => org.orgId === orgId); let canCreateOrg = !env.flags.disableUserCreateOrg || user.serverAdmin; if (build === "saas" && user.type !== "internal") { canCreateOrg = false; } 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}
))}
{canCreateOrg && (
)}
); }