fix: mobile unable to change org

This commit is contained in:
BennyKok 2024-01-18 21:53:56 +08:00
parent 7ebd05332c
commit f54d680e7e
2 changed files with 50 additions and 29 deletions

View File

@ -2,6 +2,11 @@
import { NavbarMenu } from "@/components/NavbarMenu"; import { NavbarMenu } from "@/components/NavbarMenu";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { import {
Sheet, Sheet,
SheetContent, SheetContent,
@ -9,13 +14,19 @@ import {
SheetTitle, SheetTitle,
SheetTrigger, SheetTrigger,
} from "@/components/ui/sheet"; } from "@/components/ui/sheet";
import { OrganizationSwitcher, UserButton } from "@clerk/nextjs"; import {
OrganizationList,
OrganizationSwitcher,
UserButton,
useOrganization,
} from "@clerk/nextjs";
import { Github, Menu } from "lucide-react"; import { Github, Menu } from "lucide-react";
import meta from "next-gen/config"; import meta from "next-gen/config";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useMediaQuery } from "usehooks-ts"; import { useMediaQuery } from "usehooks-ts";
export function Navbar() { export function Navbar() {
const { organization } = useOrganization();
const _isDesktop = useMediaQuery("(min-width: 1024px)"); const _isDesktop = useMediaQuery("(min-width: 1024px)");
const [isDesktop, setIsDesktop] = useState(true); const [isDesktop, setIsDesktop] = useState(true);
useEffect(() => { useEffect(() => {
@ -37,13 +48,24 @@ export function Navbar() {
</SheetHeader> </SheetHeader>
<div className="grid h-full grid-rows-[1fr_auto]"> <div className="grid h-full grid-rows-[1fr_auto]">
<NavbarMenu className=" h-full" /> <NavbarMenu className=" h-full" />
<OrganizationSwitcher {/* <OrganizationSwitcher
appearance={{ appearance={{
elements: { elements: {
rootBox: "flex items-center justify-center", rootBox: "flex items-center justify-center z-[50]",
}, },
}} }}
/> /> */}
<Popover>
<PopoverTrigger asChild>
<Button variant="outline">
Organization
{organization?.name && ` (${organization?.name})`}
</Button>
</PopoverTrigger>
<PopoverContent className="w-80 border-0 bg-none shadow-none">
<OrganizationList />
</PopoverContent>
</Popover>
</div> </div>
</SheetContent> </SheetContent>
</Sheet> </Sheet>

View File

@ -1,19 +1,18 @@
"use client" "use client";
import * as React from "react" import { cn } from "@/lib/utils";
import * as SheetPrimitive from "@radix-ui/react-dialog" import * as SheetPrimitive from "@radix-ui/react-dialog";
import { cva, type VariantProps } from "class-variance-authority" import { cva, type VariantProps } from "class-variance-authority";
import { X } from "lucide-react" import { X } from "lucide-react";
import * as React from "react";
import { cn } from "@/lib/utils" const Sheet = SheetPrimitive.Root;
const Sheet = SheetPrimitive.Root const SheetTrigger = SheetPrimitive.Trigger;
const SheetTrigger = SheetPrimitive.Trigger const SheetClose = SheetPrimitive.Close;
const SheetClose = SheetPrimitive.Close const SheetPortal = SheetPrimitive.Portal;
const SheetPortal = SheetPrimitive.Portal
const SheetOverlay = React.forwardRef< const SheetOverlay = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Overlay>, React.ElementRef<typeof SheetPrimitive.Overlay>,
@ -27,8 +26,8 @@ const SheetOverlay = React.forwardRef<
{...props} {...props}
ref={ref} ref={ref}
/> />
)) ));
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName SheetOverlay.displayName = SheetPrimitive.Overlay.displayName;
const sheetVariants = cva( const sheetVariants = cva(
"fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500", "fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
@ -47,7 +46,7 @@ const sheetVariants = cva(
side: "right", side: "right",
}, },
} }
) );
interface SheetContentProps interface SheetContentProps
extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>, extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>,
@ -71,8 +70,8 @@ const SheetContent = React.forwardRef<
</SheetPrimitive.Close> </SheetPrimitive.Close>
</SheetPrimitive.Content> </SheetPrimitive.Content>
</SheetPortal> </SheetPortal>
)) ));
SheetContent.displayName = SheetPrimitive.Content.displayName SheetContent.displayName = SheetPrimitive.Content.displayName;
const SheetHeader = ({ const SheetHeader = ({
className, className,
@ -85,8 +84,8 @@ const SheetHeader = ({
)} )}
{...props} {...props}
/> />
) );
SheetHeader.displayName = "SheetHeader" SheetHeader.displayName = "SheetHeader";
const SheetFooter = ({ const SheetFooter = ({
className, className,
@ -99,8 +98,8 @@ const SheetFooter = ({
)} )}
{...props} {...props}
/> />
) );
SheetFooter.displayName = "SheetFooter" SheetFooter.displayName = "SheetFooter";
const SheetTitle = React.forwardRef< const SheetTitle = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Title>, React.ElementRef<typeof SheetPrimitive.Title>,
@ -111,8 +110,8 @@ const SheetTitle = React.forwardRef<
className={cn("text-lg font-semibold text-foreground", className)} className={cn("text-lg font-semibold text-foreground", className)}
{...props} {...props}
/> />
)) ));
SheetTitle.displayName = SheetPrimitive.Title.displayName SheetTitle.displayName = SheetPrimitive.Title.displayName;
const SheetDescription = React.forwardRef< const SheetDescription = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Description>, React.ElementRef<typeof SheetPrimitive.Description>,
@ -123,8 +122,8 @@ const SheetDescription = React.forwardRef<
className={cn("text-sm text-muted-foreground", className)} className={cn("text-sm text-muted-foreground", className)}
{...props} {...props}
/> />
)) ));
SheetDescription.displayName = SheetPrimitive.Description.displayName SheetDescription.displayName = SheetPrimitive.Description.displayName;
export { export {
Sheet, Sheet,
@ -137,4 +136,4 @@ export {
SheetFooter, SheetFooter,
SheetTitle, SheetTitle,
SheetDescription, SheetDescription,
} };