diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-11-29 10:37:21 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-11-29 10:37:21 +0700 |
| commit | c996c4e0631aa3d51acc83f4cc23418e91f3158f (patch) | |
| tree | 63d31733edd048ea50780d966ff0a1d5a4fa4866 /src/lib/flashSale/components/FlashSale.jsx | |
| parent | f7a13c357a6d44f9fa6e0c034292ab782249731e (diff) | |
| parent | 37cd18a88f0f104e81c1b6f33f9bab7b2a0b2dfb (diff) | |
Merge branch 'new-release' into CR/website-improvement
Diffstat (limited to 'src/lib/flashSale/components/FlashSale.jsx')
| -rw-r--r-- | src/lib/flashSale/components/FlashSale.jsx | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/lib/flashSale/components/FlashSale.jsx b/src/lib/flashSale/components/FlashSale.jsx index 8be1d7a6..6d90cad7 100644 --- a/src/lib/flashSale/components/FlashSale.jsx +++ b/src/lib/flashSale/components/FlashSale.jsx @@ -2,10 +2,8 @@ import Image from 'next/image'; import { useEffect, useState } from 'react'; import CountDown from '@/core/components/elements/CountDown/CountDown'; -import productSearchApi from '@/lib/product/api/productSearchApi'; import ProductSlider from '@/lib/product/components/ProductSlider'; -import flashSaleApi from '../api/flashSaleApi'; import { FlashSaleSkeleton } from '../skeleton/FlashSaleSkeleton'; const FlashSale = () => { @@ -14,10 +12,14 @@ const FlashSale = () => { useEffect(() => { const loadFlashSales = async () => { - const dataFlashSales = await flashSaleApi(); - setFlashSales(dataFlashSales); + const res = await fetch('/api/flashsale-header'); + const { data } = await res.json(); + if (data) { + setFlashSales(data); + } setIsLoading(false); }; + loadFlashSales(); }, []); @@ -53,7 +55,10 @@ const FlashSale = () => { height={48} className='w-full rounded mb-4 block sm:hidden' /> - <FlashSaleProduct flashSaleId={flashSale.pricelistId} /> + <FlashSaleProduct + flashSaleId={flashSale.pricelistId} + duration={flashSale.duration} + /> </div> </div> ))} @@ -63,19 +68,24 @@ const FlashSale = () => { ); }; -const FlashSaleProduct = ({ flashSaleId }) => { +const FlashSaleProduct = ({ flashSaleId, duration }) => { const [products, setProducts] = useState(null); - useEffect(() => { + const data_search = new URLSearchParams({ + query: `fq=flashsale_id_i:${flashSaleId}&fq=flashsale_price_f:[1 TO *]&limit=500&orderBy=flashsale-price-asc&source=similar`, + operation: 'AND', + duration: `${duration}`, + }); const loadProducts = async () => { - const dataProducts = await productSearchApi({ - query: `fq=flashsale_id_i:${flashSaleId}&fq=flashsale_price_f:[1 TO *]&limit=500&orderBy=flashsale-price-asc&source=similar`, - operation: 'AND', - }); - setProducts(dataProducts.response); + const res = await fetch( + `/api/search-flashsale?${data_search.toString()}` + ); + const { data } = await res.json(); + setProducts(data.response); }; + loadProducts(); - }, [flashSaleId]); + }, []); return <ProductSlider products={products} />; }; |
