// "use client"; // import * as React from "react"; // import Link from "next/link"; // import { useRouter } from "next/navigation"; // import { api } from "@/trpc/client"; // import { useOrganization, useOrganizationList, useUser } from "@clerk/nextjs"; // import { toDecimal } from "dinero.js"; // import { Check, ChevronDown, ChevronsUpDown, PlusCircle } from "lucide-react"; // import { env } from "@projectx/stripe/env"; // import type { ExtendedPlanInfo, PlansResponse } from "@projectx/stripe/plans"; // import type { PurchaseOrg } from "@projectx/validators"; // import { purchaseOrgSchema } from "@projectx/validators"; // import { currencySymbol } from "@/lib/currency"; // import { cn } from "@/lib/utils"; // import { useZodForm } from "@/lib/zod-form"; // import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; // import { Button } from "@/components/ui/button"; // import { // Command, // CommandGroup, // CommandInput, // CommandItem, // CommandList, // CommandSeparator, // } from "@/components/ui/command"; // import { // Dialog, // DialogContent, // DialogDescription, // DialogFooter, // DialogHeader, // DialogTitle, // DialogTrigger, // } from "@/components/ui/dialog"; // import { // Form, // FormControl, // FormField, // FormItem, // FormLabel, // FormMessage, // } from "@/components/ui/form"; // import { Input } from "@/components/ui/input"; // import { // Popover, // PopoverContent, // PopoverTrigger, // } from "@/components/ui/popover"; // import { // Select, // SelectContent, // SelectItem, // SelectTrigger, // SelectValue, // } from "@/components/ui/select"; // import { useToast } from "@/components/ui/use-toast"; // type WorkspaceSwitcherProps = { // isCollapsed: boolean; // }; // export function WorkspaceSwitcher({ isCollapsed }: WorkspaceSwitcherProps) { // const router = useRouter(); // const [switcherOpen, setSwitcherOpen] = React.useState(false); // const [newOrgDialogOpen, setNewOrgDialogOpen] = React.useState(false); // const orgs = useOrganizationList({ // userMemberships: { // infinite: true, // }, // }); // const org = useOrganization(); // const { user, isSignedIn, isLoaded } = useUser(); // if (isLoaded && !isSignedIn) throw new Error("How did you get here???"); // const activeOrg = org.organization ?? user; // if ( // !orgs.isLoaded || // !org.isLoaded || // !activeOrg || // orgs.userMemberships.isLoading // ) { // // Skeleton loader // return ( // // // Ac // // // Select a workspace // // // // ); // } // const normalizedObject = { // id: activeOrg.id, // name: "name" in activeOrg ? activeOrg.name : activeOrg.fullName, // image: activeOrg.imageUrl, // }; // return ( // // // // span]:line-clamp-1 [&>span]:flex [&>span]:w-full [&>span]:items-center [&>span]:gap-1 [&>span]:truncate [&_svg]:h-4 [&_svg]:w-4 [&_svg]:shrink-0", // isCollapsed && // "flex h-9 w-9 shrink-0 items-center justify-center p-0 [&>span]:w-auto [&>svg]:hidden", // )} // > // // // // // {normalizedObject.name?.substring(0, 2)} // // // // {normalizedObject.name} // // // // // // // // // // // { // if (!user?.id) return; // normalizedObject.id = user.id ?? ""; // await orgs.setActive?.({ organization: null }); // setSwitcherOpen(false); // router.push(`/${user.id}`); // }} // className="cursor-pointer text-sm" // > // // // // {`${user?.firstName?.[0]}${user?.lastName?.[0]}` ?? "JD"} // // // {user?.fullName} // // // // // {orgs.userMemberships.data?.map(({ organization: org }) => ( // { // await orgs.setActive({ organization: org }); // setSwitcherOpen(false); // router.push(`/${org.id}`); // }} // className="cursor-pointer text-sm" // > // // // // {org.name.substring(0, 2)} // // // {org.name} // // // ))} // // // // // // // { // setSwitcherOpen(false); // setNewOrgDialogOpen(true); // }} // className="cursor-pointer" // > // // Create Organization // // // // // // // // // setNewOrgDialogOpen(false)} /> // // // ); // } // function NewOrganizationDialog(props: { closeDialog: () => void }) { // const useStripe = env.USE_STRIPE === "true"; // let plans: any | null = null; // if (useStripe) { // plans = api.stripe.plans.query(); // } // const form = useZodForm({ schema: purchaseOrgSchema }); // const toaster = useToast(); // async function handleCreateOrg(data: PurchaseOrg) { // const response = await api.stripe.purchaseOrg // .mutate(data) // .catch(() => ({ success: false as const })); // if (response?.success) window.location.href = response.url as string; // else // toaster.toast({ // title: "Error", // description: // "There was an error setting up your organization. Please try again.", // variant: "destructive", // }); // } // return ( // // // // // Create organization // // Add a new organization to manage products and customers. // // // ( // // Organization name * // // // // // // )} // /> // {useStripe && ( // ( // // // Subscription plan * // // What's included in each plan? // // // // // // // // // // {plans?.map((plan: ExtendedPlanInfo) => ( // // {plan.name} -{" "} // // {toDecimal( // plan.price, // ({ value, currency }) => // `${currencySymbol(currency.code)}${value}`, // )}{" "} // per month // // // ))} // // // // // )} // /> // )} // // props.closeDialog()}> // Cancel // // Continue // // // // // ); // }