import { useState } from "react"; import Link from "next/link"; import { useRouter } from "next/router"; import { DraggableProvided, DraggableStateSnapshot } from "react-beautiful-dnd"; import { Disclosure, Transition } from "@headlessui/react"; import { observer } from "mobx-react-lite"; // icons import { MoreVertical, PenSquare, LinkIcon, Star, Trash2, FileText, Settings, Share2, LogOut, ChevronDown, } 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, DeleteProjectModal, PublishProjectModal } from "components/project"; 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) => { const { project, provided, snapshot, handleCopyText, shortContextMenu = false } = props; // store const { project: projectStore, theme: themeStore } = useMobxStore(); // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // toast const { setToastAlert } = useToast(); // states const [leaveProjectModalOpen, setLeaveProjectModal] = useState(false); const [deleteProjectModalOpen, setDeleteProjectModal] = useState(false); const [publishModalOpen, setPublishModal] = useState(false); const isAdmin = project.member_role === 20; const isViewerOrGuest = project.member_role === 10 || project.member_role === 5; const isCollapsed = themeStore.sidebarCollapsed; 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 = () => { setLeaveProjectModal(true); }; const handleLeaveProjectModalClose = () => { setLeaveProjectModal(false); }; const handleDeleteProjectClick = () => { setDeleteProjectModal(true); }; const handleDeleteProjectModalClose = () => { setDeleteProjectModal(false); router.push(`/${workspaceSlug}/projects`); }; 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 && ( {!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 && ( router.push(`/${workspaceSlug}/projects/${project?.id}/archived-issues/`)} >
Archived Issues
)} router.push(`/${workspaceSlug}/projects/${project?.id}/draft-issues`)} >
Draft Issues
router.push(`/${workspaceSlug}/projects/${project?.id}/settings`)} >
Settings
{/* leave project */} {isViewerOrGuest && (
Leave Project
)} {!shortContextMenu && isAdmin && ( Delete 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}
); })}
)}
); });