2022-12-13 15:52:44 +00:00
|
|
|
// react
|
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
// next
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
// hooks
|
|
|
|
import useUser from "lib/hooks/useUser";
|
|
|
|
// layouts
|
2022-12-16 16:20:09 +00:00
|
|
|
import Container from "layouts/container";
|
2022-12-16 20:05:19 +00:00
|
|
|
import Sidebar from "layouts/navbar/main-siderbar";
|
2022-12-16 19:48:26 +00:00
|
|
|
import SettingsSidebar from "layouts/navbar/settings-sidebar";
|
|
|
|
import Header from "layouts/navbar/header";
|
2022-12-13 15:52:44 +00:00
|
|
|
// components
|
|
|
|
import CreateProjectModal from "components/project/create-project-modal";
|
|
|
|
// types
|
|
|
|
import { Meta } from "./types";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
meta?: Meta;
|
|
|
|
children: React.ReactNode;
|
|
|
|
noPadding?: boolean;
|
|
|
|
bg?: "primary" | "secondary";
|
2022-12-20 10:35:21 +00:00
|
|
|
noHeader?: boolean;
|
2022-12-13 15:52:44 +00:00
|
|
|
breadcrumbs?: JSX.Element;
|
2022-12-20 10:35:21 +00:00
|
|
|
left?: JSX.Element;
|
2022-12-13 15:52:44 +00:00
|
|
|
right?: JSX.Element;
|
2022-12-20 10:35:21 +00:00
|
|
|
type: "workspace" | "project";
|
2022-12-13 15:52:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const SettingsLayout: React.FC<Props> = ({
|
|
|
|
meta,
|
|
|
|
children,
|
|
|
|
noPadding = false,
|
|
|
|
bg = "primary",
|
2022-12-20 10:35:21 +00:00
|
|
|
noHeader = false,
|
2022-12-13 15:52:44 +00:00
|
|
|
breadcrumbs,
|
2022-12-20 10:35:21 +00:00
|
|
|
left,
|
2022-12-13 15:52:44 +00:00
|
|
|
right,
|
2022-12-20 10:35:21 +00:00
|
|
|
type,
|
2022-12-13 15:52:44 +00:00
|
|
|
}) => {
|
|
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
2022-12-20 10:35:21 +00:00
|
|
|
const { activeWorkspace, activeProject, user, isUserLoading } = useUser();
|
2022-12-13 15:52:44 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!isUserLoading && (!user || user === null)) router.push("/signin");
|
|
|
|
}, [isUserLoading, user, router]);
|
|
|
|
|
2022-12-20 10:35:21 +00:00
|
|
|
const workspaceLinks: {
|
|
|
|
label: string;
|
|
|
|
href: string;
|
|
|
|
}[] = [
|
|
|
|
{
|
|
|
|
label: "General",
|
|
|
|
href: "#",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Control",
|
|
|
|
href: "#",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "States",
|
|
|
|
href: "#",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Labels",
|
|
|
|
href: "#",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const sidebarLinks: {
|
|
|
|
label: string;
|
|
|
|
href: string;
|
|
|
|
}[] = [
|
|
|
|
{
|
|
|
|
label: "General",
|
|
|
|
href: `/projects/${activeProject?.id}/settings`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Control",
|
|
|
|
href: `/projects/${activeProject?.id}/settings/control`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Members",
|
|
|
|
href: `/projects/${activeProject?.id}/settings/members`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "States",
|
|
|
|
href: `/projects/${activeProject?.id}/settings/states`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Labels",
|
|
|
|
href: `/projects/${activeProject?.id}/settings/labels`,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-12-13 15:52:44 +00:00
|
|
|
return (
|
|
|
|
<Container meta={meta}>
|
|
|
|
<CreateProjectModal isOpen={isOpen} setIsOpen={setIsOpen} />
|
|
|
|
<div className="h-screen w-full flex overflow-x-hidden">
|
2022-12-20 10:35:21 +00:00
|
|
|
<Sidebar collapse />
|
|
|
|
<SettingsSidebar links={type === "workspace" ? workspaceLinks : sidebarLinks} />
|
2022-12-13 15:52:44 +00:00
|
|
|
<main className="h-screen w-full flex flex-col overflow-y-auto min-w-0">
|
2022-12-20 10:35:21 +00:00
|
|
|
{noHeader ? null : <Header breadcrumbs={breadcrumbs} left={left} right={right} />}
|
2022-12-13 15:52:44 +00:00
|
|
|
<div
|
2022-12-20 15:44:42 +00:00
|
|
|
className={`w-full flex-grow ${noPadding ? "" : "p-5 px-16"} ${
|
2022-12-13 15:52:44 +00:00
|
|
|
bg === "primary" ? "bg-primary" : bg === "secondary" ? "bg-secondary" : "bg-primary"
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
</main>
|
|
|
|
</div>
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SettingsLayout;
|