From 59cba752134fa41063956569a3f4e7ed2a6d2537 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 8 Jul 2024 08:48:29 +0700
Subject: <iman> add dynamic category

---
 src/lib/home/components/CategoryDynamic.jsx | 9 +++++++++
 1 file changed, 9 insertions(+)
 create mode 100644 src/lib/home/components/CategoryDynamic.jsx

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

diff --git a/src/lib/home/components/CategoryDynamic.jsx b/src/lib/home/components/CategoryDynamic.jsx
new file mode 100644
index 00000000..59a1858b
--- /dev/null
+++ b/src/lib/home/components/CategoryDynamic.jsx
@@ -0,0 +1,9 @@
+const CategoryDynamic = ({}) =>{
+    return(
+        <div>
+            DISINI CATEGORY DYNAMIC
+        </div>
+    )
+};
+
+export default CategoryDynamic;
\ No newline at end of file
-- 
cgit v1.2.3


From 0840f5ccc7493dfa091508db84bad8a21e073268 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Thu, 18 Jul 2024 17:24:36 +0700
Subject: <iman> update category-management

---
 src/lib/home/components/CategoryDynamic.jsx | 95 ++++++++++++++++++++++++++---
 1 file changed, 88 insertions(+), 7 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 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;
-- 
cgit v1.2.3


From 8564ea1361d40560679df6823b28dfc7e02ab197 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 19 Jul 2024 16:45:46 +0700
Subject: <iman> update view category dynamic

---
 src/lib/home/components/CategoryDynamic.jsx | 81 +++++++++++++----------------
 1 file changed, 37 insertions(+), 44 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 e3052d11..4180438a 100644
--- a/src/lib/home/components/CategoryDynamic.jsx
+++ b/src/lib/home/components/CategoryDynamic.jsx
@@ -18,66 +18,59 @@ const CategoryDynamic =    () => {
         // 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}`;
-};
 
   console.log("promoItems",promoItems)
 
   return (
     <div>
-      <div className='font-semibold sm:text-h-lg mb-6 px-4 sm:px-0'>Kategori Pilihan</div>
+      {/* <div className='font-semibold sm:text-h-lg mb-2 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='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>
               <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>
+            <Link href={createSlug('/shop/category/', category?.name, category?.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>
+          <div className='grid grid-cols-3 gap-2'>
             {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 key={index.id} className='border justify-start items-start'>
+                <div className='p-3'>
+                    <div className='flex flex-row border mb-2 justify-start items-center'>
+                      <NextImage
+                        src={index.image? index.image : "https://erp.indoteknik.com/api/image/product.template/image_256/120726?ratio=square"}
+                        alt={index.name}
+                        width={90}
+                        height={30}
+                        className='object-fit'
+                      />
+                      <div className='bagian-judul flex flex-col justify-center items-start gap-2 ml-2'>
+                          <div className='font-semibold text-lg mr-2'>{index.name}</div>
+                          <p className='text-gray_r-10 text-sm'>999 rb+ Produk</p>
+                          <Link href={createSlug('/shop/category/', index?.name, index?.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]' >
+                        {index.child_frontend_id_i.map((x)=> (
+                          <div key={x.id}>
+                                <Link href={createSlug('/shop/category/', x?.name, x?.id_level_3)} className="flex flex-row gap-2 border group hover:border-red-500">
+                                    <NextImage
+                                      src={x.image? x.image : "https://erp.indoteknik.com/api/image/product.template/image_256/127221?ratio=square"}
+                                      alt={x.name}
+                                      width={40}
+                                      height={40}
+                                    />
+                                    <div className='bagian-judul flex flex-col justify-center items-center gap-2 break-words line-clamp-2 group-hover:text-red-500'>
+                                        <div className='font-semibold line-clamp-2 group-hover:text-red-500 text-sm mr-2'>{x.name}</div>
+                                    </div>
+                                </Link>
+                            </div>
+                          ))}
                     </div>
-                  </p>
+                </div>
               </div>
             ))}
           </div>
-- 
cgit v1.2.3


From d6b459b3ea396775fae25b44d34c8dc724379224 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Sat, 20 Jul 2024 11:45:41 +0700
Subject: <iman> update mobile view

---
 src/lib/home/components/CategoryDynamic.jsx | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 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 4180438a..244543be 100644
--- a/src/lib/home/components/CategoryDynamic.jsx
+++ b/src/lib/home/components/CategoryDynamic.jsx
@@ -26,22 +26,20 @@ const CategoryDynamic =    () => {
 
   return (
     <div>
-      {/* <div className='font-semibold sm:text-h-lg mb-2 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 mb-4 mt-4'>
               <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?.category_id)} className="!text-red-500 font-semibold">Lihat Semua</Link>
+              <Link href={createSlug('/shop/category/', category?.name, category?.category_id)} className="!text-red-500 font-semibold">Lihat Semua</Link>
           </div>
           <div className='grid grid-cols-3 gap-2'>
             {category.category_id2.map((index)=> (
-              <div key={index.id} className='border justify-start items-start'>
+              <div key={index.id} className='border rounded justify-start items-start'>
                 <div className='p-3'>
-                    <div className='flex flex-row border mb-2 justify-start items-center'>
+                    <div className='flex flex-row border rounded mb-2 justify-start items-center'>
                       <NextImage
-                        src={index.image? index.image : "https://erp.indoteknik.com/api/image/product.template/image_256/120726?ratio=square"}
+                        src={index.image? index.image : "/images/noimage.jpeg"}
                         alt={index.name}
                         width={90}
                         height={30}
@@ -56,9 +54,9 @@ const CategoryDynamic =    () => {
                     <div className='grid grid-cols-2 gap-2 overflow-y-auto max-h-[240px]' >
                         {index.child_frontend_id_i.map((x)=> (
                           <div key={x.id}>
-                                <Link href={createSlug('/shop/category/', x?.name, x?.id_level_3)} className="flex flex-row gap-2 border group hover:border-red-500">
+                                <Link href={createSlug('/shop/category/', x?.name, x?.id_level_3)} className="flex flex-row gap-2 border rounded group hover:border-red-500">
                                     <NextImage
-                                      src={x.image? x.image : "https://erp.indoteknik.com/api/image/product.template/image_256/127221?ratio=square"}
+                                      src={x.image? x.image : "/images/noimage.jpeg"}
                                       alt={x.name}
                                       width={40}
                                       height={40}
-- 
cgit v1.2.3


From a78251dc5cdfdd5438aad3ce7b7e342fceb7275e Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 22 Jul 2024 16:57:47 +0700
Subject: <iman> update category management

---
 src/lib/home/components/CategoryDynamic.jsx | 4 ----
 1 file changed, 4 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 244543be..2edd5485 100644
--- a/src/lib/home/components/CategoryDynamic.jsx
+++ b/src/lib/home/components/CategoryDynamic.jsx
@@ -19,11 +19,7 @@ const CategoryDynamic =    () => {
       }
     }
       loadPromo()
-
   },[]);
-
-  console.log("promoItems",promoItems)
-
   return (
     <div>
       {promoItems && promoItems.map((category) => (
-- 
cgit v1.2.3


From bf5c3b1d48da54e0e44689412ad9de9c10cf9edb Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 23 Jul 2024 09:28:21 +0700
Subject: <iman> update category management

---
 src/lib/home/components/CategoryDynamic.jsx | 32 +++++++++--------------------
 1 file changed, 10 insertions(+), 22 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 2edd5485..cac8a138 100644
--- a/src/lib/home/components/CategoryDynamic.jsx
+++ b/src/lib/home/components/CategoryDynamic.jsx
@@ -1,36 +1,24 @@
 import React, { useEffect, useState } from 'react';
-import {fetchProductManagementSolr} from '../hooks/useCategoryManagement';
+import useCategoryManagement  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 CategoryDynamic =  () => {
+  const { categoryManagement } = useCategoryManagement()
+  
   return (
     <div>
-      {promoItems && promoItems.map((category) => (
+      {categoryManagement && categoryManagement.data?.map((category) => (
         <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>
               <p className='text-gray_r-10 text-sm'>999 rb+ Produk tersedia</p>
-              <Link href={createSlug('/shop/category/', category?.name, category?.category_id)} className="!text-red-500 font-semibold">Lihat Semua</Link>
+              <Link href={createSlug('/shop/category/', category?.name, category?.categoryIdI)} className="!text-red-500 font-semibold">Lihat Semua</Link>
           </div>
           <div className='grid grid-cols-3 gap-2'>
-            {category.category_id2.map((index)=> (
+            {category.categories.map((index)=> (
               <div key={index.id} className='border rounded justify-start items-start'>
                 <div className='p-3'>
                     <div className='flex flex-row border rounded mb-2 justify-start items-center'>
@@ -44,13 +32,13 @@ const CategoryDynamic =    () => {
                       <div className='bagian-judul flex flex-col justify-center items-start gap-2 ml-2'>
                           <div className='font-semibold text-lg mr-2'>{index.name}</div>
                           <p className='text-gray_r-10 text-sm'>999 rb+ Produk</p>
-                          <Link href={createSlug('/shop/category/', index?.name, index?.id_level_2)} className="!text-red-500 font-semibold">Lihat Semua</Link>
+                          <Link href={createSlug('/shop/category/', index?.name, index?.idLevel2)} 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]' >
-                        {index.child_frontend_id_i.map((x)=> (
+                        {index.childFrontendIdI.map((x)=> (
                           <div key={x.id}>
-                                <Link href={createSlug('/shop/category/', x?.name, x?.id_level_3)} className="flex flex-row gap-2 border rounded group hover:border-red-500">
+                                <Link href={createSlug('/shop/category/', x?.name, x?.idLevel3)} className="flex flex-row gap-2 border rounded group hover:border-red-500">
                                     <NextImage
                                       src={x.image? x.image : "/images/noimage.jpeg"}
                                       alt={x.name}
-- 
cgit v1.2.3


From b1341b76e94da9e64549768646bb54d2836976d0 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 23 Jul 2024 14:29:08 +0700
Subject: <iman> update categories management

---
 src/lib/home/components/CategoryDynamic.jsx | 119 ++++++++++++++++------------
 1 file changed, 69 insertions(+), 50 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 cac8a138..fa1df286 100644
--- a/src/lib/home/components/CategoryDynamic.jsx
+++ b/src/lib/home/components/CategoryDynamic.jsx
@@ -1,65 +1,84 @@
 import React, { useEffect, useState } from 'react';
-import useCategoryManagement  from '../hooks/useCategoryManagement';
+import useCategoryManagement from '../hooks/useCategoryManagement';
 import NextImage from 'next/image';
-import Link from "next/link"
+import Link from "next/link";
 import router from 'next/router';
-import { createSlug } from '@/core/utils/slug'
+import { createSlug } from '@/core/utils/slug';
+
+const CategoryDynamic = () => {
+  const { categoryManagement } = useCategoryManagement();
+
+  const calculateLevel3Products = (category) => {
+    return category.childFrontendIdI.reduce((total, child) => total + (child.numFound || 0), 0);
+  };
+
+  const calculateLevel2Products = (category) => {
+    return category.categories.reduce((total, subCategory) => {
+      const level3Products = calculateLevel3Products(subCategory);
+      return total + (subCategory.numFound || 0) + level3Products;
+    }, 0);
+  };
 
-const CategoryDynamic =  () => {
-  const { categoryManagement } = useCategoryManagement()
-  
   return (
     <div>
-      {categoryManagement && categoryManagement.data?.map((category) => (
-        <div key={category.id}>
-          <div className='bagian-judul flex flex-row justify-start items-center gap-3 mb-4 mt-4'>
+      {categoryManagement && categoryManagement.data?.map((category) => {
+        const countLevel2 = calculateLevel2Products(category);
+
+        return (
+          <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>
-              <p className='text-gray_r-10 text-sm'>999 rb+ Produk tersedia</p>
+              <p className='text-gray_r-10 text-sm'>{countLevel2} Produk tersedia</p>
               <Link href={createSlug('/shop/category/', category?.name, category?.categoryIdI)} className="!text-red-500 font-semibold">Lihat Semua</Link>
-          </div>
-          <div className='grid grid-cols-3 gap-2'>
-            {category.categories.map((index)=> (
-              <div key={index.id} className='border rounded justify-start items-start'>
-                <div className='p-3'>
-                    <div className='flex flex-row border rounded mb-2 justify-start items-center'>
-                      <NextImage
-                        src={index.image? index.image : "/images/noimage.jpeg"}
-                        alt={index.name}
-                        width={90}
-                        height={30}
-                        className='object-fit'
-                      />
-                      <div className='bagian-judul flex flex-col justify-center items-start gap-2 ml-2'>
-                          <div className='font-semibold text-lg mr-2'>{index.name}</div>
-                          <p className='text-gray_r-10 text-sm'>999 rb+ Produk</p>
-                          <Link href={createSlug('/shop/category/', index?.name, index?.idLevel2)} className="!text-red-500 font-semibold">Lihat Semua</Link>
+            </div>
+            <div className='grid grid-cols-3 gap-2'>
+              {category.categories.map((subCategory) => {
+                const countLevel3 = calculateLevel3Products(subCategory);
+
+                return (
+                  <div key={subCategory.id} className='border rounded justify-start items-start'>
+                    <div className='p-3'>
+                      <div className='flex flex-row border rounded mb-2 justify-start items-center'>
+                        <NextImage
+                          src={subCategory.image ? subCategory.image : "/images/noimage.jpeg"}
+                          alt={subCategory.name}
+                          width={90}
+                          height={30}
+                          className='object-fit'
+                        />
+                        <div className='bagian-judul flex flex-col justify-center items-start gap-2 ml-2'>
+                          <div className='font-semibold text-lg mr-2'>{subCategory.name}</div>
+                          <p className='text-gray_r-10 text-sm'>{(subCategory.numFound || 0) + countLevel3} Produk</p>
+                          <Link href={createSlug('/shop/category/', subCategory?.name, subCategory?.idLevel2)} 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]'>
+                        {subCategory.childFrontendIdI.map((childCategory) => (
+                          <div key={childCategory.id}>
+                            <Link href={createSlug('/shop/category/', childCategory?.name, childCategory?.idLevel3)} 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}
+                                width={40}
+                                height={40}
+                              />
+                              <div className='bagian-judul flex flex-col justify-center items-center gap-2 break-words line-clamp-2 group-hover:text-red-500'>
+                                <div className='font-semibold line-clamp-2 group-hover:text-red-500 text-sm mr-2'>{childCategory.name}</div>
+                              </div>
+                            </Link>
+                          </div>
+                        ))}
                       </div>
                     </div>
-                    <div className='grid grid-cols-2 gap-2 overflow-y-auto max-h-[240px]' >
-                        {index.childFrontendIdI.map((x)=> (
-                          <div key={x.id}>
-                                <Link href={createSlug('/shop/category/', x?.name, x?.idLevel3)} className="flex flex-row gap-2 border rounded group hover:border-red-500">
-                                    <NextImage
-                                      src={x.image? x.image : "/images/noimage.jpeg"}
-                                      alt={x.name}
-                                      width={40}
-                                      height={40}
-                                    />
-                                    <div className='bagian-judul flex flex-col justify-center items-center gap-2 break-words line-clamp-2 group-hover:text-red-500'>
-                                        <div className='font-semibold line-clamp-2 group-hover:text-red-500 text-sm mr-2'>{x.name}</div>
-                                    </div>
-                                </Link>
-                            </div>
-                          ))}
-                    </div>
-                </div>
-              </div>
-            ))}
+                  </div>
+                );
+              })}
+            </div>
           </div>
-        </div>
-      ))}
+        );
+      })}
     </div>
   );
-}
+};
 
 export default CategoryDynamic;
-- 
cgit v1.2.3


From 2e71abba4ca5b83cc1fec229d4d85961c4b56d71 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Thu, 25 Jul 2024 08:27:05 +0700
Subject: <iman> update category management

---
 src/lib/home/components/CategoryDynamic.jsx | 50 ++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 15 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 fa1df286..bbba2ceb 100644
--- a/src/lib/home/components/CategoryDynamic.jsx
+++ b/src/lib/home/components/CategoryDynamic.jsx
@@ -2,38 +2,58 @@ import React, { useEffect, useState } from 'react';
 import useCategoryManagement from '../hooks/useCategoryManagement';
 import NextImage from 'next/image';
 import Link from "next/link";
-import router from 'next/router';
 import { createSlug } from '@/core/utils/slug';
+import odooApi from '@/core/api/odooApi';
 
 const CategoryDynamic = () => {
   const { categoryManagement } = useCategoryManagement();
+  const [categoryData, setCategoryData] = useState({});
+  const [subCategoryData, setSubCategoryData] = useState({});
+  
+  useEffect(() => {
+    const fetchCategoryData = async () => {
+      if (categoryManagement && categoryManagement.data) {
+        const updatedCategoryData = {};
+        const updatedSubCategoryData = {};
+        
+        for (const category of categoryManagement.data) {
+          // Calculate level 1 products
+          const countLevel1 = await odooApi('GET', `/api/v1/category/numFound?parent_id=${category.categoryIdI}`);
+          // console.log("countLevel1.child",countLevel1)
+          
+          updatedCategoryData[category.categoryIdI] = countLevel1.numFound;
+          
+          
+          // Calculate level 2 products for each sub-category
+          for (const subCategory of countLevel1.children) {
+            updatedSubCategoryData[subCategory.id] = subCategory.numFound;
+          }
+        }
 
-  const calculateLevel3Products = (category) => {
-    return category.childFrontendIdI.reduce((total, child) => total + (child.numFound || 0), 0);
-  };
+        setCategoryData(updatedCategoryData);
+        setSubCategoryData(updatedSubCategoryData);
+      }
+    };
 
-  const calculateLevel2Products = (category) => {
-    return category.categories.reduce((total, subCategory) => {
-      const level3Products = calculateLevel3Products(subCategory);
-      return total + (subCategory.numFound || 0) + level3Products;
-    }, 0);
-  };
+    fetchCategoryData();
+  }, [categoryManagement, categoryData]);
+ 
 
   return (
     <div>
       {categoryManagement && categoryManagement.data?.map((category) => {
-        const countLevel2 = calculateLevel2Products(category);
-
+        const countLevel1 = categoryData[category.categoryIdI] || 0;
+        
         return (
           <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>
-              <p className='text-gray_r-10 text-sm'>{countLevel2} Produk tersedia</p>
+              <p className='text-gray_r-10 text-sm'>{countLevel1} Produk tersedia</p>
               <Link href={createSlug('/shop/category/', category?.name, category?.categoryIdI)} className="!text-red-500 font-semibold">Lihat Semua</Link>
             </div>
             <div className='grid grid-cols-3 gap-2'>
               {category.categories.map((subCategory) => {
-                const countLevel3 = calculateLevel3Products(subCategory);
+                const countLevel2 = subCategoryData[subCategory.idLevel2] || 0;
 
                 return (
                   <div key={subCategory.id} className='border rounded justify-start items-start'>
@@ -48,7 +68,7 @@ const CategoryDynamic = () => {
                         />
                         <div className='bagian-judul flex flex-col justify-center items-start gap-2 ml-2'>
                           <div className='font-semibold text-lg mr-2'>{subCategory.name}</div>
-                          <p className='text-gray_r-10 text-sm'>{(subCategory.numFound || 0) + countLevel3} Produk</p>
+                          <p className='text-gray_r-10 text-sm'>{countLevel2} Produk tersedia</p>
                           <Link href={createSlug('/shop/category/', subCategory?.name, subCategory?.idLevel2)} className="!text-red-500 font-semibold">Lihat Semua</Link>
                         </div>
                       </div>
-- 
cgit v1.2.3


From e5a01976cb665b824b2ad6426a2c52a5bd0964e6 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Sat, 27 Jul 2024 08:27:54 +0700
Subject: <iman> add feature category lob

---
 src/lib/home/components/CategoryDynamic.jsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(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 bbba2ceb..6ab03ec3 100644
--- a/src/lib/home/components/CategoryDynamic.jsx
+++ b/src/lib/home/components/CategoryDynamic.jsx
@@ -21,7 +21,7 @@ const CategoryDynamic = () => {
           const countLevel1 = await odooApi('GET', `/api/v1/category/numFound?parent_id=${category.categoryIdI}`);
           // console.log("countLevel1.child",countLevel1)
           
-          updatedCategoryData[category.categoryIdI] = countLevel1.numFound;
+          updatedCategoryData[category.categoryIdI] = countLevel1?.numFound;
           
           
           // Calculate level 2 products for each sub-category
-- 
cgit v1.2.3


From 067b536d7ea507575bd5bc3c12815927bd40d103 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 30 Jul 2024 16:06:13 +0700
Subject: <iman> add skeleton

---
 src/lib/home/components/CategoryDynamic.jsx | 114 +++++++++++++++-------------
 1 file changed, 63 insertions(+), 51 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 6ab03ec3..dda7cdc4 100644
--- a/src/lib/home/components/CategoryDynamic.jsx
+++ b/src/lib/home/components/CategoryDynamic.jsx
@@ -4,6 +4,7 @@ import NextImage from 'next/image';
 import Link from "next/link";
 import { createSlug } from '@/core/utils/slug';
 import odooApi from '@/core/api/odooApi';
+import { Skeleton} from '@chakra-ui/react'
 
 const CategoryDynamic = () => {
   const { categoryManagement } = useCategoryManagement();
@@ -41,62 +42,73 @@ const CategoryDynamic = () => {
 
   return (
     <div>
-      {categoryManagement && categoryManagement.data?.map((category) => {
-        const countLevel1 = categoryData[category.categoryIdI] || 0;
-        
-        return (
-          <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>
-              <p className='text-gray_r-10 text-sm'>{countLevel1} Produk tersedia</p>
-              <Link href={createSlug('/shop/category/', category?.name, category?.categoryIdI)} className="!text-red-500 font-semibold">Lihat Semua</Link>
-            </div>
-            <div className='grid grid-cols-3 gap-2'>
-              {category.categories.map((subCategory) => {
-                const countLevel2 = subCategoryData[subCategory.idLevel2] || 0;
+        {categoryManagement && categoryManagement.data?.map((category) => {
+          const countLevel1 = categoryData[category.categoryIdI] || 0;
+          
+          return (
+            <Skeleton isLoaded={categoryManagement}>
+            <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>
+                <p className={`text-gray_r-10 text-sm ${countLevel1 === 0 ? 'animate-pulse ' : ''}`}>
+                  {countLevel1 === 0 ? 'Menghitung jumlah produk...' : `${countLevel1} Produk tersedia`}
+              </p>
+                <Link href={createSlug('/shop/category/', category?.name, category?.categoryIdI)} className="!text-red-500 font-semibold">Lihat Semua</Link>
+              </div>
+              <div className='grid grid-cols-3 gap-2'>
+                {category.categories.map((subCategory) => {
+                  const countLevel2 = subCategoryData[subCategory.idLevel2] || 0;
 
-                return (
-                  <div key={subCategory.id} className='border rounded justify-start items-start'>
-                    <div className='p-3'>
-                      <div className='flex flex-row border rounded mb-2 justify-start items-center'>
-                        <NextImage
-                          src={subCategory.image ? subCategory.image : "/images/noimage.jpeg"}
-                          alt={subCategory.name}
-                          width={90}
-                          height={30}
-                          className='object-fit'
-                        />
-                        <div className='bagian-judul flex flex-col justify-center items-start gap-2 ml-2'>
-                          <div className='font-semibold text-lg mr-2'>{subCategory.name}</div>
-                          <p className='text-gray_r-10 text-sm'>{countLevel2} Produk tersedia</p>
-                          <Link href={createSlug('/shop/category/', subCategory?.name, subCategory?.idLevel2)} 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]'>
-                        {subCategory.childFrontendIdI.map((childCategory) => (
-                          <div key={childCategory.id}>
-                            <Link href={createSlug('/shop/category/', childCategory?.name, childCategory?.idLevel3)} 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}
-                                width={40}
-                                height={40}
-                              />
-                              <div className='bagian-judul flex flex-col justify-center items-center gap-2 break-words line-clamp-2 group-hover:text-red-500'>
-                                <div className='font-semibold line-clamp-2 group-hover:text-red-500 text-sm mr-2'>{childCategory.name}</div>
-                              </div>
-                            </Link>
+                  return (
+                    <div key={subCategory.id} className='border rounded justify-start items-start'>
+                      <div className='p-3'>
+                        <div className='flex flex-row border rounded mb-2 justify-start items-center'>
+                          <NextImage
+                            src={subCategory.image ? subCategory.image : "/images/noimage.jpeg"}
+                            alt={subCategory.name}
+                            width={90}
+                            height={30}
+                            className='object-fit'
+                          />
+                          <div className='bagian-judul flex flex-col justify-center items-start gap-2 ml-2'>
+                            <div className='font-semibold text-lg mr-2'>{subCategory.name}</div>
+                            {/* <p className={`text-gray_r-10 text-sm ${countLevel2 === 0 ? 'animate-pulse ' : ''}`}>
+                              {countLevel2 === 0 ? 'Menghitung jumlah produk...' : `${countLevel2} Produk tersedia`}
+                            </p> */}
+                            <Skeleton isLoaded={countLevel2 != 0}>
+                            <p className={`text-gray_r-10 text-sm`}>
+                              {countLevel2} Produk tersedia
+                            </p>
+                            </Skeleton>
+                            <Link href={createSlug('/shop/category/', subCategory?.name, subCategory?.idLevel2)} 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]'>
+                          {subCategory.childFrontendIdI.map((childCategory) => (
+                            <div key={childCategory.id}>
+                              <Link href={createSlug('/shop/category/', childCategory?.name, childCategory?.idLevel3)} 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}
+                                  width={40}
+                                  height={40}
+                                />
+                                <div className='bagian-judul flex flex-col justify-center items-center gap-2 break-words line-clamp-2 group-hover:text-red-500'>
+                                  <div className='font-semibold line-clamp-2 group-hover:text-red-500 text-sm mr-2'>{childCategory.name}</div>
+                                </div>
+                              </Link>
+                            </div>
+                          ))}
+                        </div>
                       </div>
                     </div>
-                  </div>
-                );
-              })}
+                  );
+                })}
+              </div>
             </div>
-          </div>
-        );
-      })}
+          </Skeleton>
+          );
+        })}
     </div>
   );
 };
-- 
cgit v1.2.3


From c62a5dd32e961f06a01d0a535d2fbf37118ff2e7 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 30 Jul 2024 16:09:07 +0700
Subject: <iman> add key missing

---
 src/lib/home/components/CategoryDynamic.jsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(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 dda7cdc4..60e01df0 100644
--- a/src/lib/home/components/CategoryDynamic.jsx
+++ b/src/lib/home/components/CategoryDynamic.jsx
@@ -46,7 +46,7 @@ const CategoryDynamic = () => {
           const countLevel1 = categoryData[category.categoryIdI] || 0;
           
           return (
-            <Skeleton isLoaded={categoryManagement}>
+            <Skeleton key={category.id} isLoaded={categoryManagement}>
             <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>
-- 
cgit v1.2.3


From 8fe0cdf1f457148eb39d5438b13bbec7bc912976 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Wed, 31 Jul 2024 08:59:17 +0700
Subject: <iman> update category management

---
 src/lib/home/components/CategoryDynamic.jsx | 13 +++----------
 1 file changed, 3 insertions(+), 10 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 60e01df0..f2d1a16f 100644
--- a/src/lib/home/components/CategoryDynamic.jsx
+++ b/src/lib/home/components/CategoryDynamic.jsx
@@ -18,14 +18,10 @@ const CategoryDynamic = () => {
         const updatedSubCategoryData = {};
         
         for (const category of categoryManagement.data) {
-          // Calculate level 1 products
           const countLevel1 = await odooApi('GET', `/api/v1/category/numFound?parent_id=${category.categoryIdI}`);
-          // console.log("countLevel1.child",countLevel1)
           
           updatedCategoryData[category.categoryIdI] = countLevel1?.numFound;
           
-          
-          // Calculate level 2 products for each sub-category
           for (const subCategory of countLevel1.children) {
             updatedSubCategoryData[subCategory.id] = subCategory.numFound;
           }
@@ -50,9 +46,9 @@ const CategoryDynamic = () => {
             <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>
-                <p className={`text-gray_r-10 text-sm ${countLevel1 === 0 ? 'animate-pulse ' : ''}`}>
-                  {countLevel1 === 0 ? 'Menghitung jumlah produk...' : `${countLevel1} Produk tersedia`}
-              </p>
+                <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>
               </div>
               <div className='grid grid-cols-3 gap-2'>
@@ -72,9 +68,6 @@ const CategoryDynamic = () => {
                           />
                           <div className='bagian-judul flex flex-col justify-center items-start gap-2 ml-2'>
                             <div className='font-semibold text-lg mr-2'>{subCategory.name}</div>
-                            {/* <p className={`text-gray_r-10 text-sm ${countLevel2 === 0 ? 'animate-pulse ' : ''}`}>
-                              {countLevel2 === 0 ? 'Menghitung jumlah produk...' : `${countLevel2} Produk tersedia`}
-                            </p> */}
                             <Skeleton isLoaded={countLevel2 != 0}>
                             <p className={`text-gray_r-10 text-sm`}>
                               {countLevel2} Produk tersedia
-- 
cgit v1.2.3

