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;
|
siteId: number;
|
||||||
name: string;
|
name: string;
|
||||||
subdomain: string;
|
subdomain: string;
|
||||||
pubKey: string;
|
|
||||||
subnet: string;
|
subnet: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +58,12 @@ export async function getSite(req: Request, res: Response, next: NextFunction):
|
||||||
}
|
}
|
||||||
|
|
||||||
return response(res, {
|
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,
|
success: true,
|
||||||
error: false,
|
error: false,
|
||||||
message: "Site retrieved successfully",
|
message: "Site retrieved successfully",
|
||||||
|
|
|
@ -12,29 +12,25 @@ export const metadata: Metadata = {
|
||||||
const sidebarNavItems = [
|
const sidebarNavItems = [
|
||||||
{
|
{
|
||||||
title: "Profile",
|
title: "Profile",
|
||||||
href: "/configuration/resources/{resourceId}/",
|
href: "/{orgId}/resources/{resourceId}/",
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Account",
|
|
||||||
href: "/configuration/resources/{resourceId}/account",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Appearance",
|
title: "Appearance",
|
||||||
href: "/configuration/resources/{resourceId}/appearance",
|
href: "/{orgId}/resources/{resourceId}/appearance",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Notifications",
|
title: "Notifications",
|
||||||
href: "/configuration/resources/{resourceId}/notifications",
|
href: "/{orgId}/resources/{resourceId}/notifications",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Display",
|
title: "Display",
|
||||||
href: "/configuration/resources/{resourceId}/display",
|
href: "/{orgId}/resources/{resourceId}/display",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
interface SettingsLayoutProps {
|
interface SettingsLayoutProps {
|
||||||
children: React.ReactNode,
|
children: React.ReactNode,
|
||||||
params: { resourceId: string }
|
params: { resourceId: string, orgId: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function SettingsLayout({ children, params }: SettingsLayoutProps) {
|
export default function SettingsLayout({ children, params }: SettingsLayoutProps) {
|
||||||
|
@ -66,7 +62,7 @@ export default function SettingsLayout({ children, params }: SettingsLayoutProps
|
||||||
<Separator className="my-6" />
|
<Separator className="my-6" />
|
||||||
<div className="flex flex-col space-y-8 lg:flex-row lg:space-x-12 lg:space-y-0">
|
<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">
|
<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>
|
</aside>
|
||||||
<div className="flex-1 lg:max-w-2xl">{children}</div>
|
<div className="flex-1 lg:max-w-2xl">{children}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -17,46 +17,45 @@ export const metadata: Metadata = {
|
||||||
const sidebarNavItems = [
|
const sidebarNavItems = [
|
||||||
{
|
{
|
||||||
title: "Profile",
|
title: "Profile",
|
||||||
href: "/configuration/sites/{siteId}/",
|
href: "/{orgId}/sites/{siteId}/",
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Account",
|
|
||||||
href: "/configuration/sites/{siteId}/account",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Appearance",
|
title: "Appearance",
|
||||||
href: "/configuration/sites/{siteId}/appearance",
|
href: "/{orgId}/sites/{siteId}/appearance",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Notifications",
|
title: "Notifications",
|
||||||
href: "/configuration/sites/{siteId}/notifications",
|
href: "/{orgId}/sites/{siteId}/notifications",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Display",
|
title: "Display",
|
||||||
href: "/configuration/sites/{siteId}/display",
|
href: "/{orgId}/sites/{siteId}/display",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
interface SettingsLayoutProps {
|
interface SettingsLayoutProps {
|
||||||
children: React.ReactNode,
|
children: React.ReactNode,
|
||||||
params: { siteId: string }
|
params: { siteId: string, orgId: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function SettingsLayout({ children, params }: SettingsLayoutProps) {
|
export default async function SettingsLayout({ children, params }: SettingsLayoutProps) {
|
||||||
const sessionId = cookies().get("session")?.value ?? null;
|
let site = null;
|
||||||
const res = await internal
|
if (params.siteId !== "create") {
|
||||||
.get<AxiosResponse<GetSiteResponse>>(`/site/${params.siteId}`, {
|
try {
|
||||||
headers: {
|
const sessionId = cookies().get("session")?.value ?? null;
|
||||||
Cookie: `session=${sessionId}`,
|
const res = await internal
|
||||||
},
|
.get<AxiosResponse<GetSiteResponse>>(`/site/${params.siteId}`, {
|
||||||
});
|
headers: {
|
||||||
|
Cookie: `session=${sessionId}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (!res || res.status !== 200) {
|
site = res.data.data;
|
||||||
return <div>Failed to load site</div>;
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const site = res.data.data;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="md:hidden">
|
<div className="md:hidden">
|
||||||
|
@ -85,7 +84,7 @@ export default async function SettingsLayout({ children, params }: SettingsLayou
|
||||||
<Separator className="my-6" />
|
<Separator className="my-6" />
|
||||||
<div className="flex flex-col space-y-8 lg:flex-row lg:space-x-12 lg:space-y-0">
|
<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">
|
<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>
|
</aside>
|
||||||
<div className="flex-1 lg:max-w-2xl">
|
<div className="flex-1 lg:max-w-2xl">
|
||||||
<SiteProvider site={site}>
|
<SiteProvider site={site}>
|
||||||
|
|
|
@ -1,49 +1,53 @@
|
||||||
"use client"
|
"use client"
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { usePathname } from "next/navigation"
|
import { useParams, usePathname, useRouter } from "next/navigation"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import { buttonVariants } from "@/components/ui/button"
|
import { buttonVariants } from "@/components/ui/button"
|
||||||
|
|
||||||
interface SidebarNavProps extends React.HTMLAttributes<HTMLElement> {
|
interface SidebarNavProps extends React.HTMLAttributes<HTMLElement> {
|
||||||
items: {
|
items: {
|
||||||
href: string
|
href: string
|
||||||
title: string
|
title: string
|
||||||
}[]
|
}[]
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SidebarNav({ className, items, disabled = false, ...props }: SidebarNavProps) {
|
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 (
|
return (
|
||||||
<nav
|
<nav
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1",
|
"flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1",
|
||||||
disabled && "opacity-50 pointer-events-none",
|
disabled && "opacity-50 pointer-events-none",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...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}
|
|
||||||
>
|
>
|
||||||
{item.title}
|
{items.map((item) => (
|
||||||
</Link>
|
<Link
|
||||||
))}
|
key={item.href.replace("{orgId}", orgId).replace("{siteId}", siteId).replace("{resourceId}", resourceId)}
|
||||||
</nav>
|
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";
|
import { ReactNode } from "react";
|
||||||
|
|
||||||
type LandingProviderProps = {
|
type LandingProviderProps = {
|
||||||
site: GetSiteResponse;
|
site: GetSiteResponse | null;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue