import { useState } from "react"; import { useRouter } from "next/router"; import { ArchiveIcon, CustomMenu } from "@plane/ui"; import { observer } from "mobx-react"; import { Copy, ExternalLink, Link, Pencil, Trash2, XCircle } from "lucide-react"; import omit from "lodash/omit"; // hooks import useToast from "hooks/use-toast"; import { useIssues, useEventTracker, useUser, useProjectState } from "hooks/store"; // components import { ArchiveIssueModal, CreateUpdateIssueModal, DeleteIssueModal } from "components/issues"; // helpers import { copyUrlToClipboard } from "helpers/string.helper"; // types import { TIssue } from "@plane/types"; import { IQuickActionProps } from "../list/list-view-types"; // constants import { EIssuesStoreType } from "constants/issue"; import { EUserProjectRoles } from "constants/project"; import { STATE_GROUPS } from "constants/state"; export const ModuleIssueQuickActions: React.FC = observer((props) => { const { issue, handleDelete, handleUpdate, handleRemoveFromView, 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, moduleId } = router.query; // store hooks const { setTrackElement } = useEventTracker(); const { issuesFilter } = useIssues(EIssuesStoreType.MODULE); const { membership: { currentProjectRole }, } = useUser(); const { getStateById } = useProjectState(); // toast alert const { setToastAlert } = useToast(); // derived values const stateDetails = getStateById(issue.state_id); // auth const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER && !readOnly; const isArchivingAllowed = handleArchive && isEditingAllowed; const isInArchivableGroup = !!stateDetails && [STATE_GROUPS.completed.key, STATE_GROUPS.cancelled.key].includes(stateDetails?.group); const isDeletingAllowed = isEditingAllowed; const activeLayout = `${issuesFilter.issueFilters?.displayFilters?.layout} layout`; const issueLink = `${workspaceSlug}/projects/${issue.project_id}/issues/${issue.id}`; const handleOpenInNewTab = () => window.open(`/${issueLink}`, "_blank"); const handleCopyIssueLink = () => copyUrlToClipboard(issueLink).then(() => setToastAlert({ 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({ ...issueToEdit, ...data }); }} storeType={EIssuesStoreType.MODULE} /> {isEditingAllowed && ( { setIssueToEdit({ ...issue, module_ids: moduleId ? [moduleId.toString()] : [] }); setTrackElement(activeLayout); setCreateUpdateIssueModal(true); }} >
Edit
)}
Open in new tab
Copy link
{isEditingAllowed && ( { setTrackElement(activeLayout); setCreateUpdateIssueModal(true); }} >
Make a copy
)} {isEditingAllowed && ( { handleRemoveFromView && handleRemoveFromView(); }} >
Remove from module
)} {isArchivingAllowed && ( setArchiveIssueModal(true)} disabled={!isInArchivableGroup}> {isInArchivableGroup ? (
Archive
) : (

Archive

Only completed or canceled
issues can be archived

)}
)} {isDeletingAllowed && ( { e.preventDefault(); e.stopPropagation(); setTrackElement(activeLayout); setDeleteIssueModal(true); }} >
Delete
)}
); });