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-07-17 10:58:23 +00:00
|
|
|
import { EmptyState, PrimaryButton, Spinner } from "components/ui";
|
2023-04-08 08:16:46 +00:00
|
|
|
// icons
|
|
|
|
import { LayerDiagonalIcon } from "components/icons";
|
2023-07-17 10:58:23 +00:00
|
|
|
// images
|
|
|
|
import emptyProject from "public/empty-state/project.svg";
|
2023-04-08 08:16:46 +00:00
|
|
|
|
|
|
|
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-07-17 10:58:23 +00:00
|
|
|
<div className="grid h-full w-full place-items-center p-4 bg-custom-background-100">
|
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-07-17 10:58:23 +00:00
|
|
|
<div className="container grid h-screen place-items-center bg-custom-background-100">
|
|
|
|
<EmptyState
|
|
|
|
title="No such project exists"
|
|
|
|
description="Try creating a new project"
|
|
|
|
image={emptyProject}
|
2023-08-01 08:28:58 +00:00
|
|
|
primaryButton={{
|
|
|
|
text: "Create Project",
|
|
|
|
onClick: () => {
|
|
|
|
const e = new KeyboardEvent("keydown", {
|
|
|
|
key: "p",
|
|
|
|
});
|
|
|
|
document.dispatchEvent(e);
|
|
|
|
},
|
2023-07-17 10:58:23 +00:00
|
|
|
}}
|
|
|
|
/>
|
2023-04-08 12:50:00 +00:00
|
|
|
</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"
|
2023-07-10 07:17:00 +00:00
|
|
|
? "bg-custom-background-100"
|
2023-05-05 11:37:29 +00:00
|
|
|
: bg === "secondary"
|
2023-07-10 07:17:00 +00:00
|
|
|
? "bg-custom-background-90"
|
|
|
|
: "bg-custom-background-80"
|
2023-05-05 11:37:29 +00:00
|
|
|
}`}
|
|
|
|
>
|
2023-06-24 12:42:11 +00:00
|
|
|
<AppHeader
|
|
|
|
breadcrumbs={breadcrumbs}
|
|
|
|
left={left}
|
|
|
|
right={right}
|
|
|
|
setToggleSidebar={setToggleSidebar}
|
|
|
|
noHeader={noHeader}
|
|
|
|
/>
|
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
|
|
|
);
|
|
|
|
};
|