import { Fragment } from "react"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import Link from "next/link"; import { useTheme } from "next-themes"; import { Menu, Transition } from "@headlessui/react"; import { mutate } from "swr"; import { Check, ChevronDown, CircleUserRound, LogOut, Mails, PlusSquare, Settings, UserCircle2 } from "lucide-react"; // hooks import { useApplication, useUser, useWorkspace } from "hooks/store"; // hooks import useToast from "hooks/use-toast"; // ui import { Avatar, Loader } from "@plane/ui"; // types import { IWorkspace } from "@plane/types"; // Static Data const userLinks = (workspaceSlug: string, userId: string) => [ { key: "workspace_invites", name: "Workspace invites", href: "/invitations", icon: Mails, }, { key: "view_profile", name: "View profile", href: `/${workspaceSlug}/profile/${userId}`, icon: CircleUserRound, }, { key: "settings", name: "Settings", href: `/${workspaceSlug}/settings`, icon: Settings, }, ]; const profileLinks = (workspaceSlug: string, userId: string) => [ { name: "View profile", icon: UserCircle2, link: `/${workspaceSlug}/profile/${userId}`, }, { name: "Settings", icon: Settings, link: "/profile", }, ]; export const WorkspaceSidebarDropdown = observer(() => { // router const router = useRouter(); const { workspaceSlug } = router.query; // store hooks const { theme: { sidebarCollapsed, toggleSidebar }, eventTracker: { setTrackElement }, } = useApplication(); const { currentUser, updateCurrentUser, isUserInstanceAdmin, signOut } = useUser(); const { currentWorkspace: activeWorkspace, workspaces } = useWorkspace(); // hooks const { setToastAlert } = useToast(); const { setTheme } = useTheme(); const handleWorkspaceNavigation = (workspace: IWorkspace) => updateCurrentUser({ last_workspace_id: workspace?.id, }); const handleSignOut = async () => { await signOut() .then(() => { mutate("CURRENT_USER_DETAILS", null); setTheme("system"); router.push("/"); }) .catch(() => setToastAlert({ type: "error", title: "Error!", message: "Failed to sign out. Please try again.", }) ); }; const handleItemClick = () => { console.log('CLICKED') if (window.innerWidth < 768) { toggleSidebar(); } }; const workspacesList = Object.values(workspaces ?? {}); // TODO: fix workspaces list scroll return (