import { Fragment } from "react"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import Link from "next/link"; import { Menu, Transition } from "@headlessui/react"; import { useTheme } from "next-themes"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // hooks import useUser from "hooks/use-user"; import useToast from "hooks/use-toast"; // services import { UserService } from "services/user.service"; import { AuthService } from "services/auth.service"; // components import { Avatar } from "components/ui"; import { Loader } from "@plane/ui"; // icons import { Check, LogOut, Plus, Settings, UserCircle2 } from "lucide-react"; // types import { IWorkspace } from "types"; // 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: UserCircle2, link: `/${workspaceSlug}/profile/${userId}`, }, { name: "Settings", icon: Settings, link: `/${workspaceSlug}/me/profile`, }, ]; const userService = new UserService(); const authService = new AuthService(); export const WorkspaceSidebarDropdown = observer(() => { const router = useRouter(); const { workspaceSlug } = router.query; const { theme: themeStore, workspace: workspaceStore } = useMobxStore(); const { workspaces, currentWorkspace: activeWorkspace } = workspaceStore; const { user, mutateUser } = useUser(); const { setTheme } = useTheme(); const { setToastAlert } = useToast(); 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 (
{activeWorkspace?.logo && activeWorkspace.logo !== "" ? ( Workspace Logo ) : ( activeWorkspace?.name?.charAt(0) ?? "..." )}
{!themeStore.sidebarCollapsed && (

{activeWorkspace?.name ? activeWorkspace.name : "Loading..."}

)}
Workspace {workspaces ? (
{workspaces.length > 0 ? ( workspaces.map((workspace: IWorkspace) => ( {() => ( )} )) ) : (

No workspace found!

)} { router.push("/create-workspace"); }} className="flex w-full items-center gap-2 px-2 py-1 text-sm text-custom-sidebar-text-200 hover:bg-custom-sidebar-background-80" > Create Workspace
) : (
)}
{userLinks(workspaceSlug?.toString() ?? "", user?.id ?? "").map((link, index) => ( {link.name} ))}
Sign out
{!themeStore.sidebarCollapsed && (
{user?.email} {profileLinks(workspaceSlug?.toString() ?? "", user?.id ?? "").map((link, index) => ( {link.name} ))}
Sign out
)}
); });