mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-03 02:53:56 +00:00
clean up naming and add /settings/ to path
This commit is contained in:
51
src/app/[orgId]/settings/resources/[resourceId]/layout.tsx
Normal file
51
src/app/[orgId]/settings/resources/[resourceId]/layout.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
import Image from "next/image";
|
||||
import ResourceProvider from "@app/providers/ResourceProvider";
|
||||
import { internal } from "@app/api";
|
||||
import { GetResourceResponse } from "@server/routers/resource";
|
||||
import { AxiosResponse } from "axios";
|
||||
import { redirect } from "next/navigation";
|
||||
import { authCookieHeader } from "@app/api/cookies";
|
||||
import Link from "next/link";
|
||||
import { ClientLayout } from "./components/ClientLayout";
|
||||
|
||||
interface ResourceLayoutProps {
|
||||
children: React.ReactNode;
|
||||
params: Promise<{ resourceId: number | string; orgId: string }>;
|
||||
}
|
||||
|
||||
export default async function ResourceLayout(props: ResourceLayoutProps) {
|
||||
const params = await props.params;
|
||||
|
||||
const { children } = props;
|
||||
|
||||
let resource = null;
|
||||
|
||||
if (params.resourceId !== "create") {
|
||||
try {
|
||||
const res = await internal.get<AxiosResponse<GetResourceResponse>>(
|
||||
`/resource/${params.resourceId}`,
|
||||
await authCookieHeader()
|
||||
);
|
||||
resource = res.data.data;
|
||||
} catch {
|
||||
redirect(`/${params.orgId}/settings/resources`);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="mb-4">
|
||||
<Link
|
||||
href={`/${params.orgId}/settings/resources`}
|
||||
className="text-primary font-medium"
|
||||
></Link>
|
||||
</div>
|
||||
|
||||
<ResourceProvider resource={resource}>
|
||||
<ClientLayout isCreate={params.resourceId === "create"}>
|
||||
{children}
|
||||
</ClientLayout>
|
||||
</ResourceProvider>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user