2023-03-16 08:37:19 +00:00
|
|
|
import React, { useState } from "react";
|
|
|
|
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
// services
|
|
|
|
import viewsService from "services/views.service";
|
|
|
|
import projectService from "services/project.service";
|
|
|
|
// layouts
|
2023-04-08 08:16:46 +00:00
|
|
|
import { ProjectAuthorizationWrapper } from "layouts/auth-layout";
|
2023-03-16 08:37:19 +00:00
|
|
|
// ui
|
|
|
|
import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
|
2023-03-31 10:33:25 +00:00
|
|
|
//icons
|
|
|
|
import { PlusIcon } from "components/icons";
|
2023-04-08 08:16:46 +00:00
|
|
|
// images
|
2023-03-22 09:17:13 +00:00
|
|
|
import emptyView from "public/empty-state/empty-view.svg";
|
2023-03-16 08:37:19 +00:00
|
|
|
// fetching keys
|
|
|
|
import { PROJECT_DETAILS, VIEWS_LIST } from "constants/fetch-keys";
|
|
|
|
// components
|
2023-03-28 11:18:46 +00:00
|
|
|
import { PrimaryButton, Loader, EmptyState } from "components/ui";
|
|
|
|
import { DeleteViewModal, CreateUpdateViewModal, SingleViewItem } from "components/views";
|
2023-03-16 08:37:19 +00:00
|
|
|
// types
|
2023-04-08 08:16:46 +00:00
|
|
|
import { IView } from "types";
|
|
|
|
import type { NextPage } from "next";
|
2023-03-16 08:37:19 +00:00
|
|
|
|
2023-04-08 08:16:46 +00:00
|
|
|
const ProjectViews: NextPage = () => {
|
2023-04-12 10:03:21 +00:00
|
|
|
const [createUpdateViewModal, setCreateUpdateViewModal] = useState(false);
|
|
|
|
const [selectedViewToUpdate, setSelectedViewToUpdate] = useState<IView | null>(null);
|
|
|
|
|
|
|
|
const [deleteViewModal, setDeleteViewModal] = useState(false);
|
|
|
|
const [selectedViewToDelete, setSelectedViewToDelete] = useState<IView | null>(null);
|
2023-03-16 08:37:19 +00:00
|
|
|
|
2023-04-08 08:16:46 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
2023-03-16 08:37:19 +00:00
|
|
|
|
|
|
|
const { data: activeProject } = useSWR(
|
|
|
|
workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => projectService.getProject(workspaceSlug as string, projectId as string)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
|
|
|
const { data: views } = useSWR(
|
|
|
|
workspaceSlug && projectId ? VIEWS_LIST(projectId as string) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => viewsService.getViews(workspaceSlug as string, projectId as string)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
2023-04-12 10:03:21 +00:00
|
|
|
const handleEditView = (view: IView) => {
|
|
|
|
setSelectedViewToUpdate(view);
|
|
|
|
setCreateUpdateViewModal(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleDeleteView = (view: IView) => {
|
|
|
|
setSelectedViewToDelete(view);
|
|
|
|
setDeleteViewModal(true);
|
|
|
|
};
|
|
|
|
|
2023-03-16 08:37:19 +00:00
|
|
|
return (
|
2023-04-08 08:16:46 +00:00
|
|
|
<ProjectAuthorizationWrapper
|
2023-03-16 08:37:19 +00:00
|
|
|
meta={{
|
|
|
|
title: "Plane - Views",
|
|
|
|
}}
|
|
|
|
breadcrumbs={
|
|
|
|
<Breadcrumbs>
|
|
|
|
<BreadcrumbItem title="Projects" link={`/${workspaceSlug}/projects`} />
|
2023-03-23 19:41:42 +00:00
|
|
|
<BreadcrumbItem title={`${activeProject?.name ?? "Project"} Views`} />
|
2023-03-16 08:37:19 +00:00
|
|
|
</Breadcrumbs>
|
|
|
|
}
|
2023-03-18 06:04:29 +00:00
|
|
|
right={
|
|
|
|
<div className="flex items-center gap-2">
|
2023-04-03 08:53:50 +00:00
|
|
|
<PrimaryButton
|
|
|
|
type="button"
|
|
|
|
className="flex items-center gap-2"
|
|
|
|
onClick={() => {
|
|
|
|
const e = new KeyboardEvent("keydown", { key: "v" });
|
|
|
|
document.dispatchEvent(e);
|
|
|
|
}}
|
|
|
|
>
|
2023-04-20 08:11:24 +00:00
|
|
|
<PlusIcon className="h-4 w-4" />
|
2023-03-18 06:04:29 +00:00
|
|
|
Create View
|
|
|
|
</PrimaryButton>
|
|
|
|
</div>
|
|
|
|
}
|
2023-03-16 08:37:19 +00:00
|
|
|
>
|
2023-03-18 06:04:29 +00:00
|
|
|
<CreateUpdateViewModal
|
2023-04-12 10:03:21 +00:00
|
|
|
isOpen={createUpdateViewModal}
|
|
|
|
handleClose={() => setCreateUpdateViewModal(false)}
|
|
|
|
data={selectedViewToUpdate}
|
2023-03-18 06:04:29 +00:00
|
|
|
/>
|
2023-03-16 08:37:19 +00:00
|
|
|
<DeleteViewModal
|
2023-04-12 10:03:21 +00:00
|
|
|
isOpen={deleteViewModal}
|
|
|
|
data={selectedViewToDelete}
|
|
|
|
setIsOpen={setDeleteViewModal}
|
2023-03-16 08:37:19 +00:00
|
|
|
/>
|
2023-03-22 09:17:13 +00:00
|
|
|
{views ? (
|
|
|
|
views.length > 0 ? (
|
2023-03-23 19:41:42 +00:00
|
|
|
<div className="space-y-5">
|
2023-04-20 08:11:24 +00:00
|
|
|
<h3 className="text-3xl font-semibold text-brand-base">Views</h3>
|
|
|
|
<div className="rounded-[10px] border border-brand-base">
|
2023-03-23 19:41:42 +00:00
|
|
|
{views.map((view) => (
|
2023-04-12 10:03:21 +00:00
|
|
|
<SingleViewItem
|
|
|
|
key={view.id}
|
|
|
|
view={view}
|
|
|
|
handleEditView={() => handleEditView(view)}
|
|
|
|
handleDeleteView={() => handleDeleteView(view)}
|
|
|
|
/>
|
2023-03-23 19:41:42 +00:00
|
|
|
))}
|
2023-04-20 08:11:24 +00:00
|
|
|
</div>
|
2023-03-16 08:37:19 +00:00
|
|
|
</div>
|
2023-03-22 09:17:13 +00:00
|
|
|
) : (
|
|
|
|
<EmptyState
|
|
|
|
type="view"
|
|
|
|
title="Create New View"
|
2023-03-22 11:28:32 +00:00
|
|
|
description="Views aid in saving your issues by applying various filters and grouping options."
|
2023-03-22 09:17:13 +00:00
|
|
|
imgURL={emptyView}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
) : (
|
2023-03-23 06:31:50 +00:00
|
|
|
<Loader className="space-y-3">
|
2023-03-22 09:17:13 +00:00
|
|
|
<Loader.Item height="30px" />
|
|
|
|
<Loader.Item height="30px" />
|
|
|
|
<Loader.Item height="30px" />
|
|
|
|
</Loader>
|
|
|
|
)}
|
2023-04-08 08:16:46 +00:00
|
|
|
</ProjectAuthorizationWrapper>
|
2023-03-16 08:37:19 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ProjectViews;
|