2024-04-01 17:31:31 +02:00
|
|
|
import {
|
|
|
|
Tooltip,
|
|
|
|
TooltipContent,
|
|
|
|
TooltipTrigger,
|
|
|
|
} from "@/components/ui/tooltip";
|
2024-08-09 15:26:26 +02:00
|
|
|
import { baseUrl } from "../../api/baseUrl";
|
2024-05-07 16:00:25 +02:00
|
|
|
import { cn } from "@/lib/utils";
|
2024-05-06 19:18:28 +02:00
|
|
|
import { TooltipPortal } from "@radix-ui/react-tooltip";
|
2024-04-16 22:55:24 +02:00
|
|
|
import { isDesktop } from "react-device-detect";
|
2024-04-01 17:31:31 +02:00
|
|
|
import { VscAccount } from "react-icons/vsc";
|
2024-05-18 18:36:13 +02:00
|
|
|
import {
|
|
|
|
DropdownMenu,
|
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuItem,
|
|
|
|
DropdownMenuLabel,
|
|
|
|
DropdownMenuSeparator,
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
} from "../ui/dropdown-menu";
|
|
|
|
import { Drawer, DrawerContent, DrawerTrigger } from "../ui/drawer";
|
|
|
|
import { DialogClose } from "../ui/dialog";
|
|
|
|
import { LuLogOut } from "react-icons/lu";
|
|
|
|
import useSWR from "swr";
|
2024-04-01 17:31:31 +02:00
|
|
|
|
2024-04-29 17:59:27 +02:00
|
|
|
type AccountSettingsProps = {
|
|
|
|
className?: string;
|
|
|
|
};
|
|
|
|
export default function AccountSettings({ className }: AccountSettingsProps) {
|
2024-05-18 18:36:13 +02:00
|
|
|
const { data: profile } = useSWR("profile");
|
|
|
|
const { data: config } = useSWR("config");
|
2024-08-09 15:26:26 +02:00
|
|
|
const logoutUrl = config?.proxy?.logout_url || `${baseUrl}api/logout`;
|
2024-05-18 18:36:13 +02:00
|
|
|
|
|
|
|
const Container = isDesktop ? DropdownMenu : Drawer;
|
|
|
|
const Trigger = isDesktop ? DropdownMenuTrigger : DrawerTrigger;
|
|
|
|
const Content = isDesktop ? DropdownMenuContent : DrawerContent;
|
|
|
|
const MenuItem = isDesktop ? DropdownMenuItem : DialogClose;
|
|
|
|
|
2024-04-01 17:31:31 +02:00
|
|
|
return (
|
2024-05-30 15:39:14 +02:00
|
|
|
<Container modal={!isDesktop}>
|
2024-05-19 01:09:55 +02:00
|
|
|
<Trigger>
|
2024-05-18 22:19:32 +02:00
|
|
|
<Tooltip>
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
<div
|
|
|
|
className={cn(
|
|
|
|
"flex flex-col items-center justify-center",
|
|
|
|
isDesktop
|
|
|
|
? "cursor-pointer rounded-lg bg-secondary text-secondary-foreground hover:bg-muted"
|
|
|
|
: "text-secondary-foreground",
|
|
|
|
className,
|
|
|
|
)}
|
2024-05-18 18:36:13 +02:00
|
|
|
>
|
2024-05-18 22:19:32 +02:00
|
|
|
<VscAccount className="size-5 md:m-[6px]" />
|
|
|
|
</div>
|
|
|
|
</TooltipTrigger>
|
|
|
|
<TooltipPortal>
|
|
|
|
<TooltipContent side="right">
|
|
|
|
<p>Account</p>
|
|
|
|
</TooltipContent>
|
|
|
|
</TooltipPortal>
|
|
|
|
</Tooltip>
|
|
|
|
</Trigger>
|
|
|
|
<Content
|
|
|
|
className={
|
|
|
|
isDesktop ? "mr-5 w-72" : "max-h-[75dvh] overflow-hidden p-2"
|
|
|
|
}
|
|
|
|
>
|
2024-06-03 20:43:30 +02:00
|
|
|
<div className="scrollbar-container w-full flex-col overflow-y-auto overflow-x-hidden">
|
2024-05-18 22:19:32 +02:00
|
|
|
<DropdownMenuLabel>
|
|
|
|
Current User: {profile?.username || "anonymous"}
|
|
|
|
</DropdownMenuLabel>
|
|
|
|
<DropdownMenuSeparator className={isDesktop ? "mt-3" : "mt-1"} />
|
|
|
|
<MenuItem
|
|
|
|
className={
|
|
|
|
isDesktop ? "cursor-pointer" : "flex items-center p-2 text-sm"
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<a className="flex" href={logoutUrl}>
|
|
|
|
<LuLogOut className="mr-2 size-4" />
|
|
|
|
<span>Logout</span>
|
|
|
|
</a>
|
|
|
|
</MenuItem>
|
|
|
|
</div>
|
|
|
|
</Content>
|
|
|
|
</Container>
|
2024-04-01 17:31:31 +02:00
|
|
|
);
|
|
|
|
}
|