refactor resources

This commit is contained in:
Milo Schwartz
2024-11-11 00:00:16 -05:00
parent e77fb37ef1
commit 36bbb412dd
7 changed files with 441 additions and 378 deletions

View File

@@ -5,6 +5,8 @@ import { AxiosResponse } from "axios";
import { redirect } from "next/navigation";
import { authCookieHeader } from "@app/api/cookies";
import { SidebarSettings } from "@app/components/SidebarSettings";
import Link from "next/link";
import { ArrowLeft } from "lucide-react";
interface ResourceLayoutProps {
children: React.ReactNode;
@@ -18,22 +20,20 @@ export default async function ResourceLayout(props: ResourceLayoutProps) {
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`);
}
try {
const res = await internal.get<AxiosResponse<GetResourceResponse>>(
`/resource/${params.resourceId}`,
await authCookieHeader()
);
resource = res.data.data;
} catch {
redirect(`/${params.orgId}/settings/resources`);
}
const sidebarNavItems = [
{
title: "General",
href: `/{orgId}/settings/resources/resourceId`,
href: `/{orgId}/settings/resources/{resourceId}/general`,
},
{
title: "Targets",
@@ -41,27 +41,31 @@ export default async function ResourceLayout(props: ResourceLayoutProps) {
},
];
const isCreate = params.resourceId === "create";
return (
<>
<div className="mb-4">
<Link
href="../../"
className="text-muted-foreground hover:underline"
>
<div className="flex flex-row items-center gap-1">
<ArrowLeft /> <span>All Resources</span>
</div>
</Link>
</div>
<div className="space-y-0.5 select-none mb-6">
<h2 className="text-2xl font-bold tracking-tight">
{isCreate ? "New Resource" : resource?.name + " Settings"}
{resource?.name + " Settings"}
</h2>
<p className="text-muted-foreground">
{isCreate
? "Create a new resource"
: "Configure the settings on your resource: " +
resource?.name || ""}
.
Configure the settings on your resource
</p>
</div>
<ResourceProvider resource={resource}>
<SidebarSettings
sidebarNavItems={sidebarNavItems}
disabled={isCreate}
limitWidth={true}
>
{children}