Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,170 @@
|
||||
import * as React from "react";
|
||||
import { ChevronsUpDown, Plus } from "~/components/ui/icons/vendor";
|
||||
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "~/components/ui/dropdown-menu";
|
||||
import { SidebarMenu, SidebarMenuButton, SidebarMenuItem, useSidebar } from "~/components/ui/sidebar";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useAppData } from "~/utils/data/useAppData";
|
||||
import { appPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { absolutePublicAppPath, isAbsoluteHttpUrl } from "~/utils/app/CrossHostUrls";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import { TenantSimple } from "~/utils/db/tenants.db.server";
|
||||
import clsx from "clsx";
|
||||
|
||||
|
||||
export function TeamSwitcher({ tenants, size = "md" }: { tenants: TenantSimple[]; size?: "sm" | "md" }) {
|
||||
const { t } = useTranslation();
|
||||
const { isMobile } = useSidebar();
|
||||
|
||||
const appData = useAppData();
|
||||
const rootData = useRootData();
|
||||
const canCreateAccount = true; // appData.isSuperUser;
|
||||
|
||||
const [activeTenant] = React.useState(appData?.currentTenant);
|
||||
|
||||
let activeTenantDescription = getTenantDescription({
|
||||
subscription: appData.mySubscription,
|
||||
types: appData.currentTenant.types,
|
||||
t,
|
||||
});
|
||||
const newAccountPath = absolutePublicAppPath(rootData.routing, "new-account");
|
||||
|
||||
return (
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<SidebarMenuButton
|
||||
size={size === "md" ? "lg" : "default"}
|
||||
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground h-11 select-none"
|
||||
>
|
||||
<div
|
||||
className={clsx(
|
||||
"flex aspect-square items-center justify-center rounded-lg",
|
||||
size === "sm" && "size-6",
|
||||
size === "md" && "text-foreground size-8"
|
||||
)}
|
||||
>
|
||||
{/* <activeTeam.logo className="size-4" /> */}
|
||||
{activeTenant.icon ? (
|
||||
<img className="size-6 shrink-0 rounded-md" src={activeTenant.icon} alt={activeTenant.name} />
|
||||
) : (
|
||||
<span className="bg-primary inline-flex size-6 shrink-0 items-center justify-center rounded-md">
|
||||
<span className="text-primary-foreground text-xs leading-none font-medium uppercase">{activeTenant.name.substring(0, 1)}</span>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="grid flex-1 text-left text-sm leading-tight">
|
||||
<span className="truncate font-semibold">{activeTenant.name}</span>
|
||||
{size === "md" && <span className="truncate text-xs">{activeTenantDescription}</span>}
|
||||
</div>
|
||||
<ChevronsUpDown className="ml-auto" />
|
||||
</SidebarMenuButton>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent
|
||||
className="bg-background w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg"
|
||||
align="start"
|
||||
side={isMobile ? "bottom" : "right"}
|
||||
sideOffset={4}
|
||||
>
|
||||
<DropdownMenuLabel className="text-xs">{t("models.tenant.plural")}</DropdownMenuLabel>
|
||||
{tenants.map((tenant) => (
|
||||
<DropdownMenuItem
|
||||
key={tenant.name}
|
||||
asChild
|
||||
>
|
||||
<a href={appPath({ tenantSlug: tenant.slug, path: "dashboard", mode: "host-aware" })} className="flex justify-between gap-2 truncate p-2">
|
||||
<div className="flex items-center gap-2 truncate">
|
||||
<div className="bg-background flex size-7 shrink-0 items-center justify-center overflow-hidden rounded-sm border">
|
||||
{/* <team.logo className="size-4 shrink-0" /> */}
|
||||
|
||||
{tenant.icon ? (
|
||||
<img className="size-7 shrink-0" src={tenant.icon} alt={tenant.name} />
|
||||
) : (
|
||||
<span className="inline-flex size-7 shrink-0 items-center justify-center rounded-md">
|
||||
<span className="text-xs leading-none font-medium uppercase">{tenant.name.substring(0, 1)}</span>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="truncate">
|
||||
<div className="text-foreground truncate text-sm">{tenant.name} </div>
|
||||
{/* {tenant.types.length > 0 && (
|
||||
<span className=" truncate text-xs">{getTenantDescription({ subscription: null, types: tenant.types, t })}</span>
|
||||
)} */}
|
||||
</div>
|
||||
</div>
|
||||
{/* <div className="shrink-0">
|
||||
<Button variant="ghost" size="icon">
|
||||
<Link to={appPath({ tenantSlug: tenant.slug, path: "dashboard", mode: "host-aware" })} target="_blank" onClick={(e) => e.stopPropagation()}>
|
||||
<ExternalLinkIcon className="size-3" />
|
||||
</Link>
|
||||
</Button>
|
||||
</div> */}
|
||||
</a>
|
||||
{/* <DropdownMenuShortcut>⌘{index + 1}</DropdownMenuShortcut> */}
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
{canCreateAccount && (
|
||||
<React.Fragment>
|
||||
<DropdownMenuSeparator />
|
||||
{isAbsoluteHttpUrl(newAccountPath) ? (
|
||||
<a href={newAccountPath}>
|
||||
<CreateAccountMenuItem label={t("app.tenants.create.title")} />
|
||||
</a>
|
||||
) : (
|
||||
<a href={newAccountPath}>
|
||||
<CreateAccountMenuItem label={t("app.tenants.create.title")} />
|
||||
</a>
|
||||
)}
|
||||
</React.Fragment>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
);
|
||||
}
|
||||
|
||||
function CreateAccountMenuItem({ label }: { label: string }) {
|
||||
return (
|
||||
<DropdownMenuItem className="gap-2 p-2">
|
||||
<div className="bg-background flex size-6 items-center justify-center rounded-md border">
|
||||
<Plus className="size-4" />
|
||||
</div>
|
||||
<div className="font-medium">{label}</div>
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
}
|
||||
|
||||
function getTenantDescription({
|
||||
subscription,
|
||||
types,
|
||||
t,
|
||||
}: {
|
||||
subscription: {
|
||||
products: { subscriptionProduct: { title: string } }[];
|
||||
} | null;
|
||||
types: { title: string }[];
|
||||
t: any;
|
||||
}) {
|
||||
void subscription;
|
||||
void types;
|
||||
void t;
|
||||
return "";
|
||||
// let activeTenantDescription = subscription?.products.length
|
||||
// ? t(subscription.products.find((f) => f)?.subscriptionProduct.title || "")
|
||||
// : t("settings.subscription.noSubscription");
|
||||
// if (!subscription || !subscription.products.length) {
|
||||
// // if (types.length > 0) {
|
||||
// // activeTenantDescription = t(types[0].title);
|
||||
// // }
|
||||
// }
|
||||
// return activeTenantDescription;
|
||||
}
|
||||
Reference in new issue
Block a user