diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/home/api/bannerSectionApi.js | 8 | ||||
| -rw-r--r-- | src/lib/home/components/BannerSection.jsx | 30 | ||||
| -rw-r--r-- | src/lib/home/components/CategoryHome.jsx | 2 | ||||
| -rw-r--r-- | src/lib/home/components/CategoryHomeId.jsx | 15 |
4 files changed, 48 insertions, 7 deletions
diff --git a/src/lib/home/api/bannerSectionApi.js b/src/lib/home/api/bannerSectionApi.js new file mode 100644 index 00000000..5c945ee0 --- /dev/null +++ b/src/lib/home/api/bannerSectionApi.js @@ -0,0 +1,8 @@ +import odooApi from '@/core/api/odooApi' + +const bannerSectionApi = async () => { + const dataBannerSections = await odooApi('GET', '/api/v1/banner?type=home-banner') + return dataBannerSections +} + +export default bannerSectionApi diff --git a/src/lib/home/components/BannerSection.jsx b/src/lib/home/components/BannerSection.jsx new file mode 100644 index 00000000..8459d08e --- /dev/null +++ b/src/lib/home/components/BannerSection.jsx @@ -0,0 +1,30 @@ +import Link from '@/core/components/elements/Link/Link' +import Image from 'next/image' + +const { useQuery } = require('react-query') +const { default: bannerSectionApi } = require('../api/bannerSectionApi') + +const BannerSection = () => { + const fetchBannerSection = async () => await bannerSectionApi() + const bannerSection = useQuery('bannerSection', fetchBannerSection) + + return ( + bannerSection.data && ( + <div className='grid grid-cols-1 sm:grid-cols-2 gap-4'> + {bannerSection.data?.map((banner) => ( + <Link key={banner.id} href={banner.url}> + <Image + width={512} + height={256} + src={banner.image} + alt={banner.name} + className='h-auto w-full rounded' + /> + </Link> + ))} + </div> + ) + ) +} + +export default BannerSection diff --git a/src/lib/home/components/CategoryHome.jsx b/src/lib/home/components/CategoryHome.jsx index 4566bc4b..5ff8f34e 100644 --- a/src/lib/home/components/CategoryHome.jsx +++ b/src/lib/home/components/CategoryHome.jsx @@ -14,7 +14,7 @@ const CategoryHome = ({ id }) => { banner: { image: categoryHome.data?.[0].image, name: categoryHome.data?.[0].name, - url: `/shop/search?category=${categoryHome.data?.[0].name}` + url: categoryHome.data?.[0].url } }} simpleTitle diff --git a/src/lib/home/components/CategoryHomeId.jsx b/src/lib/home/components/CategoryHomeId.jsx index 4899f216..3707063c 100644 --- a/src/lib/home/components/CategoryHomeId.jsx +++ b/src/lib/home/components/CategoryHomeId.jsx @@ -6,12 +6,15 @@ const CategoryHomeId = () => { const { categoryHomeIds } = useCategoryHomeId() return ( - <div className='flex flex-col gap-y-10'> - {categoryHomeIds.data?.map((id) => ( - <LazyLoadComponent key={id}> - <CategoryHome id={id} /> - </LazyLoadComponent> - ))} + <div> + <div className='font-medium sm:text-h-lg mb-6 px-4 sm:px-0'>Kategori Pilihan</div> + <div className='flex flex-col gap-y-10'> + {categoryHomeIds.data?.map((id) => ( + <LazyLoadComponent key={id}> + <CategoryHome id={id} /> + </LazyLoadComponent> + ))} + </div> </div> ) } |
