summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/home/components/CategoryDynamic.jsx95
-rw-r--r--src/lib/home/hooks/useCategoryManagement.js34
-rw-r--r--src/pages/index.jsx9
3 files changed, 129 insertions, 9 deletions
diff --git a/src/lib/home/components/CategoryDynamic.jsx b/src/lib/home/components/CategoryDynamic.jsx
index 59a1858b..e3052d11 100644
--- a/src/lib/home/components/CategoryDynamic.jsx
+++ b/src/lib/home/components/CategoryDynamic.jsx
@@ -1,9 +1,90 @@
-const CategoryDynamic = ({}) =>{
- return(
- <div>
- DISINI CATEGORY DYNAMIC
- </div>
- )
+import React, { useEffect, useState } from 'react';
+import {fetchProductManagementSolr} from '../hooks/useCategoryManagement';
+import NextImage from 'next/image';
+import Link from "next/link"
+import router from 'next/router';
+import { createSlug } from '@/core/utils/slug'
+
+const CategoryDynamic = () => {
+ const [promoItems, setPromoItems] = useState([]);
+ useEffect(() => {
+ const loadPromo = async () => {
+
+ try {
+ const items = await fetchProductManagementSolr();
+ setPromoItems(items);
+
+ } catch (loadError) {
+ // console.error("Error loading promo items:", loadError)
+ }
+ }
+
+
+ loadPromo()
+
+ },[]);
+
+ const image = 'https://erp.indoteknik.com/api/image/product.template/image_256/544371?ratio=square'
+ const handleLink = (name, id) => {
+ return `/shop/category/${name}/${id}`;
};
-export default CategoryDynamic; \ No newline at end of file
+ console.log("promoItems",promoItems)
+
+ return (
+ <div>
+ <div className='font-semibold sm:text-h-lg mb-6 px-4 sm:px-0'>Kategori Pilihan</div>
+ {/* Render category data */}
+ {promoItems && promoItems.map((category) => (
+ <div key={category.id}>
+ <div className='bagian-judul flex flex-row justify-start items-center gap-3'>
+ <div className='font-semibold sm:text-h-lg mr-2'>{category.name}</div>
+ <p className='text-gray_r-10 text-sm'>999 rb+ Produk tersedia</p>
+ <Link href={createSlug('/shop/category/', category?.name, category?.id)} className="!text-red-500 font-semibold">Lihat Semua</Link>
+ </div>
+ <p>
+ Kategori level 1 : {category.name} - ID level 1 : {category.id}
+ <NextImage
+ src={category.image? category.image : image}
+ alt={category.name}
+ width={90}
+ height={30}
+ />
+ </p>
+ <div>
+ {category.category_id2.map((index)=> (
+ <div key={index.id}>
+ <p>
+ id LEVEL 2: {index.id_level_2} - Name LEVEL 2: {index.name}
+ <NextImage
+ src={index.image? index.image : image}
+ alt={index.name}
+ width={90}
+ height={30}
+ />
+ <div>
+ {index.child_frontend_id_i.map((x)=> (
+ <div key={x.id}>
+ <p>
+ id LEVEL 3: {x.id_level_3} - name LEVEL 3: {x.name}
+ <NextImage
+ src={x.image? x.image : image}
+ alt={x.name}
+ width={90}
+ height={30}
+ />
+ </p>
+ </div>
+ ))}
+ </div>
+ </p>
+ </div>
+ ))}
+ </div>
+ </div>
+ ))}
+ </div>
+ );
+}
+
+export default CategoryDynamic;
diff --git a/src/lib/home/hooks/useCategoryManagement.js b/src/lib/home/hooks/useCategoryManagement.js
new file mode 100644
index 00000000..7c01df6e
--- /dev/null
+++ b/src/lib/home/hooks/useCategoryManagement.js
@@ -0,0 +1,34 @@
+export const fetchProductManagementSolr = async () => {
+ try {
+ const queryParams = new URLSearchParams({q: 'type_value_s:bundling'})
+ const response = await fetch(`/solr/product_category_management/query?q=*:*&q.op=OR&indent=true`);
+ // console.log("response", response)
+ if (!response.ok) {
+ throw new Error(`HTTP error! status: ${response.status}`);
+ }
+ const data = await response.json();
+ // console.log("data",data)
+ const dataManagement = await map(data.response.docs);
+ // console.log("dataManagement",dataManagement)
+ return dataManagement;
+ } catch (error) {
+ console.error("Error fetching promotion data:", error);
+ return [];
+ }
+};
+
+const map = async (promotions) => {
+ const result = [];
+ for (const promotion of promotions) {
+ const data = {
+ id: promotion.id,
+ category_id: promotion.category_id_i,
+ name: promotion.name_s,
+ sequence: promotion.sequence_i,
+ image: promotion.image_s,
+ category_id2: JSON.parse(promotion.category_id2_s),
+ };
+ result.push(data);
+ }
+ return result;
+};
diff --git a/src/pages/index.jsx b/src/pages/index.jsx
index 149352c2..b5d004ca 100644
--- a/src/pages/index.jsx
+++ b/src/pages/index.jsx
@@ -12,7 +12,7 @@ import PreferredBrandSkeleton from '@/lib/home/components/Skeleton/PreferredBran
import PromotinProgram from '@/lib/promotinProgram/components/HomePage';
import PagePopupIformation from '~/modules/popup-information';
import CategoryPilihan from '../lib/home/components/CategoryPilihan';
-import CategoryDynamic from '../lib/home/components/CategoryDynamic';
+// import CategoryDynamic from '../lib/home/components/CategoryDynamic';
import odooApi from '@/core/api/odooApi';
import { getIdFromSlug } from '@/core/utils/slug'
@@ -51,6 +51,11 @@ const BannerSection = dynamic(() =>
const CategoryHomeId = dynamic(() =>
import('@/lib/home/components/CategoryHomeId')
);
+
+const CategoryDynamic = dynamic(() =>
+ import('@/lib/home/components/CategoryDynamic')
+);
+
const CustomerReviews = dynamic(() =>
import('@/lib/review/components/CustomerReviews')
);
@@ -122,7 +127,7 @@ export default function Home({categoryId}) {
<PromotinProgram />
<CategoryPilihan categories={dataCategories}/>
<CategoryDynamic/>
- {/* <CategoryHomeId /> */}
+ <CategoryHomeId />
<BannerSection />
<CustomerReviews />
</div>