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
+19 -3
View File
@@ -1,4 +1,6 @@
import ApexChart from "@/app/_components/ApexChart";
import { cmsService } from "@/hooks/useCmsQueries";
import { CmsResponse } from "@/types/TCms";
import { Metadata } from "next";
import Image from "next/image";
@@ -21,7 +23,20 @@ export const metadata: Metadata = {
},
};
export default function Home() {
interface IProps {
params: { id: string };
}
export default async function Home({ params }: IProps) {
const { id } = params;
let cmsData: CmsResponse | null = null;
try {
cmsData = await cmsService.getCms(id);
} catch (error) {
console.error("Error fetching CMS data:", error);
}
const centerFrames = [
{
src: "/magnifier.svg",
@@ -45,6 +60,7 @@ export default function Home() {
"We operate on a partnership model. We only succeed when you win. This aligns our goals and makes us a true partner in your growth.",
},
];
return (
<>
<section className="block lg:flex justify-around items-center">
@@ -52,13 +68,13 @@ export default function Home() {
<div className="flex flex-col gap-8">
<h2>
<span>$</span>
<span>12,345,678</span>
<span>{cmsData?.data.chart.missedAmount ?? 1672}</span>
</h2>
<h2 className="capitalize text-2xl font-bold lg:text-3xl">
total tender amount you missed today
</h2>
</div>
<ApexChart />
<ApexChart cmsData={cmsData?.data} />
</div>
<div className="m-auto w-xs lg:m-0 lg:w-auto -z-20 relative flex justify-center h-[650px] lg:h-[750px]">
<Image