mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-31 06:59:33 +02:00
Add site context?
This commit is contained in:
parent
b53d093065
commit
ab41695988
3 changed files with 26 additions and 12 deletions
|
@ -4,7 +4,10 @@ import Image from "next/image"
|
||||||
import { Separator } from "@/components/ui/separator"
|
import { Separator } from "@/components/ui/separator"
|
||||||
import { SidebarNav } from "@/components/sidebar-nav"
|
import { SidebarNav } from "@/components/sidebar-nav"
|
||||||
import SiteProvider from "@app/providers/SiteProvider"
|
import SiteProvider from "@app/providers/SiteProvider"
|
||||||
import api from "@app/api"
|
import { internal } from "@app/api"
|
||||||
|
import { cookies } from "next/headers"
|
||||||
|
import { GetSiteResponse } from "@server/routers/site"
|
||||||
|
import { AxiosResponse } from "axios"
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Forms",
|
title: "Forms",
|
||||||
|
@ -40,20 +43,19 @@ interface SettingsLayoutProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function SettingsLayout({ children, params }: SettingsLayoutProps) {
|
export default async function SettingsLayout({ children, params }: SettingsLayoutProps) {
|
||||||
const res = await api
|
const sessionId = cookies().get("session")?.value ?? null;
|
||||||
.get(`/site/${params.siteId}`, {})
|
const res = await internal
|
||||||
.catch((e) => {
|
.get<AxiosResponse<GetSiteResponse>>(`/site/${params.siteId}`, {
|
||||||
console.error("Failed to fetch site", e);
|
headers: {
|
||||||
|
Cookie: `session=${sessionId}`,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(res);
|
if (!res || res.status !== 200) {
|
||||||
|
return <div>Failed to load site</div>;
|
||||||
console.log(params.siteId);
|
}
|
||||||
|
|
||||||
// const site = res!.data.data;
|
|
||||||
|
|
||||||
// console.log(site);
|
const site = res.data.data;
|
||||||
const site: any = {};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {
|
||||||
FormMessage,
|
FormMessage,
|
||||||
} from "@/components/ui/form"
|
} from "@/components/ui/form"
|
||||||
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
|
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
|
||||||
|
import { useSiteContext } from "@app/hooks/useSiteContext"
|
||||||
|
|
||||||
const appearanceFormSchema = z.object({
|
const appearanceFormSchema = z.object({
|
||||||
theme: z.enum(["light", "dark"], {
|
theme: z.enum(["light", "dark"], {
|
||||||
|
@ -37,6 +38,10 @@ const defaultValues: Partial<AppearanceFormValues> = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AppearanceForm() {
|
export function AppearanceForm() {
|
||||||
|
const site = useSiteContext();
|
||||||
|
|
||||||
|
console.log(site);
|
||||||
|
|
||||||
const form = useForm<AppearanceFormValues>({
|
const form = useForm<AppearanceFormValues>({
|
||||||
resolver: zodResolver(appearanceFormSchema),
|
resolver: zodResolver(appearanceFormSchema),
|
||||||
defaultValues,
|
defaultValues,
|
||||||
|
|
7
src/hooks/useSiteContext.ts
Normal file
7
src/hooks/useSiteContext.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import { SiteContext } from "@app/contexts/siteContext";
|
||||||
|
import { useContext } from "react";
|
||||||
|
|
||||||
|
export function useSiteContext() {
|
||||||
|
const site = useContext(SiteContext);
|
||||||
|
return site;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue