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";
|
2024-10-19 15:49:16 -04:00
|
|
|
import { internal } from "@app/api";
|
|
|
|
import { AxiosResponse } from "axios";
|
2024-10-19 16:37:40 -04:00
|
|
|
import { GetOrgResponse, ListOrgsResponse } from "@server/routers/org";
|
2024-10-19 15:49:16 -04:00
|
|
|
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",
|
2024-10-19 15:49:16 -04:00
|
|
|
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",
|
2024-10-19 15:49:16 -04:00
|
|
|
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",
|
2024-10-19 15:49:16 -04:00
|
|
|
icon: <Users className="h-5 w-5" />,
|
2024-10-13 22:49:14 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "General",
|
|
|
|
href: "/{orgId}/general",
|
2024-10-19 15:49:16 -04:00
|
|
|
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;
|
|
|
|
|
2024-10-19 15:49:16 -04:00
|
|
|
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();
|
|
|
|
|
2024-10-19 15:49:16 -04:00
|
|
|
try {
|
|
|
|
await internal.get<AxiosResponse<GetOrgResponse>>(
|
|
|
|
`/org/${params.orgId}`,
|
2024-10-23 13:30:23 -04:00
|
|
|
cookie
|
2024-10-19 15:49:16 -04:00
|
|
|
);
|
|
|
|
} 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
|
|
|
}
|