summaryrefslogtreecommitdiff
path: root/src/lib/home/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/home/components')
-rw-r--r--src/lib/home/components/MediaNews.jsx107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/lib/home/components/MediaNews.jsx b/src/lib/home/components/MediaNews.jsx
new file mode 100644
index 00000000..1e538d48
--- /dev/null
+++ b/src/lib/home/components/MediaNews.jsx
@@ -0,0 +1,107 @@
+import Link from '@/core/components/elements/Link/Link';
+import Image from 'next/image';
+import { bannerApi } from '@/api/bannerApi';
+import useDevice from '@/core/hooks/useDevice';
+import { Swiper, SwiperSlide } from 'swiper/react';
+import BannerPromoSkeleton from '../components/Skeleton/BannerPromoSkeleton';
+
+import { useEffect, useState } from 'react';
+const { useQuery } = require('react-query');
+const BannerSection = () => {
+ const { isMobile, isDesktop } = useDevice();
+ const [data, setData] = useState(null);
+ const [shouldFetch, setShouldFetch] = useState(false);
+ const [ isLoading, setIsLoading] = useState(true);
+ useEffect(() => {
+ const fetchData = async () => {
+ try {
+ const res = await fetch(`/api/hero-banner?type=banner-promotion`);
+ const { data } = await res.json();
+ if (data) {
+ setData(data);
+ }
+ } catch (e) {
+ console.log(e);
+ } finally {
+ setIsLoading(false);
+ }
+ };
+
+ fetchData();
+ }, []);
+
+ const promotionProgram = data;
+
+ if (isLoading) {
+ return <BannerPromoSkeleton />;
+ }
+
+ if (!promotionProgram || promotionProgram.length === 0) {
+ return null;
+ }
+
+ return (
+ <div className='px-4 sm:px-0'>
+ <div className='flex justify-between items-center mb-4 '>
+ <h1 className='font-semibold text-[14px] sm:text-h-lg'>
+ {' '}
+ <Link href='/shop/promo' className='!text-black font-semibold'>
+ Promo Tersedia
+ </Link>
+ </h1>
+ {isDesktop && (
+ <Link href='/shop/promo' className='!text-red-500 font-semibold'>
+ Lihat Semua
+ </Link>
+ )}
+ {isMobile && (
+ <Link
+ href='/shop/promo'
+ className='!text-red-500 font-semibold sm:text-h-sm'
+ >
+ Lihat Semua
+ </Link>
+ )}
+ </div>
+ {isDesktop && promotionProgram && promotionProgram?.length > 0 && (
+ <div className='grid grid-cols-3 sm:grid-cols-3 gap-4 rounded-md'>
+ {promotionProgram?.map((banner) => (
+ <Link key={banner.id} href={banner.url}>
+ <Image
+ width={439}
+ height={150}
+ quality={85}
+ src={banner.image}
+ alt={banner.name}
+ className='rounded hover:scale-105 transition duration-500 ease-in-out'
+ loading='eager'
+ />
+ </Link>
+ ))}
+ </div>
+ )}
+
+ {isMobile && (
+ <Swiper slidesPerView={1.1} spaceBetween={8} freeMode>
+ {promotionProgram?.map((banner) => (
+ <SwiperSlide key={banner.id}>
+ <Link key={banner.id} href={banner.url}>
+ <Image
+ width={350}
+ height={100}
+ quality={70}
+ src={banner.image}
+ alt={banner.name}
+ className='rounded '
+ loading='eager'
+ />
+ </Link>
+ </SwiperSlide>
+ ))}
+ </Swiper>
+ )}
+ </div>
+ );
+};
+
+export default BannerSection;