import { useState } from "react"; import omit from "lodash/omit"; import { observer } from "mobx-react"; import { useRouter } from "next/router"; import { Copy, ExternalLink, Link, Pencil, Trash2 } from "lucide-react"; // hooks import { ArchiveIcon, CustomMenu, TOAST_TYPE, setToast } from "@plane/ui"; import { ArchiveIssueModal, CreateUpdateIssueModal, DeleteIssueModal } from "components/issues"; // ui // components import { EIssuesStoreType } from "constants/issue"; import { STATE_GROUPS } from "constants/state"; import { copyUrlToClipboard } from "helpers/string.helper"; import { useEventTracker, useProjectState } from "hooks/store"; // components // helpers // types import { TIssue } from "@plane/types"; import { IQuickActionProps } from "../list/list-view-types"; // constants export const AllIssueQuickActions: React.FC = observer((props) => { const { issue, handleDelete, handleUpdate, handleArchive, customActionButton, portalElement, readOnly = false, } = props; // states const [createUpdateIssueModal, setCreateUpdateIssueModal] = useState(false); const [issueToEdit, setIssueToEdit] = useState(undefined); const [deleteIssueModal, setDeleteIssueModal] = useState(false); const [archiveIssueModal, setArchiveIssueModal] = useState(false); // router const router = useRouter(); const { workspaceSlug } = router.query; // store hooks const { setTrackElement } = useEventTracker(); const { getStateById } = useProjectState(); // derived values const stateDetails = getStateById(issue.state_id); const isEditingAllowed = !readOnly; // auth const isArchivingAllowed = handleArchive && isEditingAllowed; const isInArchivableGroup = !!stateDetails && [STATE_GROUPS.completed.key, STATE_GROUPS.cancelled.key].includes(stateDetails?.group); const issueLink = `${workspaceSlug}/projects/${issue.project_id}/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 duplicateIssuePayload = omit( { ...issue, name: `${issue.name} (copy)`, }, ["id"] ); return ( <> setArchiveIssueModal(false)} onSubmit={handleArchive} /> setDeleteIssueModal(false)} onSubmit={handleDelete} /> { setCreateUpdateIssueModal(false); setIssueToEdit(undefined); }} data={issueToEdit ?? duplicateIssuePayload} onSubmit={async (data) => { if (issueToEdit && handleUpdate) await handleUpdate(data); }} storeType={EIssuesStoreType.PROJECT} /> {isEditingAllowed && ( { setTrackElement("Global issues"); setIssueToEdit(issue); setCreateUpdateIssueModal(true); }} >
Edit
)}
Open in new tab
Copy link
{isEditingAllowed && ( { setTrackElement("Global issues"); setCreateUpdateIssueModal(true); }} >
Make a copy
)} {isArchivingAllowed && ( setArchiveIssueModal(true)} disabled={!isInArchivableGroup}> {isInArchivableGroup ? (
Archive
) : (

Archive

Only completed or canceled
issues can be archived

)}
)} {isEditingAllowed && ( { setTrackElement("Global issues"); setDeleteIssueModal(true); }} >
Delete
)}
); });