Skip to content

Commit 30935cf

Browse files
fix product page and category page
1 parent 3aa06ad commit 30935cf

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/pages/category/[slug].tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CategoryAPI } from "@/const/endPoint";
1+
import { CategoryAPI, MegaMenuAPI } from "@/const/endPoint";
22
import { getData } from "@/utils/api/fetchData/apiCall";
33
import { GetServerSidePropsContext } from "next";
44
import React, { FC, useState } from "react";
@@ -14,6 +14,7 @@ import { CategoryTransformer } from "@/utils/api/transformer/category";
1414
import { useMegaMenu } from "@/context/menuContext";
1515
import { useQuery } from "@tanstack/react-query";
1616
import MetaTags from "@/component/metaTags";
17+
import { MegaMenuTransformer } from "@/utils/api/transformer/megaMenu";
1718

1819
const fetchCategoryData = async (
1920
categoryId: string,
@@ -96,9 +97,10 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
9697
page,
9798
});
9899
const data = CategoryTransformer(categoryData);
99-
100+
const megaMenuData = await getData(MegaMenuAPI);
101+
const menu = MegaMenuTransformer(megaMenuData).menuItems;
100102
return {
101-
props: { initialCategory: data },
103+
props: { initialCategory: data, menu },
102104
};
103105
}
104106

src/pages/product/[slug].tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ProductDetailAPI } from "@/const/endPoint";
1+
import { MegaMenuAPI, ProductDetailAPI } from "@/const/endPoint";
22
import { getData } from "@/utils/api/fetchData/apiCall";
33
import { GetServerSidePropsContext } from "next";
44
import React, { FC } from "react";
@@ -8,6 +8,7 @@ import { ProductTransformer } from "@/utils/api/transformer/product";
88
import ProductPlaceholder from "./placeholder";
99
import { useFetchProductData } from "@/utils/hooks/api/useFetchProductData";
1010
import MetaTags from "@/component/metaTags";
11+
import { MegaMenuTransformer } from "@/utils/api/transformer/megaMenu";
1112

1213
const ProductPage: FC<ProductPageProps> = ({ initialProduct, productId }) => {
1314
const { data: product, isLoading } = useFetchProductData({
@@ -34,7 +35,9 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
3435
const productData =
3536
productId && (await getData(ProductDetailAPI, { product_id: productId }));
3637
const data = ProductTransformer(productData);
37-
return { props: { initialProduct: data, productId } };
38+
const megaMenuData = await getData(MegaMenuAPI);
39+
const menu = MegaMenuTransformer(megaMenuData).menuItems;
40+
return { props: { initialProduct: data, productId, menu } };
3841
}
3942
return { props: { initialProduct: null, productId } };
4043
}

0 commit comments

Comments
 (0)