diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-03-11 13:37:29 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-03-11 13:37:29 +0700 |
| commit | d26133d39e7d9cd510fdc72d239303f4ba918bdd (patch) | |
| tree | ac3266dbd2d949c6cfc230183e18014d7df0552b /src/lib/category | |
| parent | 1218d8109380488ab7d15538fe3f828883dbc822 (diff) | |
create useDevice hooks, optimize DesktopView and MobileView, and show category API data
Diffstat (limited to 'src/lib/category')
| -rw-r--r-- | src/lib/category/components/Category.jsx | 77 |
1 files changed, 59 insertions, 18 deletions
diff --git a/src/lib/category/components/Category.jsx b/src/lib/category/components/Category.jsx index 21e2ec6f..5ba45cc7 100644 --- a/src/lib/category/components/Category.jsx +++ b/src/lib/category/components/Category.jsx @@ -1,28 +1,69 @@ +import odooApi from '@/core/api/odooApi' import Link from '@/core/components/elements/Link/Link' import DesktopView from '@/core/components/views/DesktopView' +import { useEffect, useState } from 'react' const Category = () => { + const [categories, setCategories] = useState([]) + + 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() + }, []) + return ( <DesktopView> - <div className='category-box'> - <div> - <Link href='/'>Alat Potong & Pelengkap Mesin</Link> - <div> - <div className='font-medium'>Alat Potong & Pelengkap Mesin</div> - </div> - </div> - <div> - <Link href='/'>Alat Ukur & Instrument</Link> - <div> - <div className='font-medium'>Alat Ukur & Instrument</div> - </div> - </div> - <div> - <Link href='/'>Komponen Mekanikal & Hardware</Link> - <div> - <div className='font-medium'>Komponen Mekanikal & Hardware</div> + <div className='category-mega-box'> + {categories.map((category) => ( + <div key={category.id}> + <Link + href='/' + className='category-mega-box__parent' + > + {category.name} + </Link> + <div className='category-mega-box__child-wrapper'> + <div className='grid grid-cols-3 gap-x-4 gap-y-6 max-h-full overflow-auto'> + {category.childs.map((child1Category) => ( + <div key={child1Category.id}> + <Link + href='/' + className='category-mega-box__child-one mb-4' + > + {child1Category.name} + </Link> + <div className='flex flex-col gap-y-3'> + {child1Category.childs.map((child2Category) => ( + <Link + href='/' + className='category-mega-box__child-two' + key={child2Category.id} + > + {child2Category.name} + </Link> + ))} + </div> + </div> + ))} + </div> + </div> </div> - </div> + ))} </div> </DesktopView> ) |
