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
|
|
|
|
import { DeleteCycleModal, SingleCycleCard } from "components/cycles";
|
2023-03-06 06:06:48 +00:00
|
|
|
// icons
|
|
|
|
import { CompletedCycleIcon } 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-02-28 09:47:14 +00:00
|
|
|
export interface CompletedCyclesListProps {
|
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-02-28 09:47:14 +00:00
|
|
|
export const CompletedCyclesList: React.FC<CompletedCyclesListProps> = ({
|
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 (
|
|
|
|
<>
|
|
|
|
{completedCycles && (
|
|
|
|
<>
|
|
|
|
<DeleteCycleModal
|
|
|
|
isOpen={
|
|
|
|
cycleDeleteModal &&
|
|
|
|
!!selectedCycleForDelete &&
|
|
|
|
selectedCycleForDelete.actionType === "delete"
|
|
|
|
}
|
|
|
|
setIsOpen={setCycleDeleteModal}
|
|
|
|
data={selectedCycleForDelete}
|
|
|
|
/>
|
|
|
|
{completedCycles?.completed_cycles.length > 0 ? (
|
2023-03-06 06:06:48 +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)}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
2023-02-28 09:23:10 +00:00
|
|
|
) : (
|
|
|
|
<div className="flex flex-col items-center justify-center gap-4 text-center">
|
|
|
|
<CompletedCycleIcon height="56" width="56" />
|
|
|
|
<h3 className="text-gray-500">
|
|
|
|
No completed cycles yet. Create with{" "}
|
|
|
|
<pre className="inline rounded bg-gray-200 px-2 py-1">Q</pre>.
|
|
|
|
</h3>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|