"use client"; import api from "@app/api"; import SiteContext from "@app/contexts/siteContext"; import { toast } from "@app/hooks/use-toast"; import { GetSiteResponse } from "@server/routers/site/getSite"; import { AxiosResponse } from "axios"; import { useState } from "react"; interface SiteProviderProps { children: React.ReactNode; site: GetSiteResponse | null; } export function SiteProvider({ children, site: serverSite }: SiteProviderProps) { const [site, setSite] = useState(serverSite); const updateSite = async (updatedSite: Partial) => { try { if (!site) { throw new Error("No site to update"); } const res = await api.post>( `site/${site.siteId}`, updatedSite, ); setSite(res.data.data); toast({ title: "Site updated!", }); } catch (error) { console.error(error); toast({ variant: "destructive", title: "Error updating site...", }) } }; return {children}; } export default SiteProvider;