summaryrefslogtreecommitdiff
path: root/src-migrate/modules/product/PromoSection.tsx
blob: 299cbb789396f6385d63c11292f95b150a92e666 (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
import React from 'react'
import style from "./PromoSection.module.css"
import PromoCard from './PromoCard'
import { useQuery } from 'react-query'
import { Skeleton } from '@chakra-ui/react'
import { IPromotion } from '~/common/types/promotion'

type Props = {
  productId: number
}

const PromoSection = ({ productId }: Props) => {
  const promotionsQuery = useQuery(
    `promotions-highlight:${productId}`,
    async () => await fetch(`/api/product-variant/${productId}/promotion/highlight`).then((res) => res.json()) as { data: IPromotion[] },
  )

  const promotions = promotionsQuery.data

  const handleSeeMore = () => { }

  return (
    <div className='w-full'>
      {promotions?.data && promotions?.data.length > 0 && (
        <div className={style.titleWrapper}>
          <span className={style.title}>Promo Tersedia</span>
          <button type='button' onClick={handleSeeMore} className={style.seeMore}>
            Lihat Semua
          </button>
        </div>
      )}

      <Skeleton isLoaded={promotionsQuery.isSuccess} className="flex gap-x-4 overflow-x-auto min-h-[340px]">
        {promotions?.data.map((promotion) => (
          <PromoCard key={promotion.id} promotion={promotion} />
        ))}
      </Skeleton>
    </div>
  )
}

export default PromoSection