From baf0447595815be64312ac836e5f8bb403e4dcfc Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 19 May 2023 16:31:42 +0700 Subject: banner section and product category banner url --- src/lib/home/api/bannerSectionApi.js | 8 ++++++++ src/lib/home/components/BannerSection.jsx | 30 ++++++++++++++++++++++++++++++ src/lib/home/components/CategoryHome.jsx | 2 +- src/lib/home/components/CategoryHomeId.jsx | 15 +++++++++------ src/pages/index.jsx | 3 +++ 5 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 src/lib/home/api/bannerSectionApi.js create mode 100644 src/lib/home/components/BannerSection.jsx (limited to 'src') 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 && ( +
+ {bannerSection.data?.map((banner) => ( + + {banner.name} + + ))} +
+ ) + ) +} + +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 ( -
- {categoryHomeIds.data?.map((id) => ( - - - - ))} +
+
Kategori Pilihan
+
+ {categoryHomeIds.data?.map((id) => ( + + + + ))} +
) } diff --git a/src/pages/index.jsx b/src/pages/index.jsx index 5d2a3afb..d83bc990 100644 --- a/src/pages/index.jsx +++ b/src/pages/index.jsx @@ -13,6 +13,7 @@ import Link from '@/core/components/elements/Link/Link' const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout')) const FlashSale = dynamic(() => import('@/lib/flashSale/components/FlashSale')) +const BannerSection = dynamic(() => import('@/lib/home/components/BannerSection')) const HeroBanner = dynamic(() => import('@/lib/home/components/HeroBanner'), { loading: () => }) @@ -88,6 +89,7 @@ export default function Home() { + @@ -112,6 +114,7 @@ export default function Home() { + -- cgit v1.2.3