index.js
7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import { useRouter } from "next/router";
import Breadcrumb from "@/components/Common/Breadcrumb";
import HeadTitle from "@/components/Common/HeadTitle";
import InnerDetailsSubCategory from "@/components/Collection/InnerDetailsSubCategory";
import InnerBannerproduct from "@/components/Collection/InnerBannerproduct";
import AboutInfo from "@/components/Collection/AboutInfo";
import Video from "@/components/Collection/Video";
import Gallery from "@/components/Collection/Gallery";
import Catalogues from "@/container/Home/Catalogues";
import { Contact } from "@/container/Home/Contact";
import CompanyOverview from "@/components/Collection/CompanyOverview";
import TechnicalDetails from "@/components/Collection/TechnicalDetails";
import Explore from "@/components/Collection/Explore";
import { getCollectionDetailCategoryData } from "@/services/collectionDetailCategoryApi";
import { getCollectionSubCategoryData } from "@/services/collectionSubCategoryApi";
import { getCataloguesBySlug } from "@/services/cataloguesApi";
import { fetchFromStrapi } from "@/services/api";
import { Tab, Tabs } from "react-bootstrap";
const SubCategoryOrProductPage = ({
type,
products,
productData,
activeSubCategory,
cataloguesData,
}) => {
const router = useRouter();
const { category, subCategory } = router.query;
if (!router.isReady) return null;
/* ======================================================
🟢 IF PRODUCT (2 LEVEL PRODUCT PAGE)
====================================================== */
if (type === "product") {
const subCategoryData = productData.productData;
const breadcrumbData = [
{ href: "/", label: "Collections" },
{
href: `/collections/${category}`,
label: category.replace(/-/g, " "),
},
{
href: router.asPath,
label: productData.title,
},
];
const productTabs = productData?.productTabs;
return (
<>
<Breadcrumb breadcrumbData={breadcrumbData} />
<InnerBannerproduct productData={productData} />
{productData?.isDoorAndPartitionsLayouts == true ? (
<section className="details-tab-section">
<div className="custom_containers">
<div className="details-tab">
<div className="head">Products:</div>
<Tabs defaultActiveKey={productTabs?.[0]?.title} className="tab-01">
{productTabs?.map((tab) => (
<Tab
key={tab.id}
eventKey={tab.title}
title={tab.title}
>
<AboutInfo productData={tab?.aboutInfo} />
<CompanyOverview
companyOverviewData={tab?.companyOverview?.items}
/>
<Video productData={tab?.videoSection} />
{tab?.technicalDetails?.length > 0 && (
<TechnicalDetails
productData={tab?.technicalDetails}
/>
)}
{tab?.gallery?.length > 0 && (
<Gallery productData={tab?.gallery} />
)}
</Tab>
))}
</Tabs>
</div>
</div>
</section>
) : (<>
<AboutInfo productData={productData?.aboutInfo} />
<CompanyOverview companyOverviewData={productData?.companyOverview} />
<Video productData={productData?.video} />
<Video productData={productData?.video} />
{productData?.technicalDetails?.length > 0 && (
<TechnicalDetails productData={productData?.technicalDetails} />
)}
<Gallery productData={productData?.gallery} />
{/* <Explore productData={productData?.explore} /> */}
</>)}
{productData?.isDoorAndPartitionsLayouts && (
<Explore productData={productData?.exploreProducts} />
)}
{!productData?.isDoorAndPartitionsLayouts && (
<Catalogues cataloguesData={cataloguesData} />
)}
{/* {productData?.isDoorAndPartitionsLayouts === false && (
<AboutInfo productData={productData?.aboutInfo} />
)} */}
{/* {productData?.isDoorAndPartitionsLayouts == false && (
<CompanyOverview companyOverviewData={productData?.companyOverview} />
)}
{productData?.isDoorAndPartitionsLayouts == false && (
<Video productData={productData?.video} />
)}
{productData?.isDoorAndPartitionsLayouts == false && (
<TechnicalDetails productData={productData?.technicalDetails} />
)}
{productData?.isDoorAndPartitionsLayouts == false && (
<Gallery productData={productData?.gallery} />
)} */}
<Contact />
</>
);
}
/* ======================================================
🔵 IF SUBCATEGORY (NORMAL 2 LEVEL SUBCATEGORY PAGE)
====================================================== */
// if (!products || products.length === 0) {
// return <h1>Sub Category not found</h1>;
// }
const subCategoryData = products[0]?.collection_sub_category;
const breadcrumbData = [
// { href: "/", label: "Home" },
{ href: "/", label: "Collections" },
{
href: `/collections/${category}`,
label: category.replace(/-/g, " "),
},
{
href: router.asPath,
label: subCategoryData?.title,
},
];
return (
<>
<Breadcrumb breadcrumbData={breadcrumbData} />
<HeadTitle categoryData={activeSubCategory} />
<InnerDetailsSubCategory products={products} />
</>
);
};
export default SubCategoryOrProductPage;
/* ======================================================
✅ SERVER SIDE LOGIC
====================================================== */
export async function getServerSideProps({ params }) {
try {
const { subCategory } = params;
/* 1️⃣ Check if this slug is a PRODUCT */
const productCheck = await getCollectionDetailCategoryData(subCategory);
if (productCheck && productCheck.length > 0) {
const cataloguesData = await getCataloguesBySlug();
return {
props: {
type: "product",
productData: productCheck[0],
cataloguesData,
},
};
}
/* 2️⃣ Otherwise treat as SUBCATEGORY */
const query = {
filters: {
collection_sub_category: {
slug: {
$eq: subCategory,
},
},
},
populate: {
image: true,
collection_sub_category: {
populate: true,
},
},
};
const response = await fetchFromStrapi(
"/api/collection-detail-categories",
query,
);
const allProducts = response?.data || [];
const products = allProducts;
// const allProducts = await getCollectionDetailCategoryData();
const categoriesSub = await getCollectionSubCategoryData();
const activeSubCategory =
categoriesSub.find((item) => item.slug === subCategory) || null;
return {
props: {
type: "subcategory",
products,
activeSubCategory,
},
};
} catch (error) {
console.error(error);
return {
notFound: true,
};
}
}