2024-03-11 15:30:05 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
import { observer } from "mobx-react";
|
2024-03-20 15:32:58 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
// icons
|
|
|
|
import { ArchiveRestoreIcon, LinkIcon, Pencil, Trash2 } from "lucide-react";
|
2024-03-19 14:38:35 +00:00
|
|
|
// ui
|
2024-03-20 15:32:58 +00:00
|
|
|
import { ArchiveIcon, CustomMenu, TOAST_TYPE, setToast } from "@plane/ui";
|
|
|
|
// components
|
|
|
|
import { ArchiveCycleModal, CycleCreateUpdateModal, CycleDeleteModal } from "@/components/cycles";
|
|
|
|
// constants
|
2024-03-19 14:38:35 +00:00
|
|
|
import { EUserProjectRoles } from "@/constants/project";
|
2024-03-20 15:32:58 +00:00
|
|
|
// helpers
|
2024-03-19 14:38:35 +00:00
|
|
|
import { copyUrlToClipboard } from "@/helpers/string.helper";
|
2024-03-20 15:32:58 +00:00
|
|
|
// hooks
|
2024-03-19 14:38:35 +00:00
|
|
|
import { useCycle, useEventTracker, useUser } from "@/hooks/store";
|
2024-03-11 15:30:05 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
cycleId: string;
|
|
|
|
projectId: string;
|
|
|
|
workspaceSlug: string;
|
2024-03-20 15:32:58 +00:00
|
|
|
isArchived?: boolean;
|
2024-03-11 15:30:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const CycleQuickActions: React.FC<Props> = observer((props) => {
|
2024-03-20 15:32:58 +00:00
|
|
|
const { cycleId, projectId, workspaceSlug, isArchived } = props;
|
|
|
|
// router
|
|
|
|
const router = useRouter();
|
2024-03-11 15:30:05 +00:00
|
|
|
// states
|
|
|
|
const [updateModal, setUpdateModal] = useState(false);
|
2024-03-20 15:32:58 +00:00
|
|
|
const [archiveCycleModal, setArchiveCycleModal] = useState(false);
|
2024-03-11 15:30:05 +00:00
|
|
|
const [deleteModal, setDeleteModal] = useState(false);
|
|
|
|
// store hooks
|
|
|
|
const { setTrackElement } = useEventTracker();
|
|
|
|
const {
|
|
|
|
membership: { currentWorkspaceAllProjectsRole },
|
|
|
|
} = useUser();
|
2024-03-20 15:32:58 +00:00
|
|
|
const { getCycleById, restoreCycle } = useCycle();
|
2024-03-11 15:30:05 +00:00
|
|
|
// derived values
|
|
|
|
const cycleDetails = getCycleById(cycleId);
|
2024-04-05 14:35:55 +00:00
|
|
|
const isCompleted = cycleDetails?.status?.toLowerCase() === "completed";
|
2024-03-11 15:30:05 +00:00
|
|
|
// auth
|
|
|
|
const isEditingAllowed =
|
|
|
|
!!currentWorkspaceAllProjectsRole && currentWorkspaceAllProjectsRole[projectId] >= EUserProjectRoles.MEMBER;
|
|
|
|
|
|
|
|
const handleCopyText = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
copyUrlToClipboard(`${workspaceSlug}/projects/${projectId}/cycles/${cycleId}`).then(() => {
|
|
|
|
setToast({
|
|
|
|
type: TOAST_TYPE.SUCCESS,
|
|
|
|
title: "Link Copied!",
|
|
|
|
message: "Cycle link copied to clipboard.",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleEditCycle = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
setTrackElement("Cycles page list layout");
|
|
|
|
setUpdateModal(true);
|
|
|
|
};
|
|
|
|
|
2024-03-20 15:32:58 +00:00
|
|
|
const handleArchiveCycle = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
setArchiveCycleModal(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleRestoreCycle = async (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
await restoreCycle(workspaceSlug, projectId, cycleId)
|
|
|
|
.then(() => {
|
|
|
|
setToast({
|
|
|
|
type: TOAST_TYPE.SUCCESS,
|
|
|
|
title: "Restore success",
|
|
|
|
message: "Your cycle can be found in project cycles.",
|
|
|
|
});
|
2024-04-03 12:49:34 +00:00
|
|
|
router.push(`/${workspaceSlug}/projects/${projectId}/archives/cycles`);
|
2024-03-20 15:32:58 +00:00
|
|
|
})
|
|
|
|
.catch(() =>
|
|
|
|
setToast({
|
|
|
|
type: TOAST_TYPE.ERROR,
|
|
|
|
title: "Error!",
|
|
|
|
message: "Cycle could not be restored. Please try again.",
|
|
|
|
})
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-03-11 15:30:05 +00:00
|
|
|
const handleDeleteCycle = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
setTrackElement("Cycles page list layout");
|
|
|
|
setDeleteModal(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{cycleDetails && (
|
|
|
|
<div className="fixed">
|
|
|
|
<CycleCreateUpdateModal
|
|
|
|
data={cycleDetails}
|
|
|
|
isOpen={updateModal}
|
|
|
|
handleClose={() => setUpdateModal(false)}
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
projectId={projectId}
|
|
|
|
/>
|
2024-03-20 15:32:58 +00:00
|
|
|
<ArchiveCycleModal
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
projectId={projectId}
|
|
|
|
cycleId={cycleId}
|
|
|
|
isOpen={archiveCycleModal}
|
|
|
|
handleClose={() => setArchiveCycleModal(false)}
|
|
|
|
/>
|
2024-03-11 15:30:05 +00:00
|
|
|
<CycleDeleteModal
|
|
|
|
cycle={cycleDetails}
|
|
|
|
isOpen={deleteModal}
|
|
|
|
handleClose={() => setDeleteModal(false)}
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
projectId={projectId}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<CustomMenu ellipsis placement="bottom-end">
|
2024-03-20 15:32:58 +00:00
|
|
|
{!isCompleted && isEditingAllowed && !isArchived && (
|
|
|
|
<CustomMenu.MenuItem onClick={handleEditCycle}>
|
|
|
|
<span className="flex items-center justify-start gap-2">
|
|
|
|
<Pencil className="h-3 w-3" />
|
|
|
|
<span>Edit cycle</span>
|
|
|
|
</span>
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
)}
|
|
|
|
{isEditingAllowed && !isArchived && (
|
|
|
|
<CustomMenu.MenuItem onClick={handleArchiveCycle} disabled={!isCompleted}>
|
|
|
|
{isCompleted ? (
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<ArchiveIcon className="h-3 w-3" />
|
|
|
|
Archive cycle
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="flex items-start gap-2">
|
|
|
|
<ArchiveIcon className="h-3 w-3" />
|
|
|
|
<div className="-mt-1">
|
|
|
|
<p>Archive cycle</p>
|
|
|
|
<p className="text-xs text-custom-text-400">
|
|
|
|
Only completed cycle <br /> can be archived.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
)}
|
|
|
|
{isEditingAllowed && isArchived && (
|
|
|
|
<CustomMenu.MenuItem onClick={handleRestoreCycle}>
|
|
|
|
<span className="flex items-center justify-start gap-2">
|
|
|
|
<ArchiveRestoreIcon className="h-3 w-3" />
|
|
|
|
<span>Restore cycle</span>
|
|
|
|
</span>
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
)}
|
|
|
|
{!isArchived && (
|
|
|
|
<CustomMenu.MenuItem onClick={handleCopyText}>
|
|
|
|
<span className="flex items-center justify-start gap-2">
|
|
|
|
<LinkIcon className="h-3 w-3" />
|
|
|
|
<span>Copy cycle link</span>
|
|
|
|
</span>
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
)}
|
2024-04-17 15:02:25 +00:00
|
|
|
<hr className="my-2 border-custom-border-200" />
|
2024-03-11 15:30:05 +00:00
|
|
|
{!isCompleted && isEditingAllowed && (
|
2024-04-17 15:02:25 +00:00
|
|
|
<CustomMenu.MenuItem onClick={handleDeleteCycle}>
|
|
|
|
<span className="flex items-center justify-start gap-2">
|
|
|
|
<Trash2 className="h-3 w-3" />
|
|
|
|
<span>Delete cycle</span>
|
|
|
|
</span>
|
|
|
|
</CustomMenu.MenuItem>
|
2024-03-11 15:30:05 +00:00
|
|
|
)}
|
|
|
|
</CustomMenu>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|