2023-10-20 11:37:46 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import { CustomMenu } from "@plane/ui";
|
|
|
|
import { Copy, Link, Pencil, Trash2 } from "lucide-react";
|
2023-12-11 11:59:10 +00:00
|
|
|
// mobx store
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
2023-10-20 11:37:46 +00:00
|
|
|
// 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";
|
2023-11-23 09:17:04 +00:00
|
|
|
import { IQuickActionProps } from "../list/list-view-types";
|
2023-11-27 08:45:33 +00:00
|
|
|
import { EProjectStore } from "store/command-palette.store";
|
2023-12-11 11:59:10 +00:00
|
|
|
// constant
|
|
|
|
import { EUserWorkspaceRoles } from "constants/workspace";
|
2023-10-20 11:37:46 +00:00
|
|
|
|
2023-11-23 09:17:04 +00:00
|
|
|
export const ProjectIssueQuickActions: React.FC<IQuickActionProps> = (props) => {
|
2023-12-06 13:51:24 +00:00
|
|
|
const { issue, handleDelete, handleUpdate, customActionButton } = props;
|
2023-10-20 11:37:46 +00:00
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug } = router.query;
|
|
|
|
|
|
|
|
// states
|
|
|
|
const [createUpdateIssueModal, setCreateUpdateIssueModal] = useState(false);
|
|
|
|
const [issueToEdit, setIssueToEdit] = useState<IIssue | null>(null);
|
|
|
|
const [deleteIssueModal, setDeleteIssueModal] = useState(false);
|
|
|
|
|
2023-12-11 11:59:10 +00:00
|
|
|
const { user: userStore } = useMobxStore();
|
|
|
|
|
|
|
|
const { currentProjectRole } = userStore;
|
|
|
|
|
|
|
|
const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserWorkspaceRoles.MEMBER;
|
|
|
|
|
2023-10-20 11:37:46 +00:00
|
|
|
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 (
|
|
|
|
<>
|
|
|
|
<DeleteIssueModal
|
|
|
|
data={issue}
|
|
|
|
isOpen={deleteIssueModal}
|
|
|
|
handleClose={() => setDeleteIssueModal(false)}
|
|
|
|
onSubmit={handleDelete}
|
|
|
|
/>
|
|
|
|
<CreateUpdateIssueModal
|
|
|
|
isOpen={createUpdateIssueModal}
|
|
|
|
handleClose={() => {
|
|
|
|
setCreateUpdateIssueModal(false);
|
|
|
|
setIssueToEdit(null);
|
|
|
|
}}
|
|
|
|
// pre-populate date only if not editing
|
|
|
|
prePopulateData={!issueToEdit && createUpdateIssueModal ? { ...issue, name: `${issue.name} (copy)` } : {}}
|
|
|
|
data={issueToEdit}
|
|
|
|
onSubmit={async (data) => {
|
2023-11-23 09:17:04 +00:00
|
|
|
if (issueToEdit && handleUpdate) handleUpdate({ ...issueToEdit, ...data });
|
2023-10-20 11:37:46 +00:00
|
|
|
}}
|
2023-11-27 08:45:33 +00:00
|
|
|
currentStore={EProjectStore.PROJECT}
|
2023-10-20 11:37:46 +00:00
|
|
|
/>
|
2023-12-18 06:41:14 +00:00
|
|
|
<CustomMenu
|
|
|
|
placement="bottom-start"
|
|
|
|
customButton={customActionButton}
|
|
|
|
ellipsis
|
|
|
|
menuButtonOnClick={(e) => e.stopPropagation()}
|
|
|
|
>
|
2023-10-20 11:37:46 +00:00
|
|
|
<CustomMenu.MenuItem
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
handleCopyIssueLink();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<Link className="h-3 w-3" />
|
|
|
|
Copy link
|
|
|
|
</div>
|
|
|
|
</CustomMenu.MenuItem>
|
2023-12-11 11:59:10 +00:00
|
|
|
{isEditingAllowed && (
|
|
|
|
<>
|
|
|
|
<CustomMenu.MenuItem
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
setIssueToEdit(issue);
|
|
|
|
setCreateUpdateIssueModal(true);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<Pencil className="h-3 w-3" />
|
|
|
|
Edit issue
|
|
|
|
</div>
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
<CustomMenu.MenuItem
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
setCreateUpdateIssueModal(true);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<Copy className="h-3 w-3" />
|
|
|
|
Make a copy
|
|
|
|
</div>
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
<CustomMenu.MenuItem
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
setDeleteIssueModal(true);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<Trash2 className="h-3 w-3" />
|
|
|
|
Delete issue
|
|
|
|
</div>
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
</>
|
|
|
|
)}
|
2023-10-20 11:37:46 +00:00
|
|
|
</CustomMenu>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|