11import MainSlider from "@/component/mainSlider" ;
22import HomeCategory from "@/component/homeCategory" ;
33import ProductCarousel from "@/component/productCarousel" ;
4- import { HomePageAPI } from "@/const/endPoint" ;
4+ import { HomePageAPI , MegaMenuAPI } from "@/const/endPoint" ;
55import Subscribe from "@/component/subscribe" ;
66import InstagramPost from "@/component/instagramPost" ;
77import { HomeProps , Product } from "@/utils/type" ;
8- import { MegaMenuProvider } from "@/context/menuContext" ;
98import { HomeTransformer } from "@/utils/api/transformer/home" ;
109import { getData } from "@/utils/api/fetchData/apiCall" ;
1110import { useScrollRestoration } from "@/utils/hooks" ;
1211import { useQuery } from "@tanstack/react-query" ;
13- import { useRouter } from "next/router" ;
1412import { GetServerSidePropsContext } from "next" ;
1513import MetaTags from "@/component/metaTags" ;
14+ import { MegaMenuTransformer } from "@/utils/api/transformer/megaMenu" ;
1615
1716const fetchCHomeData = async ( ) => {
1817 const data = await getData ( HomePageAPI ) ;
1918 return HomeTransformer ( data ) . homeProductCarousel ;
2019} ;
2120
22- export default function Home ( {
23- homeProductCarousel,
24- menu,
25- } : HomeProps ) : JSX . Element {
21+ export default function Home ( { homeProductCarousel } : HomeProps ) : JSX . Element {
2622 useScrollRestoration ( ) ;
27- const router = useRouter ( ) ;
28- const locale = router . locale || "en" ;
23+
2924 const { data : carouselData } = useQuery < Product [ ] > ( {
3025 queryKey : [ "homePage" ] ,
3126 queryFn : ( ) => fetchCHomeData ( ) ,
@@ -36,25 +31,26 @@ export default function Home({
3631
3732 return (
3833 < >
39- < MegaMenuProvider initialMenu = { menu } language = { locale } >
40- < MetaTags />
41- < MainSlider />
42- < HomeCategory />
43- < ProductCarousel product = { carouselData } />
44- < Subscribe />
45- < InstagramPost />
46- </ MegaMenuProvider >
34+ < MetaTags />
35+ < MainSlider />
36+ < HomeCategory />
37+ < ProductCarousel product = { carouselData } />
38+ < Subscribe />
39+ < InstagramPost />
4740 </ >
4841 ) ;
4942}
5043
5144export async function getServerSideProps ( context : GetServerSidePropsContext ) {
5245 const referer = context . req . headers . referer || null ;
46+
5347 if ( ! referer ) {
5448 const data = await getData ( HomePageAPI ) ;
5549 const { homeProductCarousel } = HomeTransformer ( data ) ;
56-
57- return { props : { homeProductCarousel } } ;
50+ const megaMenuData = await getData ( MegaMenuAPI ) ;
51+ const menu = MegaMenuTransformer ( megaMenuData ) . menuItems ;
52+ return { props : { homeProductCarousel, menu } } ;
5853 }
59- return { props : { homeProductCarousel : null } } ;
54+
55+ return { props : { homeProductCarousel : null , menu : [ ] } } ;
6056}
0 commit comments