2023-02-28 09:23:10 +00:00
|
|
|
import { useState } from "react";
|
2023-03-06 06:06:48 +00:00
|
|
|
|
2023-02-28 09:23:10 +00:00
|
|
|
import { useRouter } from "next/router";
|
2023-03-06 06:06:48 +00:00
|
|
|
|
2023-02-28 09:23:10 +00:00
|
|
|
import useSWR from "swr";
|
|
|
|
|
2023-03-06 06:06:48 +00:00
|
|
|
// services
|
|
|
|
import cyclesService from "services/cycles.service";
|
2023-02-28 09:23:10 +00:00
|
|
|
// components
|
2023-05-17 07:28:01 +00:00
|
|
|
import { DeleteCycleModal, SingleCycleCard, SingleCycleList } from "components/cycles";
|
2023-03-06 06:06:48 +00:00
|
|
|
// icons
|
2023-05-17 07:28:01 +00:00
|
|
|
import { ExclamationIcon } from "components/icons";
|
2023-02-28 09:23:10 +00:00
|
|
|
// types
|
|
|
|
import { ICycle, SelectCycleType } from "types";
|
2023-03-06 06:06:48 +00:00
|
|
|
// fetch-keys
|
2023-02-28 09:23:10 +00:00
|
|
|
import { CYCLE_COMPLETE_LIST } from "constants/fetch-keys";
|
2023-03-15 05:31:54 +00:00
|
|
|
import { EmptyState, Loader } from "components/ui";
|
|
|
|
// image
|
|
|
|
import emptyCycle from "public/empty-state/empty-cycle.svg";
|
2023-02-28 09:23:10 +00:00
|
|
|
|
2023-02-28 09:47:14 +00:00
|
|
|
export interface CompletedCyclesListProps {
|
2023-05-17 07:28:01 +00:00
|
|
|
cycleView: string;
|
2023-02-28 09:23:10 +00:00
|
|
|
setCreateUpdateCycleModal: React.Dispatch<React.SetStateAction<boolean>>;
|
|
|
|
setSelectedCycle: React.Dispatch<React.SetStateAction<SelectCycleType>>;
|
2023-02-28 09:47:14 +00:00
|
|
|
}
|
2023-02-28 09:23:10 +00:00
|
|
|
|
2023-05-17 07:28:01 +00:00
|
|
|
export const CompletedCycles: React.FC<CompletedCyclesListProps> = ({
|
|
|
|
cycleView,
|
2023-02-28 09:23:10 +00:00
|
|
|
setCreateUpdateCycleModal,
|
|
|
|
setSelectedCycle,
|
|
|
|
}) => {
|
|
|
|
const [cycleDeleteModal, setCycleDeleteModal] = useState(false);
|
|
|
|
const [selectedCycleForDelete, setSelectedCycleForDelete] = useState<SelectCycleType>();
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
|
|
|
const { data: completedCycles } = useSWR(
|
|
|
|
workspaceSlug && projectId ? CYCLE_COMPLETE_LIST(projectId as string) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => cyclesService.getCompletedCycles(workspaceSlug as string, projectId as string)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleDeleteCycle = (cycle: ICycle) => {
|
|
|
|
setSelectedCycleForDelete({ ...cycle, actionType: "delete" });
|
|
|
|
setCycleDeleteModal(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleEditCycle = (cycle: ICycle) => {
|
|
|
|
setSelectedCycle({ ...cycle, actionType: "edit" });
|
|
|
|
setCreateUpdateCycleModal(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-03-07 05:34:51 +00:00
|
|
|
<DeleteCycleModal
|
|
|
|
isOpen={
|
|
|
|
cycleDeleteModal &&
|
|
|
|
!!selectedCycleForDelete &&
|
|
|
|
selectedCycleForDelete.actionType === "delete"
|
|
|
|
}
|
|
|
|
setIsOpen={setCycleDeleteModal}
|
|
|
|
data={selectedCycleForDelete}
|
|
|
|
/>
|
|
|
|
{completedCycles ? (
|
|
|
|
completedCycles.completed_cycles.length > 0 ? (
|
2023-03-28 13:18:57 +00:00
|
|
|
<div className="flex flex-col gap-4">
|
2023-04-20 08:11:24 +00:00
|
|
|
<div className="flex items-center gap-2 text-sm text-brand-secondary">
|
2023-05-05 10:15:53 +00:00
|
|
|
<ExclamationIcon
|
|
|
|
height={14}
|
|
|
|
width={14}
|
|
|
|
className="fill-current text-brand-secondary"
|
|
|
|
/>
|
2023-03-28 13:18:57 +00:00
|
|
|
<span>Completed cycles are not editable.</span>
|
|
|
|
</div>
|
2023-05-19 12:38:47 +00:00
|
|
|
{cycleView === "list" && (
|
2023-05-17 07:28:01 +00:00
|
|
|
<div>
|
|
|
|
{completedCycles.completed_cycles.map((cycle) => (
|
|
|
|
<div className="hover:bg-brand-surface-2">
|
|
|
|
<div className="flex flex-col border-brand-base">
|
|
|
|
<SingleCycleList
|
|
|
|
key={cycle.id}
|
|
|
|
cycle={cycle}
|
|
|
|
handleDeleteCycle={() => handleDeleteCycle(cycle)}
|
|
|
|
handleEditCycle={() => handleEditCycle(cycle)}
|
|
|
|
isCompleted
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
2023-05-19 12:38:47 +00:00
|
|
|
)}
|
|
|
|
{cycleView === "board" && (
|
2023-05-17 07:28:01 +00:00
|
|
|
<div className="grid grid-cols-1 gap-9 md:grid-cols-2 lg:grid-cols-3">
|
|
|
|
{completedCycles.completed_cycles.map((cycle) => (
|
|
|
|
<SingleCycleCard
|
|
|
|
key={cycle.id}
|
|
|
|
cycle={cycle}
|
|
|
|
handleDeleteCycle={() => handleDeleteCycle(cycle)}
|
|
|
|
handleEditCycle={() => handleEditCycle(cycle)}
|
|
|
|
isCompleted
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)}
|
2023-05-19 12:38:47 +00:00
|
|
|
{cycleView === "gantt" && (
|
|
|
|
<EmptyState
|
|
|
|
type="cycle"
|
|
|
|
title="Create New Cycle"
|
|
|
|
description="Sprint more effectively with Cycles by confining your project to a fixed amount of time. Create new cycle now."
|
|
|
|
imgURL={emptyCycle}
|
|
|
|
/>
|
|
|
|
)}
|
2023-03-07 05:34:51 +00:00
|
|
|
</div>
|
|
|
|
) : (
|
2023-03-15 05:31:54 +00:00
|
|
|
<EmptyState
|
|
|
|
type="cycle"
|
|
|
|
title="Create New Cycle"
|
|
|
|
description="Sprint more effectively with Cycles by confining your project
|
|
|
|
to a fixed amount of time. Create new cycle now."
|
|
|
|
imgURL={emptyCycle}
|
|
|
|
/>
|
2023-03-07 05:34:51 +00:00
|
|
|
)
|
|
|
|
) : (
|
|
|
|
<Loader className="grid grid-cols-1 gap-9 md:grid-cols-2 lg:grid-cols-3">
|
|
|
|
<Loader.Item height="200px" />
|
|
|
|
<Loader.Item height="200px" />
|
|
|
|
<Loader.Item height="200px" />
|
|
|
|
</Loader>
|
2023-02-28 09:23:10 +00:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|