summaryrefslogtreecommitdiff
path: root/src-migrate/modules/product-promo/components/Section.tsx
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-06-21 11:01:35 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-06-21 11:01:35 +0700
commit220190db66bcc1c6db78180c593f21e9cf8f363c (patch)
tree1517faa9636a6b3b2cc8d468a57b1fe476c229d7 /src-migrate/modules/product-promo/components/Section.tsx
parent208b234320b6c42491a4e87a1c3db3abab9c1715 (diff)
parent1cf754b4d8da1aa28700ffc3dad67081f6daf9a5 (diff)
Merge branch 'promotion-program' into feature/all-promotion
Diffstat (limited to 'src-migrate/modules/product-promo/components/Section.tsx')
-rw-r--r--src-migrate/modules/product-promo/components/Section.tsx30
1 files changed, 17 insertions, 13 deletions
diff --git a/src-migrate/modules/product-promo/components/Section.tsx b/src-migrate/modules/product-promo/components/Section.tsx
index b6753be7..4e8a7dd5 100644
--- a/src-migrate/modules/product-promo/components/Section.tsx
+++ b/src-migrate/modules/product-promo/components/Section.tsx
@@ -1,31 +1,35 @@
import style from "../styles/section.module.css"
-import React from 'react'
-import { useQuery } from 'react-query'
import { Button, Skeleton } from '@chakra-ui/react'
+import { useQuery } from 'react-query'
-import ProductPromoCard from './Card'
+import SmoothRender from "~/components/ui/smooth-render"
+import clsxm from "~/libs/clsxm"
import { IPromotion } from '~/types/promotion'
-import ProductPromoModal from "./Modal"
import { useModalStore } from "../stores/useModalStore"
-import clsxm from "~/libs/clsxm"
+import ProductPromoCard from './Card'
+import ProductPromoModal from "./Modal"
type Props = {
- productId: number
+ productId: number;
}
const ProductPromoSection = ({ 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 promotionsQuery = useQuery({
+ queryKey: [`promotions.highlight`, productId],
+ queryFn: async () => await fetch(`/api/product-variant/${productId}/promotion/highlight`).then((res) => res.json()) as { data: IPromotion[] }
+ })
const promotions = promotionsQuery.data
const { openModal } = useModalStore()
return (
- <div className='w-full'>
+ <SmoothRender
+ isLoaded={(promotions?.data && promotions?.data.length > 0) || false}
+ height='450px'
+ duration='700ms'
+ >
<ProductPromoModal />
{promotions?.data && promotions?.data.length > 0 && (
@@ -46,11 +50,11 @@ const ProductPromoSection = ({ productId }: Props) => {
>
{promotions?.data.map((promotion) => (
<div key={promotion.id} className="min-w-[400px] max-w-[400px]">
- <ProductPromoCard promotion={promotion} />
+ <ProductPromoCard promotion={promotion} />
</div>
))}
</Skeleton>
- </div>
+ </SmoothRender>
)
}