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.
This commit is contained in:
AmirReza Jamali
2025-11-11 15:22:12 +03:30
parent 910e8aed89
commit efbdb82535
12 changed files with 198 additions and 107 deletions
+21
View File
@@ -0,0 +1,21 @@
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),
});
};