From 4dc62bbe5262be23b2622853973e803f63214a60 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 12 Aug 2024 17:09:13 +0700
Subject: <iman> update category management

---
 src/lib/category/components/Category.jsx | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

(limited to 'src/lib/category/components/Category.jsx')

diff --git a/src/lib/category/components/Category.jsx b/src/lib/category/components/Category.jsx
index ff958378..b10cb661 100644
--- a/src/lib/category/components/Category.jsx
+++ b/src/lib/category/components/Category.jsx
@@ -6,11 +6,36 @@ import { ChevronRightIcon } from '@heroicons/react/24/outline'
 import Image from 'next/image'
 import { useEffect, useState } from 'react'
 import PopularBrand from './PopularBrand'
+import { bannerApi } from '@/api/bannerApi';
+const { useQuery } = require('react-query')
 
 const Category = () => {
   const [categories, setCategories] = useState([])
   const [openCategories, setOpenCategory] = useState([]);
+  const [banner, setBanner] = useState([]);
+
+  const promotionProgram = useQuery('banner-promo-category-card', bannerApi({ type: 'banner-promo-category-card' }));
+  // const promotionProgram = useQuery('promotionProgram', bannerApi({ type: 'banner-promotion' }));
   
+  useEffect(() => {
+    const loadCategories = async () => {
+      let dataCategories = await odooApi('GET', '/api/v1/category/tree')
+      dataCategories = dataCategories?.map((category) => {
+        category.childs = category.childs.map((child1Category) => {
+          return {
+            ...child1Category,
+            isOpen: false
+          }
+        })
+        return {
+          ...category,
+          isOpen: false
+        }
+      })
+      setCategories(dataCategories)
+    }
+    loadCategories()
+  }, [])
 
   useEffect(() => {
     const loadCategories = async () => {
@@ -86,9 +111,12 @@ const Category = () => {
               </div>
               <div className='category-mega-box__child-wrapper !w-[260px] !flex !flex-col !gap-4'>
               <PopularBrand category={category} />
-                <div className='flex w-60 h-20 object-cover'>
-                  <Image src='https://erp.indoteknik.com/api/image/x_banner.banner/x_banner_image/397' alt='' width={275} height={4} />
+              {promotionProgram?.data[0]?.map((banner, index)=>(
+                <div key={index} className='flex w-60 h-20 object-cover'>
+                  {/* <Image src='https://erp.indoteknik.com/api/image/x_banner.banner/x_banner_image/397' alt='' width={275} height={4} /> */}
+                  <Image src={`${banner.image}`} alt={`${banner.name}`} width={275} height={4} />
                 </div>
+              ))}
               </div>
             </div>
           </div>
-- 
cgit v1.2.3

