import { useState } from "react"; import { observer } from "mobx-react"; import { useRouter } from "next/router"; // icons import { ArchiveRestoreIcon, ExternalLink, Link, Trash2 } from "lucide-react"; // ui import { ContextMenu, CustomMenu, TContextMenuItem, TOAST_TYPE, setToast } from "@plane/ui"; // components import { DeleteIssueModal } from "@/components/issues"; // constants import { EIssuesStoreType } from "@/constants/issue"; import { EUserProjectRoles } from "@/constants/project"; // helpers import { cn } from "@/helpers/common.helper"; import { copyUrlToClipboard } from "@/helpers/string.helper"; // hooks import { useEventTracker, useIssues, useUser } from "@/hooks/store"; // types import { IQuickActionProps } from "../list/list-view-types"; export const ArchivedIssueQuickActions: React.FC = observer((props) => { const { issue, handleDelete, handleRestore, customActionButton, portalElement, readOnly = false, placements = "bottom-end", parentRef, } = props; // states const [deleteIssueModal, setDeleteIssueModal] = useState(false); // router const router = useRouter(); const { workspaceSlug } = router.query; // store hooks const { membership: { currentProjectRole }, } = useUser(); const { setTrackElement } = useEventTracker(); const { issuesFilter } = useIssues(EIssuesStoreType.ARCHIVED); // derived values const activeLayout = `${issuesFilter.issueFilters?.displayFilters?.layout} layout`; // auth const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER && !readOnly; const isRestoringAllowed = handleRestore && isEditingAllowed; const issueLink = `${workspaceSlug}/projects/${issue.project_id}/archives/issues/${issue.id}`; const handleOpenInNewTab = () => window.open(`/${issueLink}`, "_blank"); const handleCopyIssueLink = () => copyUrlToClipboard(issueLink).then(() => setToast({ type: TOAST_TYPE.SUCCESS, title: "Link copied", message: "Issue link copied to clipboard", }) ); const handleIssueRestore = async () => { if (!handleRestore) return; await handleRestore() .then(() => { setToast({ type: TOAST_TYPE.SUCCESS, title: "Restore success", message: "Your issue can be found in project issues.", }); }) .catch(() => { setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Issue could not be restored. Please try again.", }); }); }; const MENU_ITEMS: TContextMenuItem[] = [ { key: "restore", title: "Restore", icon: ArchiveRestoreIcon, action: handleIssueRestore, shouldRender: isRestoringAllowed, }, { key: "open-in-new-tab", title: "Open in new tab", icon: ExternalLink, action: handleOpenInNewTab, }, { key: "copy-link", title: "Copy link", icon: Link, action: handleCopyIssueLink, }, { key: "delete", title: "Delete", icon: Trash2, action: () => { setTrackElement(activeLayout); setDeleteIssueModal(true); }, shouldRender: isEditingAllowed, }, ]; return ( <> setDeleteIssueModal(false)} onSubmit={handleDelete} /> {MENU_ITEMS.map((item) => { if (item.shouldRender === false) return null; return ( { e.preventDefault(); e.stopPropagation(); item.action(); }} className={cn( "flex items-center gap-2", { "text-custom-text-400": item.disabled, }, item.className )} > {item.icon && }
{item.title}
{item.description && (

{item.description}

)}
); })}
); });