import { useState } from "react"; import { useRouter } from "next/router"; import { CustomMenu } from "@plane/ui"; import { Copy, Link, Pencil, Trash2 } from "lucide-react"; // hooks import { useUser } from "hooks/store"; import useToast from "hooks/use-toast"; // components import { 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"; // constant import { EUserProjectRoles } from "constants/project"; import { EIssuesStoreType } from "constants/issue"; export const ProjectIssueQuickActions: React.FC = (props) => { const { issue, handleDelete, handleUpdate, customActionButton, portalElement } = props; // router const router = useRouter(); const { workspaceSlug } = router.query; // states const [createUpdateIssueModal, setCreateUpdateIssueModal] = useState(false); const [issueToEdit, setIssueToEdit] = useState(undefined); const [deleteIssueModal, setDeleteIssueModal] = useState(false); // store hooks const { membership: { currentProjectRole }, } = useUser(); const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.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", }) ); }; const duplicateIssuePayload = { ...issue, name: `${issue.name} (copy)`, }; delete duplicateIssuePayload.id; return ( <> setDeleteIssueModal(false)} onSubmit={handleDelete} /> { setCreateUpdateIssueModal(false); setIssueToEdit(undefined); }} data={issueToEdit ?? duplicateIssuePayload} onSubmit={async (data) => { if (issueToEdit && handleUpdate) await handleUpdate({ ...issueToEdit, ...data }); }} storeType={EIssuesStoreType.PROJECT} /> { handleCopyIssueLink(); }} >
Copy link
{isEditingAllowed && ( <> { setIssueToEdit(issue); setCreateUpdateIssueModal(true); }} >
Edit issue
{ setCreateUpdateIssueModal(true); }} >
Make a copy
{ setDeleteIssueModal(true); }} >
Delete issue
)}
); };