import { Fragment } from "react"; import { useRouter } from "next/router"; import Link from "next/link"; // headless ui import { Menu, Transition } from "@headlessui/react"; // next-themes import { useTheme } from "next-themes"; // hooks import useUser from "hooks/use-user"; import useWorkspaces from "hooks/use-workspaces"; import useToast from "hooks/use-toast"; // services import { UserService } from "services/user.service"; import { AuthService } from "services/auth.service"; // components import { Avatar, Icon } from "components/ui"; import { Loader } from "@plane/ui"; // icons import { CheckIcon, PlusIcon } from "@heroicons/react/24/outline"; // helpers import { truncateText } from "helpers/string.helper"; // types import { IWorkspace } from "types"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // Static Data const userLinks = (workspaceSlug: string, userId: string) => [ { name: "Workspace Settings", href: `/${workspaceSlug}/settings`, }, { name: "Workspace Invites", href: "/invitations", }, { name: "My Profile", href: `/${workspaceSlug}/profile/${userId}`, }, ]; const profileLinks = (workspaceSlug: string, userId: string) => [ { name: "View profile", icon: "account_circle", link: `/${workspaceSlug}/profile/${userId}`, }, { name: "Settings", icon: "settings", link: `/${workspaceSlug}/me/profile`, }, ]; const userService = new UserService(); const authService = new AuthService(); export const WorkspaceSidebarDropdown = () => { const store: any = useMobxStore(); const router = useRouter(); const { workspaceSlug } = router.query; const { user, mutateUser } = useUser(); const { setTheme } = useTheme(); const { setToastAlert } = useToast(); const { activeWorkspace, workspaces } = useWorkspaces(); const handleWorkspaceNavigation = (workspace: IWorkspace) => { userService .updateUser({ last_workspace_id: workspace?.id, }) .then(() => { mutateUser(); router.push(`/${workspace.slug}/`); }) .catch(() => setToastAlert({ type: "error", title: "Error!", message: "Failed to navigate to the workspace. Please try again.", }) ); }; const handleSignOut = async () => { await authService .signOut() .then(() => { mutateUser(undefined); router.push("/"); setTheme("system"); }) .catch(() => setToastAlert({ type: "error", title: "Error!", message: "Failed to sign out. Please try again.", }) ); }; return (