From f7ad601638549f024201d3ee1fa920abe7c74f64 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 6 Sep 2024 14:59:17 +0700
Subject: <iman> update mapping solr data fetch

---
 src/lib/home/components/CategoryDynamic.jsx | 38 +++++++++++------------------
 1 file changed, 14 insertions(+), 24 deletions(-)

(limited to 'src/lib/home/components/CategoryDynamic.jsx')

diff --git a/src/lib/home/components/CategoryDynamic.jsx b/src/lib/home/components/CategoryDynamic.jsx
index 11a15d6d..ca104ada 100644
--- a/src/lib/home/components/CategoryDynamic.jsx
+++ b/src/lib/home/components/CategoryDynamic.jsx
@@ -1,6 +1,5 @@
 import React, { useEffect, useState, useCallback } from 'react';
-import useCategoryManagement from '../hooks/useCategoryManagement';
-import {fetchPopulerProductSolr} from '../api/categoryManagementApi'
+import {fetchCategoryManagementSolr} from '../api/categoryManagementApi'
 import NextImage from 'next/image';
 import Link from "next/link";
 import { createSlug } from '@/core/utils/slug';
@@ -14,28 +13,20 @@ import { Navigation, Pagination, Autoplay } from 'swiper';
 
 const CategoryDynamic = () => {
 
-  const [manufactures, setManufactures] = useState([])
+  const [categoryManagement, setCategoryManagement] = useState([])
+  const [isLoading, setIsLoading] = useState(false)
   const loadBrand = useCallback(async () => {
-    // setIsLoading(true)
-    //Get brand from odoo
-    /*const result = await odooApi(
-      'GET',
-      `/api/v1/manufacture?limit=0&offset=${manufactures.length}&name=${name}`
-    )*/
-
-    // Change get brands from solr
-    const items = await fetchPopulerProductSolr();
-
-    console.log("items",items)
+    setIsLoading(true)
+    const items = await fetchCategoryManagementSolr();
     
-    // setIsLoading(false)
-    // setManufactures((manufactures) => [...result.data])
+    setIsLoading(false)
+    setCategoryManagement(items)
   }, [])
 
   useEffect(() => {
     loadBrand()
   }, [loadBrand])
-  const { categoryManagement } = useCategoryManagement();
+  
   // const [categoryData, setCategoryData] = useState({});
   // const [subCategoryData, setSubCategoryData] = useState({});
   
@@ -76,18 +67,17 @@ const CategoryDynamic = () => {
  
   return (
     <div>
-        {categoryManagement && categoryManagement.data?.map((category) => {
+        {categoryManagement && categoryManagement?.map((category) => {
           // const countLevel1 = categoryData[category.categoryIdI] || 0;
-          
           return (
-            <Skeleton key={category.id} isLoaded={categoryManagement}>
+            <Skeleton key={category.id} isLoaded={!isLoading}>
               <div key={category.id}>
                 <div className='bagian-judul flex flex-row justify-start items-center gap-3 mb-4 mt-4'>
                   <div className='font-semibold sm:text-h-lg mr-2'>{category.name}</div>
                   {/* <Skeleton isLoaded={countLevel1 != 0}>
                     <p className={`text-gray_r-10 text-sm`}>{countLevel1} Produk tersedia</p>
                   </Skeleton> */}
-                  <Link href={createSlug('/shop/category/', category?.name, category?.categoryIdI)} className="!text-red-500 font-semibold">Lihat Semua</Link>
+                  <Link href={createSlug('/shop/category/', category?.name, category?.id)} className="!text-red-500 font-semibold">Lihat Semua</Link>
                 </div>
                 
                 {/* Swiper for SubCategories */}
@@ -115,13 +105,13 @@ const CategoryDynamic = () => {
                                     {countLevel2} Produk tersedia
                                   </p>
                                 </Skeleton> */}
-                                <Link href={createSlug('/shop/category/', subCategory?.name, subCategory?.idLevel2)} className="!text-red-500 font-semibold">Lihat Semua</Link>
+                                <Link href={createSlug('/shop/category/', subCategory?.name, subCategory?.id_level_2)} className="!text-red-500 font-semibold">Lihat Semua</Link>
                               </div>
                             </div>
                             <div className='grid grid-cols-2 gap-2 overflow-y-auto max-h-[240px] min-h-[240px] content-start'>
-                              {subCategory.childFrontendIdI.map((childCategory) => (
+                              {subCategory.child_frontend_id_i.map((childCategory) => (
                                 <div key={childCategory.id} className=''>
-                                  <Link href={createSlug('/shop/category/', childCategory?.name, childCategory?.idLevel3)} className="flex flex-row gap-2 border rounded group hover:border-red-500">
+                                  <Link href={createSlug('/shop/category/', childCategory?.name, childCategory?.id_level_3)} className="flex flex-row gap-2 border rounded group hover:border-red-500">
                                     <NextImage
                                       src={childCategory.image ? childCategory.image : "/images/noimage.jpeg"}
                                       alt={childCategory.name}
-- 
cgit v1.2.3

