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

104 lines
2.8 KiB
TypeScript
Raw Normal View History

2024-10-13 22:24:02 -04:00
import { Metadata } from "next";
import { TopbarNav } from "./components/TopbarNav";
import { Cog, Combine, 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";
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";
import { cache } from "react";
export const dynamic = "force-dynamic";
2024-10-13 18:33:41 -04:00
export const metadata: Metadata = {
title: `Settings - 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",
href: "/{orgId}/settings/sites",
icon: <Combine className="h-5 w-5" />,
2024-10-13 18:33:41 -04:00
},
{
title: "Resources",
href: "/{orgId}/settings/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}/settings/users",
icon: <Users className="h-5 w-5" />,
2024-10-13 22:49:14 -04:00
},
{
title: "General",
href: "/{orgId}/settings/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
interface SettingsLayoutProps {
2024-10-13 22:24:02 -04:00
children: React.ReactNode;
2024-10-23 13:30:23 -04:00
params: Promise<{ orgId: string }>;
2024-10-13 18:33:41 -04:00
}
export default async function SettingsLayout(props: SettingsLayoutProps) {
2024-10-23 13:30:23 -04:00
const params = await props.params;
const { children } = props;
const getUser = cache(verifySession);
const user = await getUser();
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 {
const getOrg = cache(() =>
internal.get<AxiosResponse<GetOrgResponse>>(
`/org/${params.orgId}`,
cookie
)
);
const org = await getOrg();
} catch {
redirect(`/`);
}
2024-10-19 16:37:40 -04:00
let orgs: ListOrgsResponse["orgs"] = [];
2024-10-26 22:02:58 -04:00
try {
const getOrgs = cache(() =>
internal.get<AxiosResponse<ListOrgsResponse>>(`/orgs`, cookie)
2024-10-26 22:02:58 -04:00
);
const res = await getOrgs();
2024-10-26 22:02:58 -04:00
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 (
<>
<div className="w-full border-b bg-neutral-100 dark:bg-neutral-900 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
}