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";
|
|
|
|
// layouts
|
|
|
|
import AppHeader from "layouts/app-layout/app-header";
|
|
|
|
import AppSidebar from "layouts/app-layout/app-sidebar";
|
|
|
|
// 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 Props = {
|
|
|
|
children: React.ReactNode;
|
|
|
|
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> = ({
|
|
|
|
children,
|
|
|
|
noHeader = false,
|
|
|
|
bg = "primary",
|
|
|
|
breadcrumbs,
|
|
|
|
left,
|
|
|
|
right,
|
|
|
|
}) => {
|
|
|
|
const [toggleSidebar, setToggleSidebar] = useState(false);
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
|
|
|
const { loading, error, memberRole: memberType } = useProjectMyMembership();
|
|
|
|
|
|
|
|
const settingsLayout = router.pathname.includes("/settings");
|
|
|
|
|
|
|
|
return (
|
2023-05-29 10:08:35 +00:00
|
|
|
<>
|
2023-04-08 12:50:00 +00:00
|
|
|
<CommandPalette />
|
2023-05-05 11:37:29 +00:00
|
|
|
<div className="relative flex h-screen w-full overflow-hidden">
|
2023-05-16 05:11:37 +00:00
|
|
|
<AppSidebar toggleSidebar={toggleSidebar} setToggleSidebar={setToggleSidebar} />
|
2023-05-05 11:37:29 +00:00
|
|
|
|
2023-04-08 12:50:00 +00:00
|
|
|
{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-24 07:51:09 +00:00
|
|
|
<p className="text-2xl font-semibold">No such project exists. 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"
|
|
|
|
/>
|
|
|
|
) : (
|
2023-05-05 11:37:29 +00:00
|
|
|
<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"
|
|
|
|
}`}
|
|
|
|
>
|
2023-04-08 12:50:00 +00:00
|
|
|
{!noHeader && (
|
|
|
|
<AppHeader
|
|
|
|
breadcrumbs={breadcrumbs}
|
|
|
|
left={left}
|
|
|
|
right={right}
|
|
|
|
setToggleSidebar={setToggleSidebar}
|
|
|
|
/>
|
|
|
|
)}
|
2023-05-05 11:37:29 +00:00
|
|
|
<div className="h-full w-full overflow-hidden">
|
2023-05-11 12:08:46 +00:00
|
|
|
<div className="h-full w-full overflow-x-hidden overflow-y-scroll">{children}</div>
|
2023-04-08 12:50:00 +00:00
|
|
|
</div>
|
|
|
|
</main>
|
|
|
|
)}
|
|
|
|
</div>
|
2023-05-29 10:08:35 +00:00
|
|
|
</>
|
2023-04-08 08:16:46 +00:00
|
|
|
);
|
|
|
|
};
|