From 911e0fdc6beb2f97c7e390a6aec5773202189d68 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 19 Jul 2024 17:07:23 +0700
Subject: <iman> update mobile view

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

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

diff --git a/src/lib/home/components/CategoryDynamicMobile.jsx b/src/lib/home/components/CategoryDynamicMobile.jsx
new file mode 100644
index 00000000..a550bd62
--- /dev/null
+++ b/src/lib/home/components/CategoryDynamicMobile.jsx
@@ -0,0 +1,69 @@
+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'
+import { Swiper, SwiperProps, SwiperSlide }  from 'swiper/react';
+import 'swiper/css';
+
+const CategoryDynamicMobile =    () => {
+  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()
+
+  },[]);
+
+  console.log("promoItems",promoItems)
+
+  return (
+    <div className='p-4'>
+      {/* <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-between items-center gap-3 mb-4 mt-4'>
+              <div className='font-semibold sm:text-h-sm mr-2'>{category.name}</div>
+                <Link href={createSlug('/shop/category/', category?.name, category?.category_id)} className="!text-red-500 font-semibold text-sm">Lihat Semua</Link>
+          </div>
+          <Swiper slidesPerView={2.3} spaceBetween={10}>
+          {category.category_id2.map((index)=> (
+            <SwiperSlide>
+              <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>
+              </div>
+            </SwiperSlide>
+            ))}
+          </Swiper>
+        </div>
+      ))}
+    </div>
+  );
+}
+
+export default CategoryDynamicMobile;
-- 
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/CategoryDynamicMobile.jsx | 97 +++++++++++++++--------
 1 file changed, 65 insertions(+), 32 deletions(-)

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

diff --git a/src/lib/home/components/CategoryDynamicMobile.jsx b/src/lib/home/components/CategoryDynamicMobile.jsx
index a550bd62..317042b8 100644
--- a/src/lib/home/components/CategoryDynamicMobile.jsx
+++ b/src/lib/home/components/CategoryDynamicMobile.jsx
@@ -1,69 +1,102 @@
 import React, { useEffect, useState } from 'react';
-import {fetchProductManagementSolr} from '../hooks/useCategoryManagement';
+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'
-import { Swiper, SwiperProps, SwiperSlide }  from 'swiper/react';
+import Link from "next/link";
+import { createSlug } from '@/core/utils/slug';
+import { Swiper, SwiperSlide } from 'swiper/react';
 import 'swiper/css';
 
-const CategoryDynamicMobile =    () => {
+const CategoryDynamicMobile = () => {
   const [promoItems, setPromoItems] = useState([]);
+  const [selectedCategory, setSelectedCategory] = useState({});
+
   useEffect(() => {
     const loadPromo = async () => {
-      
       try {
         const items = await fetchProductManagementSolr();
         setPromoItems(items);
-
+        if (items.length > 0) {
+          const initialSelections = items.reduce((acc, category) => {
+            if (category.category_id2.length > 0) {
+              acc[category.id] = category.category_id2[0].id_level_2;
+            }
+            return acc;
+          }, {});
+          setSelectedCategory(initialSelections);
+        }
       } catch (loadError) {
         // console.error("Error loading promo items:", loadError)
       }
-    }
-      loadPromo()
+    };
+    loadPromo();
+  }, []);
 
-  },[]);
-
-  console.log("promoItems",promoItems)
+  const handleCategoryLevel2Click = (categoryLevel1Id, categoryLevel2Id) => {
+    setSelectedCategory(prev => ({
+      ...prev,
+      [categoryLevel1Id]: categoryLevel2Id
+    }));
+  };
 
   return (
     <div className='p-4'>
-      {/* <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-between items-center gap-3 mb-4 mt-4'>
-              <div className='font-semibold sm:text-h-sm mr-2'>{category.name}</div>
-                <Link href={createSlug('/shop/category/', category?.name, category?.category_id)} className="!text-red-500 font-semibold text-sm">Lihat Semua</Link>
+            <div className='font-semibold sm:text-h-sm mr-2'>{category.name}</div>
+            <Link href={createSlug('/shop/category/', category?.name, category?.category_id)} className="!text-red-500 font-semibold text-sm">Lihat Semua</Link>
           </div>
           <Swiper slidesPerView={2.3} spaceBetween={10}>
-          {category.category_id2.map((index)=> (
-            <SwiperSlide>
-              <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'>
+            {category.category_id2.map((index) => (
+              <SwiperSlide key={index.id}>
+                <div
+                  onClick={() => handleCategoryLevel2Click(category.id, index?.id_level_2)}
+                  className={`border flex justify-start items-center max-w-48 max-h-16 rounded ${selectedCategory[category.id] === index?.id_level_2 ? 'bg-red-50 border-red-500 text-red-500' : 'border-gray-200 text-gray-900'}`}
+                >
+                  <div className='p-1 flex justify-start items-center'>
+                    <div className='flex flex-row justify-center 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}
+                        width={30}
                         height={30}
-                        className='object-fit'
+                        className='object-'
                       />
-                      <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 className='bagian-judul flex flex-col justify-center items-start gap-1 ml-2'>
+                        <div className='font-semibold text-[10px] line-clamp-1'>{index.name}</div>
+                        <p className='text-gray_r-10 text-[10px]'>999 rb+ Produk</p>
                       </div>
                     </div>
+                  </div>
                 </div>
-              </div>
-            </SwiperSlide>
+              </SwiperSlide>
             ))}
           </Swiper>
+          <div className='p-3 mt-2 border'>
+            <div className='grid grid-cols-2 gap-2 overflow-y-auto max-h-[240px]'>
+              {category.category_id2.map((index) => (
+                selectedCategory[category.id] === index?.id_level_2 && 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-1 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-start gap-1 break-words line-clamp-2 group-hover:text-red-500'>
+                        <div className='font-semibold line-clamp-2 group-hover:text-red-500 text-[10px]'>{x.name}</div>
+                      </div>
+                    </Link>
+                  </div>
+                ))
+              ))}
+            </div>
+          </div>
         </div>
       ))}
     </div>
   );
-}
+};
 
 export default CategoryDynamicMobile;
-- 
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/CategoryDynamicMobile.jsx | 41 +++++++++++------------
 1 file changed, 20 insertions(+), 21 deletions(-)

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

diff --git a/src/lib/home/components/CategoryDynamicMobile.jsx b/src/lib/home/components/CategoryDynamicMobile.jsx
index 317042b8..c1433a2d 100644
--- a/src/lib/home/components/CategoryDynamicMobile.jsx
+++ b/src/lib/home/components/CategoryDynamicMobile.jsx
@@ -1,5 +1,5 @@
 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 { createSlug } from '@/core/utils/slug';
@@ -7,51 +7,50 @@ import { Swiper, SwiperSlide } from 'swiper/react';
 import 'swiper/css';
 
 const CategoryDynamicMobile = () => {
-  const [promoItems, setPromoItems] = useState([]);
+  const { categoryManagement } = useCategoryManagement()
   const [selectedCategory, setSelectedCategory] = useState({});
 
   useEffect(() => {
     const loadPromo = async () => {
       try {
-        const items = await fetchProductManagementSolr();
-        setPromoItems(items);
-        if (items.length > 0) {
-          const initialSelections = items.reduce((acc, category) => {
-            if (category.category_id2.length > 0) {
-              acc[category.id] = category.category_id2[0].id_level_2;
+        if (categoryManagement.data?.length > 0) {
+          const initialSelections = categoryManagement.data.reduce((acc, category) => {
+            if (category.categories.length > 0) {
+              acc[category.id] = category.categories[0].idLevel2;
             }
             return acc;
           }, {});
           setSelectedCategory(initialSelections);
         }
       } catch (loadError) {
-        // console.error("Error loading promo items:", loadError)
+        // console.error("Error loading promo items:", loadError);
       }
     };
+
     loadPromo();
-  }, []);
+  }, [categoryManagement.data]);
 
-  const handleCategoryLevel2Click = (categoryLevel1Id, categoryLevel2Id) => {
+  const handleCategoryLevel2Click = (categoryIdI, idLevel2) => {
     setSelectedCategory(prev => ({
       ...prev,
-      [categoryLevel1Id]: categoryLevel2Id
+      [categoryIdI]: idLevel2
     }));
   };
-
+ 
   return (
     <div className='p-4'>
-      {promoItems && promoItems.map((category) => (
+      {categoryManagement.data && categoryManagement.data.map((category) => (
         <div key={category.id}>
           <div className='bagian-judul flex flex-row justify-between items-center gap-3 mb-4 mt-4'>
             <div className='font-semibold sm:text-h-sm mr-2'>{category.name}</div>
-            <Link href={createSlug('/shop/category/', category?.name, category?.category_id)} className="!text-red-500 font-semibold text-sm">Lihat Semua</Link>
+            <Link href={createSlug('/shop/category/', category?.name, category?.categoryIdI)} className="!text-red-500 font-semibold text-sm">Lihat Semua</Link>
           </div>
           <Swiper slidesPerView={2.3} spaceBetween={10}>
-            {category.category_id2.map((index) => (
+            {category.categories.map((index) => (
               <SwiperSlide key={index.id}>
                 <div
-                  onClick={() => handleCategoryLevel2Click(category.id, index?.id_level_2)}
-                  className={`border flex justify-start items-center max-w-48 max-h-16 rounded ${selectedCategory[category.id] === index?.id_level_2 ? 'bg-red-50 border-red-500 text-red-500' : 'border-gray-200 text-gray-900'}`}
+                  onClick={() => handleCategoryLevel2Click(category.id, index?.idLevel2)}
+                  className={`border flex justify-start items-center max-w-48 max-h-16 rounded ${selectedCategory[category.id] === index?.idLevel2 ? 'bg-red-50 border-red-500 text-red-500' : 'border-gray-200 text-gray-900'}`}
                 >
                   <div className='p-1 flex justify-start items-center'>
                     <div className='flex flex-row justify-center items-center'>
@@ -74,10 +73,10 @@ const CategoryDynamicMobile = () => {
           </Swiper>
           <div className='p-3 mt-2 border'>
             <div className='grid grid-cols-2 gap-2 overflow-y-auto max-h-[240px]'>
-              {category.category_id2.map((index) => (
-                selectedCategory[category.id] === index?.id_level_2 && index.child_frontend_id_i.map((x) => (
+              {category.categories.map((index) => (
+                selectedCategory[category.id] === index?.idLevel2 && index.childFrontendIdI.map((x) => (
                   <div key={x.id}>
-                    <Link href={createSlug('/shop/category/', x?.name, x?.id_level_3)} className="flex flex-row gap-1 border rounded group hover:border-red-500">
+                    <Link href={createSlug('/shop/category/', x?.name, x?.idLevel3)} className="flex flex-row gap-1 border rounded group hover:border-red-500">
                       <NextImage
                         src={x.image ? x.image : "/images/noimage.jpeg"}
                         alt={x.name}
-- 
cgit v1.2.3

