Files
AmirReza Jamali efbdb82535 feat: Add CMS context, hooks, and types for managing CMS data
- Implemented CmsContext and CmsProvider for global state management of CMS data.
- Created a custom hook `useGetCms` to fetch CMS data using React Query.
- Defined TypeScript interfaces for CMS response and its related data structures.
- Added error handling for data fetching in both the service and context.
2025-11-11 15:22:12 +03:30

22 lines
608 B
TypeScript

import api from "@/service/api";
import { CmsResponse } from "@/types/TCms";
import { useQuery } from "@tanstack/react-query";
import { useMemo } from "react";
export const cmsService = {
getCms: async (id: string): Promise<CmsResponse> => {
try {
return (await api.get(`cms/${id}`)).data;
} catch (error) {
console.log("Error fetching CMS data:", error);
throw error;
}
},
};
export const useGetCms = (pageId: string) => {
const queryKey = useMemo(() => ["cms", pageId], [pageId]);
return useQuery({
queryKey,
queryFn: () => cmsService.getCms(pageId),
});
};