2023-04-08 08:16:46 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
|
|
|
|
import Link from "next/link";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
// contexts
|
|
|
|
import { useProjectMyMembership, ProjectMemberProvider } from "contexts/project-member.context";
|
2023-04-13 10:09:05 +00:00
|
|
|
// hooks
|
|
|
|
import useIssuesView from "hooks/use-issues-view";
|
2023-04-08 08:16:46 +00:00
|
|
|
// layouts
|
|
|
|
import Container from "layouts/container";
|
|
|
|
import AppHeader from "layouts/app-layout/app-header";
|
|
|
|
import AppSidebar from "layouts/app-layout/app-sidebar";
|
|
|
|
import SettingsNavbar from "layouts/settings-navbar";
|
|
|
|
// components
|
|
|
|
import { NotAuthorizedView, JoinProject } from "components/auth-screens";
|
|
|
|
import { CommandPalette } from "components/command-palette";
|
|
|
|
// ui
|
2023-04-08 12:50:00 +00:00
|
|
|
import { PrimaryButton, Spinner } from "components/ui";
|
2023-04-08 08:16:46 +00:00
|
|
|
// icons
|
|
|
|
import { LayerDiagonalIcon } from "components/icons";
|
|
|
|
|
|
|
|
type Meta = {
|
|
|
|
title?: string | null;
|
|
|
|
description?: string | null;
|
|
|
|
image?: string | null;
|
|
|
|
url?: string | null;
|
|
|
|
};
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
meta?: Meta;
|
|
|
|
children: React.ReactNode;
|
|
|
|
noPadding?: boolean;
|
|
|
|
noHeader?: boolean;
|
|
|
|
bg?: "primary" | "secondary";
|
|
|
|
breadcrumbs?: JSX.Element;
|
|
|
|
left?: JSX.Element;
|
|
|
|
right?: JSX.Element;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ProjectAuthorizationWrapper: React.FC<Props> = (props) => (
|
|
|
|
<ProjectMemberProvider>
|
|
|
|
<ProjectAuthorizationWrapped {...props} />
|
|
|
|
</ProjectMemberProvider>
|
|
|
|
);
|
|
|
|
|
|
|
|
const ProjectAuthorizationWrapped: React.FC<Props> = ({
|
|
|
|
meta,
|
|
|
|
children,
|
|
|
|
noPadding = false,
|
|
|
|
noHeader = false,
|
|
|
|
bg = "primary",
|
|
|
|
breadcrumbs,
|
|
|
|
left,
|
|
|
|
right,
|
|
|
|
}) => {
|
|
|
|
const [toggleSidebar, setToggleSidebar] = useState(false);
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
2023-04-17 12:52:04 +00:00
|
|
|
const { issueView } = useIssuesView();
|
2023-04-13 10:09:05 +00:00
|
|
|
|
2023-04-08 08:16:46 +00:00
|
|
|
const { loading, error, memberRole: memberType } = useProjectMyMembership();
|
|
|
|
|
|
|
|
const settingsLayout = router.pathname.includes("/settings");
|
|
|
|
|
|
|
|
return (
|
2023-04-08 12:50:00 +00:00
|
|
|
<Container meta={meta}>
|
|
|
|
<CommandPalette />
|
|
|
|
<div className="flex h-screen w-full overflow-x-hidden">
|
|
|
|
<AppSidebar toggleSidebar={toggleSidebar} setToggleSidebar={setToggleSidebar} />
|
|
|
|
{loading ? (
|
2023-04-20 12:43:21 +00:00
|
|
|
<div className="grid h-full w-full place-items-center p-4">
|
2023-04-08 12:50:00 +00:00
|
|
|
<div className="flex flex-col items-center gap-3 text-center">
|
2023-04-19 15:22:52 +00:00
|
|
|
<h3 className="text-xl">Loading your project...</h3>
|
2023-04-08 12:50:00 +00:00
|
|
|
<Spinner />
|
2023-04-08 08:16:46 +00:00
|
|
|
</div>
|
2023-04-08 12:50:00 +00:00
|
|
|
</div>
|
|
|
|
) : error?.status === 401 || error?.status === 403 ? (
|
|
|
|
<JoinProject />
|
|
|
|
) : error?.status === 404 ? (
|
2023-04-20 12:43:21 +00:00
|
|
|
<div className="container grid h-screen place-items-center">
|
|
|
|
<div className="space-y-4 text-center">
|
2023-04-08 12:50:00 +00:00
|
|
|
<p className="text-2xl font-semibold">No such project exist. Create one?</p>
|
2023-04-11 12:24:01 +00:00
|
|
|
<PrimaryButton
|
2023-04-08 12:50:00 +00:00
|
|
|
onClick={() => {
|
|
|
|
const e = new KeyboardEvent("keydown", { key: "p" });
|
|
|
|
document.dispatchEvent(e);
|
|
|
|
}}
|
2023-04-08 12:35:54 +00:00
|
|
|
>
|
2023-04-08 12:50:00 +00:00
|
|
|
Create project
|
|
|
|
</PrimaryButton>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) : settingsLayout && (memberType?.isGuest || memberType?.isViewer) ? (
|
|
|
|
<NotAuthorizedView
|
|
|
|
actionButton={
|
|
|
|
<Link href={`/${workspaceSlug}/projects/${projectId}/issues`}>
|
|
|
|
<a>
|
|
|
|
<PrimaryButton className="flex items-center gap-1">
|
|
|
|
<LayerDiagonalIcon height={16} width={16} color="white" /> Go to issues
|
|
|
|
</PrimaryButton>
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
}
|
|
|
|
type="project"
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<main className="flex h-screen w-full min-w-0 flex-col overflow-y-auto">
|
|
|
|
{!noHeader && (
|
|
|
|
<AppHeader
|
|
|
|
breadcrumbs={breadcrumbs}
|
|
|
|
left={left}
|
|
|
|
right={right}
|
|
|
|
setToggleSidebar={setToggleSidebar}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<div
|
|
|
|
className={`flex w-full flex-grow flex-col ${
|
2023-04-13 10:09:05 +00:00
|
|
|
noPadding || issueView === "list" ? "" : settingsLayout ? "p-8 lg:px-28" : "p-8"
|
2023-04-08 12:50:00 +00:00
|
|
|
} ${
|
2023-04-20 12:43:21 +00:00
|
|
|
bg === "primary"
|
|
|
|
? "bg-brand-base"
|
|
|
|
: bg === "secondary"
|
|
|
|
? "bg-brand-surface-1"
|
|
|
|
: "bg-brand-base"
|
2023-04-08 12:50:00 +00:00
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{settingsLayout && (
|
|
|
|
<div className="mb-12 space-y-6">
|
|
|
|
<div>
|
|
|
|
<h3 className="text-3xl font-semibold">Project Settings</h3>
|
|
|
|
<p className="mt-1 text-gray-600">
|
|
|
|
This information will be displayed to every member of the project.
|
|
|
|
</p>
|
2023-04-08 12:35:54 +00:00
|
|
|
</div>
|
2023-04-08 12:50:00 +00:00
|
|
|
<SettingsNavbar />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
</main>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</Container>
|
2023-04-08 08:16:46 +00:00
|
|
|
);
|
|
|
|
};
|