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 { 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 (
<> <>

View file

@ -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,

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;
}