From 8d8c43d90373aab6238773e291a48d65d55c52a2 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Sat, 17 Feb 2024 10:23:23 +0700 Subject: Add voucher section --- src-migrate/modules/promo/components/Hero.tsx | 23 +++++--- src-migrate/modules/promo/components/Voucher.tsx | 73 ++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 7 deletions(-) (limited to 'src-migrate/modules/promo/components') diff --git a/src-migrate/modules/promo/components/Hero.tsx b/src-migrate/modules/promo/components/Hero.tsx index 63524509..5470b93b 100644 --- a/src-migrate/modules/promo/components/Hero.tsx +++ b/src-migrate/modules/promo/components/Hero.tsx @@ -1,19 +1,21 @@ -import { Swiper, SwiperProps, SwiperSlide } from 'swiper/react'; -import style from '../styles/hero.module.css'; -import 'swiper/css' +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'; const swiperBanner: SwiperProps = { autoplay: { delay: 6000, disableOnInteraction: false }, - // modules: [Pagination, Autoplay], - loop: true, + loop: false, className: 'h-[400px] w-full', - slidesPerView: 1.1, + slidesPerView: 1, spaceBetween: 10 } @@ -23,7 +25,14 @@ const Hero = () => { queryFn: () => getBanner({ type: 'all-promo' }) }) - const banners = bannerQuery.data || [] + const banners = useMemo(() => bannerQuery.data || [], [bannerQuery.data]); + + useEffect(() => { + if (banners.length > 1) { + swiperBanner.slidesPerView = 1.1; + swiperBanner.loop = true; + } + }, [banners]); return (
diff --git a/src-migrate/modules/promo/components/Voucher.tsx b/src-migrate/modules/promo/components/Voucher.tsx index 11742f9a..0706f044 100644 --- a/src-migrate/modules/promo/components/Voucher.tsx +++ b/src-migrate/modules/promo/components/Voucher.tsx @@ -1,9 +1,82 @@ +import { useMemo } from 'react' +import { useQuery } from 'react-query' +import { Swiper, SwiperProps, SwiperSlide } from 'swiper/react' +import { getVoucher } from '~/services/voucher' import style from '../styles/voucher.module.css' +import Image from 'next/image' +import { useToast } from '@chakra-ui/react' + +const swiperVoucher: SwiperProps = { + autoplay: { + delay: 6000, + disableOnInteraction: false + }, + loop: false, + className: 'h-[160px] w-full', + slidesPerView: 3, + spaceBetween: 16 +} const Voucher = () => { + const toast = useToast(); + const voucherQuery = useQuery({ + queryKey: ['voucher.all-voucher'], + queryFn: getVoucher + }) + + const vouchers = useMemo(() => voucherQuery.data || [], [voucherQuery.data]); + + const copyText = (text: string) => { + navigator.clipboard.writeText(text) + toast({ + title: 'Salin ke papan klip', + description: 'Kode voucher berhasil disalin', + status: 'success', + duration: 3000, + isClosable: true, + position: 'bottom', + }) + } + return ( <>
Pakai Voucher Belanja
+ +
+ + {voucherQuery.isLoading && ( +
+ {Array.from({ length: 3 }).map((_, index) => ( +
+ ))} +
+ )} + {!voucherQuery.isLoading && ( +
+ + {vouchers.map((voucher) => ( + +
+ {voucher.name} + +
+
{voucher.name}
+
{voucher.description} Lorem ipsum dolor sit, amet consectetur adipisicing elit. Officiis magni nobis sint aspernatur soluta deserunt excepturi delectus corporis libero, voluptate odit! Cupiditate, quibusdam ipsa saepe voluptas repudiandae eum quaerat suscipit.
+
+
+
Kode Promo
+
{voucher.code}
+
+ +
+
+
+
+ ))} +
+
+ )} + ) } -- cgit v1.2.3