Add site context?

This commit is contained in:
Owen Schwartz 2024-10-13 22:58:47 -04:00
parent b53d093065
commit ab41695988
No known key found for this signature in database
GPG key ID: 8271FDFFD9E0CCBD
3 changed files with 26 additions and 12 deletions

View file

@ -4,7 +4,10 @@ import Image from "next/image"
import { Separator } from "@/components/ui/separator"
import { SidebarNav } from "@/components/sidebar-nav"
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 = {
title: "Forms",
@ -40,20 +43,19 @@ interface SettingsLayoutProps {
}
export default async function SettingsLayout({ children, params }: SettingsLayoutProps) {
const res = await api
.get(`/site/${params.siteId}`, {})
.catch((e) => {
console.error("Failed to fetch site", e);
const sessionId = cookies().get("session")?.value ?? null;
const res = await internal
.get<AxiosResponse<GetSiteResponse>>(`/site/${params.siteId}`, {
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: any = {};
const site = res.data.data;
return (
<>

View file

@ -18,6 +18,7 @@ import {
FormMessage,
} from "@/components/ui/form"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
import { useSiteContext } from "@app/hooks/useSiteContext"
const appearanceFormSchema = z.object({
theme: z.enum(["light", "dark"], {
@ -37,6 +38,10 @@ const defaultValues: Partial<AppearanceFormValues> = {
}
export function AppearanceForm() {
const site = useSiteContext();
console.log(site);
const form = useForm<AppearanceFormValues>({
resolver: zodResolver(appearanceFormSchema),
defaultValues,

View file

@ -0,0 +1,7 @@
import { SiteContext } from "@app/contexts/siteContext";
import { useContext } from "react";
export function useSiteContext() {
const site = useContext(SiteContext);
return site;
}