// ui/contexts/SonContext.tsx import React, { createContext, useContext } from "react"; import { Son } from "@/lib/types"; import { useSons } from "@/hooks/useSons"; import { Dispatch, SetStateAction } from "react"; import { useWebhook } from "@/hooks/useWebhook"; import { Webhook } from "@/lib/types"; interface SonContextProps { sons: Son[]; setSons: Dispatch>; loading: boolean; error: Error | null; fetchSons: () => void; createSon: ( sonData: Omit ) => Promise; updateSon: (id: string, sonData: Partial) => Promise; deleteSon: (id: string) => Promise; webhook: Webhook | null; webhookLoading: boolean; webhookError: Error | null; fetchWebhook: () => Promise; } const SonContext = createContext(undefined); export const SonProvider: React.FC<{ children: React.ReactNode }> = ({ children, }) => { const { sons, setSons, loading, error, fetchSons, createSon, updateSon, deleteSon, } = useSons(); const { webhook, loading: webhookLoading, error: webhookError, fetchWebhook, } = useWebhook(); return ( {children} ); }; export const useSonContext = () => { const context = useContext(SonContext); if (!context) { throw new Error("useSonContext must be used within a SonProvider"); } return context; };