forked from github/plane
1a534a3c19
* chore: global bar graph component * chore: global pie graph component * chore: global line graph component * chore: removed unnecessary file * chore: refactored global chart components to accept all props * chore: function to convert response to chart data * chore: global calendar graph component added * chore: global scatter plot graph component * feat: analytics boilerplate created * chore: null value for segment and project * chore: clean up file * chore: change project query param key * chore: export, refresh buttons, analytics table * fix: analytics fetch key error * chore: show only integer values in the y-axis * chore: custom x-axis tick values and bar colors * refactor: divide analytics page into granular components * chore: convert analytics page to modal, save analytics modal * fix: build error * fix: modal overflow issues, analytics loading screen * chore: custom tooltip, refactor: graphs folder structure * refactor: folder structure, chore: x-axis tick values for larger data * chore: code cleanup * chore: remove unnecessary files * fix: refresh analytics button on error * feat: scope and demand analytics * refactor: scope and demand and custom analytics folder structure * fix: dynamic import type * chore: minor updates * feat: project, cycle and module level analytics * style: project analytics modal * fix: merge conflicts
151 lines
4.7 KiB
TypeScript
151 lines
4.7 KiB
TypeScript
import { useState } from "react";
|
|
|
|
import Link from "next/link";
|
|
import { useRouter } from "next/router";
|
|
|
|
import useSWR from "swr";
|
|
|
|
// services
|
|
import workspaceServices from "services/workspace.service";
|
|
// layouts
|
|
import Container from "layouts/container";
|
|
import AppSidebar from "layouts/app-layout/app-sidebar";
|
|
import AppHeader from "layouts/app-layout/app-header";
|
|
import { UserAuthorizationLayout } from "./user-authorization-wrapper";
|
|
// components
|
|
import { NotAuthorizedView, NotAWorkspaceMember } from "components/auth-screens";
|
|
import { AnalyticsWorkspaceModal } from "components/analytics";
|
|
import { CommandPalette } from "components/command-palette";
|
|
// icons
|
|
import { PrimaryButton, Spinner } from "components/ui";
|
|
import { LayerDiagonalIcon } from "components/icons";
|
|
// fetch-keys
|
|
import { WORKSPACE_MEMBERS_ME } from "constants/fetch-keys";
|
|
|
|
type Meta = {
|
|
title?: string | null;
|
|
description?: string | null;
|
|
image?: string | null;
|
|
url?: string | null;
|
|
};
|
|
|
|
type Props = {
|
|
meta?: Meta;
|
|
children: React.ReactNode;
|
|
noHeader?: boolean;
|
|
bg?: "primary" | "secondary";
|
|
breadcrumbs?: JSX.Element;
|
|
left?: JSX.Element;
|
|
right?: JSX.Element;
|
|
};
|
|
|
|
export const WorkspaceAuthorizationLayout: React.FC<Props> = ({
|
|
meta,
|
|
children,
|
|
noHeader = false,
|
|
bg = "primary",
|
|
breadcrumbs,
|
|
left,
|
|
right,
|
|
}) => {
|
|
const [toggleSidebar, setToggleSidebar] = useState(false);
|
|
const [analyticsModal, setAnalyticsModal] = useState(false);
|
|
|
|
const router = useRouter();
|
|
const { workspaceSlug } = router.query;
|
|
|
|
const { data: workspaceMemberMe, error } = useSWR(
|
|
workspaceSlug ? WORKSPACE_MEMBERS_ME(workspaceSlug as string) : null,
|
|
workspaceSlug ? () => workspaceServices.workspaceMemberMe(workspaceSlug.toString()) : null
|
|
);
|
|
|
|
if (!workspaceMemberMe && !error)
|
|
return (
|
|
<div className="grid h-screen place-items-center p-4">
|
|
<div className="flex flex-col items-center gap-3 text-center">
|
|
<h3 className="text-xl">Loading your workspace...</h3>
|
|
<Spinner />
|
|
</div>
|
|
</div>
|
|
);
|
|
|
|
if (error?.status === 401 || error?.status === 403) return <NotAWorkspaceMember />;
|
|
|
|
// FIXME: show 404 for workspace not workspace member
|
|
if (error?.status === 404) {
|
|
return (
|
|
<div className="container flex h-screen items-center justify-center">
|
|
<p className="text-2xl font-semibold">No such workspace exist. Create one?</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const settingsLayout = router.pathname.includes("/settings");
|
|
const memberType = {
|
|
isOwner: workspaceMemberMe?.role === 20,
|
|
isMember: workspaceMemberMe?.role === 15,
|
|
isViewer: workspaceMemberMe?.role === 10,
|
|
isGuest: workspaceMemberMe?.role === 5,
|
|
};
|
|
|
|
return (
|
|
<UserAuthorizationLayout>
|
|
<Container meta={meta}>
|
|
<CommandPalette />
|
|
<div className="relative flex h-screen w-full overflow-hidden">
|
|
<AppSidebar
|
|
toggleSidebar={toggleSidebar}
|
|
setToggleSidebar={setToggleSidebar}
|
|
isAnalyticsModalOpen={analyticsModal}
|
|
setAnalyticsModal={setAnalyticsModal}
|
|
/>
|
|
{settingsLayout && (memberType?.isGuest || memberType?.isViewer) ? (
|
|
<NotAuthorizedView
|
|
actionButton={
|
|
<Link href={`/${workspaceSlug}`}>
|
|
<a>
|
|
<PrimaryButton className="flex items-center gap-1">
|
|
<LayerDiagonalIcon height={16} width={16} color="white" /> Go to workspace
|
|
</PrimaryButton>
|
|
</a>
|
|
</Link>
|
|
}
|
|
type="workspace"
|
|
/>
|
|
) : (
|
|
<main
|
|
className={`relative flex h-full w-full flex-col overflow-hidden ${
|
|
bg === "primary"
|
|
? "bg-brand-surface-1"
|
|
: bg === "secondary"
|
|
? "bg-brand-sidebar"
|
|
: "bg-brand-base"
|
|
}`}
|
|
>
|
|
{analyticsModal && (
|
|
<AnalyticsWorkspaceModal
|
|
isOpen={analyticsModal}
|
|
onClose={() => setAnalyticsModal(false)}
|
|
/>
|
|
)}
|
|
{!noHeader && (
|
|
<AppHeader
|
|
breadcrumbs={breadcrumbs}
|
|
left={left}
|
|
right={right}
|
|
setToggleSidebar={setToggleSidebar}
|
|
/>
|
|
)}
|
|
<div className="h-full w-full overflow-hidden">
|
|
<div className="relative h-full w-full overflow-x-hidden overflow-y-scroll">
|
|
{children}
|
|
</div>
|
|
</div>
|
|
</main>
|
|
)}
|
|
</div>
|
|
</Container>
|
|
</UserAuthorizationLayout>
|
|
);
|
|
};
|