import odooApi from '@/core/api/odooApi' import Link from '@/core/components/elements/Link/Link' import DesktopView from '@/core/components/views/DesktopView' import { createSlug } from '@/core/utils/slug' 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 () => { // 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() // }, []) // console.log("categories",categories) return (
{categories?.map((category) => (
{category.name}
{category.childs.map((child1Category) => (
{child1Category.name}
{child1Category.childs.map((child2Category, index) => ( (index < 4) && ( {child2Category.name} ) ))} {child1Category.childs.length > 5 && (

Lihat Semua

)}
))}
{promotionProgram?.data[0]?.map((banner, index)=>(
{/* */} {`${banner.name}`}
))}
))}
) } export default Category