summaryrefslogtreecommitdiff
path: root/src-migrate/modules/promo/components/Hero.tsx
blob: 2701250d5c82c7183dc67d5096a1d1c06861cf94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import 'swiper/css';

import Image from 'next/image';
import { useEffect, useMemo } from 'react';
import { useQuery } from 'react-query';
import { Swiper, SwiperProps, SwiperSlide }  from 'swiper/react';

import { getBanner } from '~/services/banner';
import style from '../styles/hero.module.css';
import 'swiper/css/navigation';
import 'swiper/css/pagination';
import  { Navigation, Pagination, Autoplay } from 'swiper';
import MobileView from '../../../../src/core/components/views/MobileView';
import DesktopView from '@/core/components/views/DesktopView';

const swiperBanner: SwiperProps = {
  modules:[Navigation, Pagination, Autoplay],
  autoplay: {
    delay: 6000,
    disableOnInteraction: false
  },
  loop: true,
  className: 'h-[400px] w-full',
  slidesPerView: 1,
  spaceBetween: 10,
  pagination:true,
}
const swiperBannerMob = {
  autoplay: {
    delay: 6000,
    disableOnInteraction: false,
  },
  modules: [Pagination, Autoplay],
  loop: true,
  className: 'border border-gray_r-6 min-h-full',
  slidesPerView: 1,
};

const Hero = () => {
  const bannerQuery = useQuery({
    queryKey: ['banner.all-promo'],
    queryFn: () => getBanner({ type: 'banner-promotion' })
  })

  const banners = useMemo(() => bannerQuery.data || [], [bannerQuery.data]);

  useEffect(() => {
    if (banners.length > 1) {
      swiperBanner.slidesPerView = 1.1;
      swiperBanner.loop = true;
      swiperBannerMobile.loop = true;
    }
  }, [banners]);

  const swiperBannerMobile = {
    ...swiperBannerMob,
    pagination: { dynamicBullets: false, clickable: true },
  };

  return (
    <>
      <DesktopView>
        <div className={style['wrapper']}>
          <div className={style['desc-section']}>
            <div className={style['title']}>Pasti Hemat & Untung Selama Belanja di Indoteknik.com!</div>
            <div className='h-4' />
            <div className={style['subtitle']}>Cari paket yang kami sediakan dengan penawaran harga & Nikmati kemudahan dalam setiap transaksi dengan fitur lengkap Pembayaran hingga barang sampai! </div>
          </div>

          <div className={style['banner-section']}>
            <Swiper {...swiperBanner}>
              {banners.map((banner, index) => (
                <SwiperSlide key={index}>
                  <Image
                    src={banner.image}
                    alt={banner.name}
                    width={666}
                    height={450}
                    quality={100}
                    className='w-full h-full object-fit object-center rounded-2xl' />
                </SwiperSlide>
              ))}
            </Swiper>
          </div>
        </div>
      </DesktopView>
      <MobileView>
          <Swiper {...swiperBannerMobile}>
            {banners?.map((banner, index) => (
              <SwiperSlide key={index}>
                    <Image
                      width={439}
                      height={150}
                      quality={100}
                      src={banner.image}
                      alt={banner.name}
                      className='w-full h-full object-cover object-center rounded-2xl'
                    />
              </SwiperSlide>
            ))}
          </Swiper>
          
      </MobileView>
    </>
  )
}

export default Hero