summaryrefslogtreecommitdiff
path: root/src-migrate/modules/product-promo/components/Section.tsx
diff options
context:
space:
mode:
authortrisusilo48 <tri.susilo@altama.co.id>2024-07-10 15:58:51 +0700
committertrisusilo48 <tri.susilo@altama.co.id>2024-07-10 15:58:51 +0700
commit2e3c726bc8217f3960cfecec44b81303b03de72b (patch)
tree1b85ced7f61f3e4c3f1f27b577b37aa161615065 /src-migrate/modules/product-promo/components/Section.tsx
parent2b3bd9c0a454dbad69ce29cee877bfb1fca5dfa6 (diff)
parenta99bf6480eea556e53b85e6db45f3b8c2361e693 (diff)
Merge branch 'release' into development
# Conflicts: # src/pages/shop/product/variant/[slug].jsx
Diffstat (limited to 'src-migrate/modules/product-promo/components/Section.tsx')
-rw-r--r--src-migrate/modules/product-promo/components/Section.tsx61
1 files changed, 61 insertions, 0 deletions
diff --git a/src-migrate/modules/product-promo/components/Section.tsx b/src-migrate/modules/product-promo/components/Section.tsx
new file mode 100644
index 00000000..4e8a7dd5
--- /dev/null
+++ b/src-migrate/modules/product-promo/components/Section.tsx
@@ -0,0 +1,61 @@
+import style from "../styles/section.module.css"
+
+import { Button, Skeleton } from '@chakra-ui/react'
+import { useQuery } from 'react-query'
+
+import SmoothRender from "~/components/ui/smooth-render"
+import clsxm from "~/libs/clsxm"
+import { IPromotion } from '~/types/promotion'
+import { useModalStore } from "../stores/useModalStore"
+import ProductPromoCard from './Card'
+import ProductPromoModal from "./Modal"
+
+type Props = {
+ productId: number;
+}
+
+const ProductPromoSection = ({ productId }: Props) => {
+ 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 (
+ <SmoothRender
+ isLoaded={(promotions?.data && promotions?.data.length > 0) || false}
+ height='450px'
+ duration='700ms'
+ >
+ <ProductPromoModal />
+
+ {promotions?.data && promotions?.data.length > 0 && (
+ <div className={style.titleWrapper}>
+ <span className={style.title}>Promo Tersedia</span>
+ <Button colorScheme="yellow" type='button' onClick={() => openModal(productId)}>
+ Lihat Semua
+ </Button>
+ </div>
+ )}
+
+ <Skeleton
+ isLoaded={promotionsQuery.isSuccess}
+ className={clsxm(
+ "flex gap-x-4 overflow-x-auto px-4 md:px-0", {
+ "min-h-[340px]": promotions?.data && promotions?.data.length > 0
+ })}
+ >
+ {promotions?.data.map((promotion) => (
+ <div key={promotion.id} className="min-w-[400px] max-w-[400px]">
+ <ProductPromoCard promotion={promotion} />
+ </div>
+ ))}
+ </Skeleton>
+ </SmoothRender>
+ )
+}
+
+export default ProductPromoSection \ No newline at end of file