2023-03-16 08:37:19 +00:00
|
|
|
import React, { useState } from "react";
|
|
|
|
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
// lib
|
2023-03-27 11:23:31 +00:00
|
|
|
import { requiredAdmin, requiredAuth } from "lib/auth";
|
2023-03-16 08:37:19 +00:00
|
|
|
|
|
|
|
// services
|
|
|
|
import viewsService from "services/views.service";
|
|
|
|
import projectService from "services/project.service";
|
|
|
|
|
|
|
|
// layouts
|
|
|
|
import AppLayout from "layouts/app-layout";
|
|
|
|
// ui
|
|
|
|
import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
|
2023-03-28 11:18:46 +00:00
|
|
|
|
2023-03-31 10:33:25 +00:00
|
|
|
//icons
|
|
|
|
import { PlusIcon } from "components/icons";
|
|
|
|
|
2023-03-22 09:17:13 +00:00
|
|
|
// image
|
|
|
|
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-03-27 11:23:31 +00:00
|
|
|
import { IView, UserAuth } from "types";
|
2023-03-16 08:37:19 +00:00
|
|
|
import type { NextPage, GetServerSidePropsContext } from "next";
|
|
|
|
|
2023-03-27 11:23:31 +00:00
|
|
|
const ProjectViews: NextPage<UserAuth> = (props) => {
|
2023-03-18 06:04:29 +00:00
|
|
|
const [isCreateViewModalOpen, setIsCreateViewModalOpen] = useState(false);
|
2023-03-16 08:37:19 +00:00
|
|
|
const [selectedView, setSelectedView] = useState<IView | null>(null);
|
|
|
|
|
|
|
|
const {
|
|
|
|
query: { workspaceSlug, projectId },
|
|
|
|
} = useRouter();
|
|
|
|
|
|
|
|
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
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<AppLayout
|
|
|
|
meta={{
|
|
|
|
title: "Plane - Views",
|
|
|
|
}}
|
2023-03-27 11:23:31 +00:00
|
|
|
memberType={props}
|
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-03-31 10:33:25 +00:00
|
|
|
<PlusIcon className="w-4 h-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
|
|
|
|
isOpen={isCreateViewModalOpen}
|
|
|
|
handleClose={() => setIsCreateViewModalOpen(false)}
|
|
|
|
/>
|
2023-03-16 08:37:19 +00:00
|
|
|
<DeleteViewModal
|
|
|
|
isOpen={!!selectedView}
|
|
|
|
data={selectedView}
|
|
|
|
onClose={() => setSelectedView(null)}
|
|
|
|
onSuccess={() => setSelectedView(null)}
|
|
|
|
/>
|
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">
|
|
|
|
<h3 className="text-3xl font-semibold text-black">Views</h3>
|
|
|
|
<div className="rounded-[10px] border">
|
|
|
|
{views.map((view) => (
|
2023-03-29 11:00:40 +00:00
|
|
|
<SingleViewItem key={view.id} view={view} setSelectedView={setSelectedView} />
|
2023-03-23 19:41:42 +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-03-16 08:37:19 +00:00
|
|
|
</AppLayout>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
|
|
|
|
const user = await requiredAuth(ctx.req?.headers.cookie);
|
|
|
|
|
|
|
|
const redirectAfterSignIn = ctx.resolvedUrl;
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
return {
|
|
|
|
redirect: {
|
|
|
|
destination: `/signin?next=${redirectAfterSignIn}`,
|
|
|
|
permanent: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-03-27 11:23:31 +00:00
|
|
|
const projectId = ctx.query.projectId as string;
|
|
|
|
const workspaceSlug = ctx.query.workspaceSlug as string;
|
|
|
|
|
|
|
|
const memberDetail = await requiredAdmin(workspaceSlug, projectId, ctx.req?.headers.cookie);
|
|
|
|
|
2023-03-16 08:37:19 +00:00
|
|
|
return {
|
|
|
|
props: {
|
2023-03-27 11:23:31 +00:00
|
|
|
isOwner: memberDetail?.role === 20,
|
|
|
|
isMember: memberDetail?.role === 15,
|
|
|
|
isViewer: memberDetail?.role === 10,
|
|
|
|
isGuest: memberDetail?.role === 5,
|
2023-03-16 08:37:19 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ProjectViews;
|