import { useRef, useState } from "react"; import Link from "next/link"; import { useRouter } from "next/router"; import { DraggableProvided, DraggableStateSnapshot } from "@hello-pangea/dnd"; import { Disclosure, Transition } from "@headlessui/react"; import { observer } from "mobx-react-lite"; // icons import { MoreVertical, PenSquare, LinkIcon, Star, FileText, Settings, Share2, LogOut, ChevronDown, MoreHorizontal, } from "lucide-react"; // hooks import useToast from "hooks/use-toast"; // helpers import { renderEmoji } from "helpers/emoji.helper"; // types import { IProject } from "types"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // components import { CustomMenu, Tooltip, ArchiveIcon, PhotoFilterIcon, DiceIcon, ContrastIcon, LayersIcon } from "@plane/ui"; import { LeaveProjectModal, PublishProjectModal } from "components/project"; import useOutsideClickDetector from "hooks/use-outside-click-detector"; type Props = { project: IProject; provided?: DraggableProvided; snapshot?: DraggableStateSnapshot; handleCopyText: () => void; shortContextMenu?: boolean; }; const navigation = (workspaceSlug: string, projectId: string) => [ { name: "Issues", href: `/${workspaceSlug}/projects/${projectId}/issues`, Icon: LayersIcon, }, { name: "Cycles", href: `/${workspaceSlug}/projects/${projectId}/cycles`, Icon: ContrastIcon, }, { name: "Modules", href: `/${workspaceSlug}/projects/${projectId}/modules`, Icon: DiceIcon, }, { name: "Views", href: `/${workspaceSlug}/projects/${projectId}/views`, Icon: PhotoFilterIcon, }, { name: "Pages", href: `/${workspaceSlug}/projects/${projectId}/pages`, Icon: FileText, }, { name: "Settings", href: `/${workspaceSlug}/projects/${projectId}/settings`, Icon: Settings, }, ]; export const ProjectSidebarListItem: React.FC = observer((props) => { // eslint-disable-next-line @typescript-eslint/no-unused-vars const { project, provided, snapshot, handleCopyText, shortContextMenu = false } = props; // store const { project: projectStore, theme: themeStore, trackEvent: { setTrackElement }, } = useMobxStore(); // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // toast const { setToastAlert } = useToast(); // states const [leaveProjectModalOpen, setLeaveProjectModal] = useState(false); const [publishModalOpen, setPublishModal] = useState(false); const [isMenuActive, setIsMenuActive] = useState(false); const isAdmin = project.member_role === 20; const isViewerOrGuest = project.member_role === 10 || project.member_role === 5; const isCollapsed = themeStore.sidebarCollapsed; const actionSectionRef = useRef(null); const handleAddToFavorites = () => { if (!workspaceSlug) return; projectStore.addProjectToFavorites(workspaceSlug.toString(), project.id).catch(() => { setToastAlert({ type: "error", title: "Error!", message: "Couldn't remove the project from favorites. Please try again.", }); }); }; const handleRemoveFromFavorites = () => { if (!workspaceSlug) return; projectStore.removeProjectFromFavorites(workspaceSlug.toString(), project.id).catch(() => { setToastAlert({ type: "error", title: "Error!", message: "Couldn't remove the project from favorites. Please try again.", }); }); }; const handleLeaveProject = () => { setTrackElement("APP_SIDEBAR_PROJECT_DROPDOWN"); setLeaveProjectModal(true); }; const handleLeaveProjectModalClose = () => { setLeaveProjectModal(false); }; useOutsideClickDetector(actionSectionRef, () => setIsMenuActive(false)); return ( <> setPublishModal(false)} /> {({ open }) => ( <>
{provided && ( )}
{project.emoji ? ( {renderEmoji(project.emoji)} ) : project.icon_prop ? (
{renderEmoji(project.icon_prop)}
) : ( {project?.name.charAt(0)} )} {!isCollapsed &&

{project.name}

}
{!isCollapsed && ( )}
{!isCollapsed && ( setIsMenuActive(!isMenuActive)} >
} className={`hidden flex-shrink-0 group-hover:block ${isMenuActive ? "!block" : ""}`} buttonClassName="!text-custom-sidebar-text-400 hover:text-custom-sidebar-text-400" ellipsis placement="bottom-start" > {!project.is_favorite && ( Add to favorites )} {project.is_favorite && ( Remove from favorites )} Copy project link {/* publish project settings */} {isAdmin && ( setPublishModal(true)}>
{project.is_deployed ? "Publish settings" : "Publish"}
)} {project.archive_in > 0 && (
Archived Issues
)}
Draft Issues
Settings
{/* leave project */} {isViewerOrGuest && (
Leave project
)} )} {navigation(workspaceSlug as string, project?.id).map((item) => { if ( (item.name === "Cycles" && !project.cycle_view) || (item.name === "Modules" && !project.module_view) || (item.name === "Views" && !project.issue_views_view) || (item.name === "Pages" && !project.page_view) ) return; return (
{!isCollapsed && item.name}
); })}
)}
); });