2024-10-13 22:24:02 -04:00
|
|
|
import { Metadata } from "next";
|
|
|
|
import { TopbarNav } from "./components/TopbarNav";
|
2024-11-02 15:44:48 -04:00
|
|
|
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";
|
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-11-03 13:57:51 -05:00
|
|
|
import { cache } from "react";
|
|
|
|
|
|
|
|
export const dynamic = "force-dynamic";
|
2024-10-13 18:33:41 -04:00
|
|
|
|
|
|
|
export const metadata: Metadata = {
|
2024-11-02 15:44:48 -04:00
|
|
|
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",
|
2024-11-02 15:44:48 -04:00
|
|
|
href: "/{orgId}/settings/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-11-02 15:44:48 -04:00
|
|
|
href: "/{orgId}/settings/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",
|
2024-11-02 15:44:48 -04:00
|
|
|
href: "/{orgId}/settings/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",
|
2024-11-02 15:44:48 -04:00
|
|
|
href: "/{orgId}/settings/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-11-02 15:44:48 -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
|
|
|
}
|
|
|
|
|
2024-11-02 15:44:48 -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;
|
|
|
|
|
2024-11-03 13:57:51 -05:00
|
|
|
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();
|
|
|
|
|
2024-10-19 15:49:16 -04:00
|
|
|
try {
|
2024-11-03 13:57:51 -05:00
|
|
|
const getOrg = cache(() =>
|
|
|
|
internal.get<AxiosResponse<GetOrgResponse>>(
|
|
|
|
`/org/${params.orgId}`,
|
|
|
|
cookie
|
|
|
|
)
|
2024-10-19 15:49:16 -04:00
|
|
|
);
|
2024-11-03 13:57:51 -05:00
|
|
|
const org = await getOrg();
|
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 {
|
2024-11-03 13:57:51 -05:00
|
|
|
const getOrgs = cache(() =>
|
|
|
|
internal.get<AxiosResponse<ListOrgsResponse>>(`/orgs`, cookie)
|
2024-10-26 22:02:58 -04:00
|
|
|
);
|
2024-11-03 13:57:51 -05: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 (
|
|
|
|
<>
|
2024-11-08 00:03:54 -05:00
|
|
|
<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
|
|
|
}
|