fosrl.pangolin/src/app/[orgId]/layout.tsx

100 lines
2.6 KiB
TypeScript
Raw Normal View History

2024-10-13 22:24:02 -04:00
import { Metadata } from "next";
import { TopbarNav } from "./components/TopbarNav";
2024-10-14 00:02:55 -04:00
import { Cog, Combine, LayoutGrid, Tent, Users, Waypoints } from "lucide-react";
2024-10-13 22:24:02 -04:00
import Header from "./components/Header";
2024-10-13 22:49:14 -04:00
import { verifySession } from "@app/lib/auth/verifySession";
import { redirect } from "next/navigation";
2024-10-14 18:26:07 -04:00
import { cache } from "react";
import { internal } from "@app/api";
import { AxiosResponse } from "axios";
2024-10-19 16:37:40 -04:00
import { GetOrgResponse, ListOrgsResponse } from "@server/routers/org";
import { authCookieHeader } from "@app/api/cookies";
2024-10-13 18:33:41 -04:00
export const metadata: Metadata = {
2024-10-26 17:24:31 -04:00
title: `Configuration - Pangolin`,
2024-10-13 22:24:02 -04:00
description: "",
};
2024-10-13 18:33:41 -04:00
2024-10-13 22:24:02 -04:00
const topNavItems = [
2024-10-13 18:33:41 -04:00
{
title: "Sites",
2024-10-13 22:49:14 -04:00
href: "/{orgId}/sites",
icon: <Combine className="h-5 w-5" />,
2024-10-13 18:33:41 -04:00
},
{
title: "Resources",
2024-10-13 22:49:14 -04:00
href: "/{orgId}/resources",
icon: <Waypoints className="h-5 w-5" />,
2024-10-13 18:33:41 -04:00
},
2024-10-13 22:49:14 -04:00
{
title: "Users",
href: "/{orgId}/users",
icon: <Users className="h-5 w-5" />,
2024-10-13 22:49:14 -04:00
},
{
title: "General",
href: "/{orgId}/general",
icon: <Cog className="h-5 w-5" />,
2024-10-13 22:49:14 -04:00
},
2024-10-13 22:24:02 -04:00
];
2024-10-13 18:33:41 -04:00
2024-10-13 22:24:02 -04:00
interface ConfigurationLaytoutProps {
children: React.ReactNode;
2024-10-23 13:30:23 -04:00
params: Promise<{ orgId: string }>;
2024-10-13 18:33:41 -04:00
}
2024-10-23 13:30:23 -04:00
export default async function ConfigurationLaytout(
props: ConfigurationLaytoutProps
) {
const params = await props.params;
const { children } = props;
const user = await verifySession();
2024-10-13 22:49:14 -04:00
if (!user) {
redirect("/auth/login");
}
2024-10-23 13:30:23 -04:00
const cookie = await authCookieHeader();
try {
await internal.get<AxiosResponse<GetOrgResponse>>(
`/org/${params.orgId}`,
2024-10-23 13:30:23 -04:00
cookie
);
} catch {
redirect(`/`);
}
2024-10-19 16:37:40 -04:00
let orgs: ListOrgsResponse["orgs"] = [];
2024-10-26 22:02:58 -04:00
try {
const res = await internal.get<AxiosResponse<ListOrgsResponse>>(
`/orgs`,
cookie
);
if (res && res.data.data.orgs) {
orgs = res.data.data.orgs;
}
} catch (e) {
console.error("Error fetching orgs", e);
}
2024-10-13 18:33:41 -04:00
return (
<>
2024-10-17 22:12:02 -04:00
<div className="w-full bg-muted mb-6 select-none sm:px-0 px-3 pt-3">
2024-10-15 23:52:58 -04:00
<div className="container mx-auto flex flex-col content-between gap-4 ">
2024-10-19 16:37:40 -04:00
<Header
email={user.email}
orgName={params.orgId}
orgs={orgs}
/>
2024-10-14 00:02:55 -04:00
<TopbarNav items={topNavItems} orgId={params.orgId} />
2024-10-13 18:33:41 -04:00
</div>
</div>
2024-10-13 22:24:02 -04:00
2024-10-13 22:49:14 -04:00
<div className="container mx-auto sm:px-0 px-3">{children}</div>
2024-10-13 18:33:41 -04:00
</>
2024-10-13 22:24:02 -04:00
);
2024-10-13 18:33:41 -04:00
}