import { useState } from "react"; import { useRouter } from "next/router"; import { CustomMenu } from "@plane/ui"; import { Copy, Link, Pencil, Trash2 } from "lucide-react"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // hooks import useToast from "hooks/use-toast"; // components import { CreateUpdateIssueModal, DeleteIssueModal } from "components/issues"; // helpers import { copyUrlToClipboard } from "helpers/string.helper"; // types import { IIssue } from "types"; import { IQuickActionProps } from "../list/list-view-types"; import { EProjectStore } from "store/command-palette.store"; // constant import { EUserWorkspaceRoles } from "constants/workspace"; export const ProjectIssueQuickActions: React.FC = (props) => { const { issue, handleDelete, handleUpdate, customActionButton } = props; const router = useRouter(); const { workspaceSlug } = router.query; // states const [createUpdateIssueModal, setCreateUpdateIssueModal] = useState(false); const [issueToEdit, setIssueToEdit] = useState(null); const [deleteIssueModal, setDeleteIssueModal] = useState(false); const { user: userStore } = useMobxStore(); const { currentProjectRole } = userStore; const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserWorkspaceRoles.MEMBER; const { setToastAlert } = useToast(); const handleCopyIssueLink = () => { copyUrlToClipboard(`${workspaceSlug}/projects/${issue.project}/issues/${issue.id}`).then(() => setToastAlert({ type: "success", title: "Link copied", message: "Issue link copied to clipboard", }) ); }; return ( <> setDeleteIssueModal(false)} onSubmit={handleDelete} /> { setCreateUpdateIssueModal(false); setIssueToEdit(null); }} // pre-populate date only if not editing prePopulateData={!issueToEdit && createUpdateIssueModal ? { ...issue, name: `${issue.name} (copy)` } : {}} data={issueToEdit} onSubmit={async (data) => { if (issueToEdit && handleUpdate) handleUpdate({ ...issueToEdit, ...data }); }} currentStore={EProjectStore.PROJECT} /> e.stopPropagation()} > { e.preventDefault(); e.stopPropagation(); handleCopyIssueLink(); }} >
Copy link
{isEditingAllowed && ( <> { e.preventDefault(); e.stopPropagation(); setIssueToEdit(issue); setCreateUpdateIssueModal(true); }} >
Edit issue
{ e.preventDefault(); e.stopPropagation(); setCreateUpdateIssueModal(true); }} >
Make a copy
{ e.preventDefault(); e.stopPropagation(); setDeleteIssueModal(true); }} >
Delete issue
)}
); };