2023-03-16 08:37:19 +00:00
|
|
|
import React, { useState } from "react";
|
|
|
|
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
// hooks
|
|
|
|
import useUserAuth from "hooks/use-user-auth";
|
2023-03-16 08:37:19 +00:00
|
|
|
// 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-07-12 06:15:45 +00:00
|
|
|
import emptyView from "public/empty-state/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
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
const { user } = useUserAuth();
|
|
|
|
|
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
|
|
|
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-06-06 16:06:00 +00:00
|
|
|
user={user}
|
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-06-06 16:06:00 +00:00
|
|
|
user={user}
|
2023-03-16 08:37:19 +00:00
|
|
|
/>
|
2023-03-22 09:17:13 +00:00
|
|
|
{views ? (
|
|
|
|
views.length > 0 ? (
|
2023-05-05 11:37:29 +00:00
|
|
|
<div className="space-y-5 p-8">
|
2023-07-10 07:17:00 +00:00
|
|
|
<h3 className="text-2xl font-semibold text-custom-text-100">Views</h3>
|
2023-07-17 07:30:44 +00:00
|
|
|
<div className="divide-y divide-custom-border-300 rounded-[10px] border border-custom-border-300">
|
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
|
2023-07-12 06:15:45 +00:00
|
|
|
title="Get focused with views"
|
2023-03-22 11:28:32 +00:00
|
|
|
description="Views aid in saving your issues by applying various filters and grouping options."
|
2023-07-12 06:15:45 +00:00
|
|
|
image={emptyView}
|
|
|
|
buttonText="New View"
|
|
|
|
buttonIcon={<PlusIcon className="h-4 w-4" />}
|
|
|
|
onClick={() => {
|
|
|
|
const e = new KeyboardEvent("keydown", {
|
|
|
|
key: "v",
|
|
|
|
});
|
|
|
|
document.dispatchEvent(e);
|
|
|
|
}}
|
2023-03-22 09:17:13 +00:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
) : (
|
2023-05-10 20:45:39 +00:00
|
|
|
<Loader className="space-y-3 p-8">
|
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;
|