import { Fragment, Ref, useState } from "react"; import { observer } from "mobx-react"; import Link from "next/link"; import { useParams } from "next/navigation"; import { usePopper } from "react-popper"; // icons import { Activity, Check, ChevronDown, LogOut, Mails, PlusSquare, Settings } from "lucide-react"; // ui import { Menu, Transition } from "@headlessui/react"; // types import { IWorkspace } from "@plane/types"; // plane ui import { Avatar, Loader, TOAST_TYPE, setToast } from "@plane/ui"; import { GOD_MODE_URL } from "@/helpers/common.helper"; // hooks import { useAppTheme, useUser, useUserProfile, useWorkspace } from "@/hooks/store"; import { WorkspaceLogo } from "./logo"; // Static Data const userLinks = (workspaceSlug: string) => [ { key: "workspace_invites", name: "Workspace invites", href: "/invitations", icon: Mails, }, { key: "settings", name: "Workspace settings", href: `/${workspaceSlug}/settings`, icon: Settings, }, ]; const profileLinks = (workspaceSlug: string, userId: string) => [ { name: "My activity", icon: Activity, link: `/${workspaceSlug}/profile/${userId}`, }, { name: "Settings", icon: Settings, link: "/profile", }, ]; export const WorkspaceSidebarDropdown = observer(() => { // router params const { workspaceSlug } = useParams(); // store hooks const { sidebarCollapsed, toggleSidebar } = useAppTheme(); const { data: currentUser } = useUser(); const { // updateCurrentUser, // isUserInstanceAdmin, signOut, } = useUser(); const { updateUserProfile } = useUserProfile(); const isUserInstanceAdmin = false; const { currentWorkspace: activeWorkspace, workspaces } = useWorkspace(); // popper-js refs const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); // popper-js init const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: "right", modifiers: [ { name: "preventOverflow", options: { padding: 12, }, }, ], }); const handleWorkspaceNavigation = (workspace: IWorkspace) => updateUserProfile({ last_workspace_id: workspace?.id, }); const handleSignOut = async () => { await signOut().catch(() => setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Failed to sign out. Please try again.", }) ); }; const handleItemClick = () => { if (window.innerWidth < 768) { toggleSidebar(); } }; const workspacesList = Object.values(workspaces ?? {}); // TODO: fix workspaces list scroll return (
{({ open }) => ( <>
{!sidebarCollapsed && (

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

)}
{!sidebarCollapsed && (
{currentUser?.email}
{workspacesList ? (
{workspacesList.length > 0 && workspacesList.map((workspace) => ( { handleWorkspaceNavigation(workspace); handleItemClick(); }} className="w-full" >
{workspace?.logo && workspace.logo !== "" ? ( Workspace Logo ) : ( workspace?.name?.charAt(0) ?? "..." )}
{workspace.name}
{workspace.id === activeWorkspace?.id && ( )}
))}
) : (
)}
Create workspace {userLinks(workspaceSlug?.toString() ?? "").map((link, index) => ( { if (index > 0) handleItemClick(); }} > {link.name} ))}
Sign out
)}
{!sidebarCollapsed && ( } style={styles.popper} {...attributes.popper} >
{currentUser?.email} {profileLinks(workspaceSlug?.toString() ?? "", currentUser?.id ?? "").map((link, index) => ( { if (index == 0) handleItemClick(); }} > {link.name} ))}
Sign out
{isUserInstanceAdmin && (
Enter God Mode
)}
)}
); });