import { useState } from "react"; import omit from "lodash/omit"; import { observer } from "mobx-react"; // icons import { Pencil, Trash2 } from "lucide-react"; // types import { TIssue } from "@plane/types"; // ui import { CustomMenu } from "@plane/ui"; // components import { CreateUpdateIssueModal, DeleteIssueModal } from "@/components/issues"; // constant import { EIssuesStoreType } from "@/constants/issue"; import { EUserProjectRoles } from "@/constants/project"; // hooks import { useEventTracker, useIssues, useUser } from "@/hooks/store"; // types import { IQuickActionProps } from "../list/list-view-types"; export const DraftIssueQuickActions: React.FC = observer((props) => { const { issue, handleDelete, handleUpdate, customActionButton, portalElement, readOnly = false } = props; // states const [createUpdateIssueModal, setCreateUpdateIssueModal] = useState(false); const [issueToEdit, setIssueToEdit] = useState(undefined); const [deleteIssueModal, setDeleteIssueModal] = useState(false); // store hooks const { membership: { currentProjectRole }, } = useUser(); const { setTrackElement } = useEventTracker(); const { issuesFilter } = useIssues(EIssuesStoreType.PROJECT); // derived values const activeLayout = `${issuesFilter.issueFilters?.displayFilters?.layout} layout`; // auth const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER && !readOnly; const isDeletingAllowed = isEditingAllowed; const duplicateIssuePayload = omit( { ...issue, name: `${issue.name} (copy)`, is_draft: true, }, ["id"] ); return ( <> setDeleteIssueModal(false)} onSubmit={handleDelete} /> { setCreateUpdateIssueModal(false); setIssueToEdit(undefined); }} data={issueToEdit ?? duplicateIssuePayload} onSubmit={async (data) => { if (issueToEdit && handleUpdate) await handleUpdate(data); }} storeType={EIssuesStoreType.PROJECT} isDraft /> {isEditingAllowed && ( { setTrackElement(activeLayout); setIssueToEdit(issue); setCreateUpdateIssueModal(true); }} >
Edit
)} {isDeletingAllowed && ( { setTrackElement(activeLayout); setDeleteIssueModal(true); }} >
Delete
)}
); });