Merge branch 'main' of https://github.com/fosrl/pangolin
This commit is contained in:
commit
cc767a7ccd
5 changed files with 74 additions and 71 deletions
|
@ -18,7 +18,6 @@ export type GetSiteResponse = {
|
|||
siteId: number;
|
||||
name: string;
|
||||
subdomain: string;
|
||||
pubKey: string;
|
||||
subnet: string;
|
||||
}
|
||||
|
||||
|
@ -59,7 +58,12 @@ export async function getSite(req: Request, res: Response, next: NextFunction):
|
|||
}
|
||||
|
||||
return response(res, {
|
||||
data: site[0],
|
||||
data: {
|
||||
siteId: site[0].siteId,
|
||||
name: site[0].name,
|
||||
subdomain: site[0].subdomain,
|
||||
subnet: site[0].subnet,
|
||||
},
|
||||
success: true,
|
||||
error: false,
|
||||
message: "Site retrieved successfully",
|
||||
|
|
|
@ -12,29 +12,25 @@ export const metadata: Metadata = {
|
|||
const sidebarNavItems = [
|
||||
{
|
||||
title: "Profile",
|
||||
href: "/configuration/resources/{resourceId}/",
|
||||
},
|
||||
{
|
||||
title: "Account",
|
||||
href: "/configuration/resources/{resourceId}/account",
|
||||
href: "/{orgId}/resources/{resourceId}/",
|
||||
},
|
||||
{
|
||||
title: "Appearance",
|
||||
href: "/configuration/resources/{resourceId}/appearance",
|
||||
href: "/{orgId}/resources/{resourceId}/appearance",
|
||||
},
|
||||
{
|
||||
title: "Notifications",
|
||||
href: "/configuration/resources/{resourceId}/notifications",
|
||||
href: "/{orgId}/resources/{resourceId}/notifications",
|
||||
},
|
||||
{
|
||||
title: "Display",
|
||||
href: "/configuration/resources/{resourceId}/display",
|
||||
href: "/{orgId}/resources/{resourceId}/display",
|
||||
},
|
||||
]
|
||||
|
||||
interface SettingsLayoutProps {
|
||||
children: React.ReactNode,
|
||||
params: { resourceId: string }
|
||||
params: { resourceId: string, orgId: string }
|
||||
}
|
||||
|
||||
export default function SettingsLayout({ children, params }: SettingsLayoutProps) {
|
||||
|
@ -66,7 +62,7 @@ export default function SettingsLayout({ children, params }: SettingsLayoutProps
|
|||
<Separator className="my-6" />
|
||||
<div className="flex flex-col space-y-8 lg:flex-row lg:space-x-12 lg:space-y-0">
|
||||
<aside className="-mx-4 lg:w-1/5">
|
||||
<SidebarNav items={sidebarNavItems.map(i => { i.href = i.href.replace("{resourceId}", params.resourceId); return i})} />
|
||||
<SidebarNav items={sidebarNavItems.map(i => { i.href = i.href.replace("{resourceId}", params.resourceId).replace("{orgId}", params.orgId); return i})} />
|
||||
</aside>
|
||||
<div className="flex-1 lg:max-w-2xl">{children}</div>
|
||||
</div>
|
||||
|
|
|
@ -17,46 +17,45 @@ export const metadata: Metadata = {
|
|||
const sidebarNavItems = [
|
||||
{
|
||||
title: "Profile",
|
||||
href: "/configuration/sites/{siteId}/",
|
||||
},
|
||||
{
|
||||
title: "Account",
|
||||
href: "/configuration/sites/{siteId}/account",
|
||||
href: "/{orgId}/sites/{siteId}/",
|
||||
},
|
||||
{
|
||||
title: "Appearance",
|
||||
href: "/configuration/sites/{siteId}/appearance",
|
||||
href: "/{orgId}/sites/{siteId}/appearance",
|
||||
},
|
||||
{
|
||||
title: "Notifications",
|
||||
href: "/configuration/sites/{siteId}/notifications",
|
||||
href: "/{orgId}/sites/{siteId}/notifications",
|
||||
},
|
||||
{
|
||||
title: "Display",
|
||||
href: "/configuration/sites/{siteId}/display",
|
||||
href: "/{orgId}/sites/{siteId}/display",
|
||||
},
|
||||
]
|
||||
|
||||
interface SettingsLayoutProps {
|
||||
children: React.ReactNode,
|
||||
params: { siteId: string }
|
||||
params: { siteId: string, orgId: string }
|
||||
}
|
||||
|
||||
export default async function SettingsLayout({ children, params }: SettingsLayoutProps) {
|
||||
const sessionId = cookies().get("session")?.value ?? null;
|
||||
const res = await internal
|
||||
.get<AxiosResponse<GetSiteResponse>>(`/site/${params.siteId}`, {
|
||||
headers: {
|
||||
Cookie: `session=${sessionId}`,
|
||||
},
|
||||
});
|
||||
let site = null;
|
||||
if (params.siteId !== "create") {
|
||||
try {
|
||||
const sessionId = cookies().get("session")?.value ?? null;
|
||||
const res = await internal
|
||||
.get<AxiosResponse<GetSiteResponse>>(`/site/${params.siteId}`, {
|
||||
headers: {
|
||||
Cookie: `session=${sessionId}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (!res || res.status !== 200) {
|
||||
return <div>Failed to load site</div>;
|
||||
site = res.data.data;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const site = res.data.data;
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="md:hidden">
|
||||
|
@ -85,7 +84,7 @@ export default async function SettingsLayout({ children, params }: SettingsLayou
|
|||
<Separator className="my-6" />
|
||||
<div className="flex flex-col space-y-8 lg:flex-row lg:space-x-12 lg:space-y-0">
|
||||
<aside className="-mx-4 lg:w-1/5">
|
||||
<SidebarNav items={sidebarNavItems.map(i => { i.href = i.href.replace("{siteId}", params.siteId); return i})} disabled={params.siteId == "create"} />
|
||||
<SidebarNav items={sidebarNavItems} disabled={params.siteId == "create"} />
|
||||
</aside>
|
||||
<div className="flex-1 lg:max-w-2xl">
|
||||
<SiteProvider site={site}>
|
||||
|
|
|
@ -1,49 +1,53 @@
|
|||
"use client"
|
||||
import React from 'react'
|
||||
import Link from "next/link"
|
||||
import { usePathname } from "next/navigation"
|
||||
import { useParams, usePathname, useRouter } from "next/navigation"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { buttonVariants } from "@/components/ui/button"
|
||||
|
||||
interface SidebarNavProps extends React.HTMLAttributes<HTMLElement> {
|
||||
items: {
|
||||
href: string
|
||||
title: string
|
||||
}[]
|
||||
disabled?: boolean
|
||||
items: {
|
||||
href: string
|
||||
title: string
|
||||
}[]
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
export function SidebarNav({ className, items, disabled = false, ...props }: SidebarNavProps) {
|
||||
const pathname = usePathname()
|
||||
const pathname = usePathname();
|
||||
const params = useParams();
|
||||
const orgId = params.orgId as string;
|
||||
const siteId = params.siteId as string;
|
||||
const resourceId = params.resourceId as string;
|
||||
|
||||
return (
|
||||
<nav
|
||||
className={cn(
|
||||
"flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1",
|
||||
disabled && "opacity-50 pointer-events-none",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{items.map((item) => (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
className={cn(
|
||||
buttonVariants({ variant: "ghost" }),
|
||||
pathname === item.href
|
||||
? "bg-muted hover:bg-muted"
|
||||
: "hover:bg-transparent hover:underline",
|
||||
"justify-start",
|
||||
disabled && "cursor-not-allowed"
|
||||
)}
|
||||
onClick={disabled ? (e) => e.preventDefault() : undefined}
|
||||
tabIndex={disabled ? -1 : undefined}
|
||||
aria-disabled={disabled}
|
||||
return (
|
||||
<nav
|
||||
className={cn(
|
||||
"flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1",
|
||||
disabled && "opacity-50 pointer-events-none",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{item.title}
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
)
|
||||
{items.map((item) => (
|
||||
<Link
|
||||
key={item.href.replace("{orgId}", orgId).replace("{siteId}", siteId).replace("{resourceId}", resourceId)}
|
||||
href={item.href.replace("{orgId}", orgId).replace("{siteId}", siteId).replace("{resourceId}", resourceId)}
|
||||
className={cn(
|
||||
buttonVariants({ variant: "ghost" }),
|
||||
pathname === item.href.replace("{orgId}", orgId).replace("{siteId}", siteId).replace("{resourceId}", resourceId)
|
||||
? "bg-muted hover:bg-muted"
|
||||
: "hover:bg-transparent hover:underline",
|
||||
"justify-start",
|
||||
disabled && "cursor-not-allowed"
|
||||
)}
|
||||
onClick={disabled ? (e) => e.preventDefault() : undefined}
|
||||
tabIndex={disabled ? -1 : undefined}
|
||||
aria-disabled={disabled}
|
||||
>
|
||||
{item.title}
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
)
|
||||
}
|
|
@ -5,7 +5,7 @@ import { GetSiteResponse } from "@server/routers/site/getSite";
|
|||
import { ReactNode } from "react";
|
||||
|
||||
type LandingProviderProps = {
|
||||
site: GetSiteResponse;
|
||||
site: GetSiteResponse | null;
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue