import { useState } from "react"; import { useRouter } from "next/router"; import { CustomMenu } from "@plane/ui"; import { Copy, Link, Pencil, Trash2, XCircle } from "lucide-react"; import omit from "lodash/omit"; // hooks import useToast from "hooks/use-toast"; import { useEventTracker, useIssues, useUser } from "hooks/store"; // 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"; // constants import { EIssuesStoreType } from "constants/issue"; import { EUserProjectRoles } from "constants/project"; export const CycleIssueQuickActions: React.FC = (props) => { const { issue, handleDelete, handleUpdate, handleRemoveFromView, customActionButton, portalElement, readOnly = false, } = props; // states const [createUpdateIssueModal, setCreateUpdateIssueModal] = useState(false); const [issueToEdit, setIssueToEdit] = useState(undefined); const [deleteIssueModal, setDeleteIssueModal] = useState(false); // router const router = useRouter(); const { workspaceSlug, cycleId } = router.query; // store hooks const { setTrackElement } = useEventTracker(); const { issuesFilter } = useIssues(EIssuesStoreType.CYCLE); // toast alert const { setToastAlert } = useToast(); // store hooks const { membership: { currentProjectRole }, } = useUser(); const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER; const activeLayout = `${issuesFilter.issueFilters?.displayFilters?.layout} layout`; const handleCopyIssueLink = () => { copyUrlToClipboard(`${workspaceSlug}/projects/${issue.project_id}/issues/${issue.id}`).then(() => setToastAlert({ type: "success", title: "Link copied", message: "Issue link copied to clipboard", }) ); }; const duplicateIssuePayload = omit( { ...issue, name: `${issue.name} (copy)`, }, ["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.CYCLE} /> { handleCopyIssueLink(); }} >
Copy link
{isEditingAllowed && !readOnly && ( <> { setIssueToEdit({ ...issue, cycle_id: cycleId?.toString() ?? null, }); setTrackElement(activeLayout); setCreateUpdateIssueModal(true); }} >
Edit issue
{ handleRemoveFromView && handleRemoveFromView(); }} >
Remove from cycle
{ setTrackElement(activeLayout); setCreateUpdateIssueModal(true); }} >
Make a copy
{ setTrackElement(activeLayout); setDeleteIssueModal(true); }} >
Delete issue
)}
); };