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}
Kode Promo
{voucher.code}
))}
)} ) } export default Voucher