diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2025-01-22 10:10:19 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2025-01-22 10:10:19 +0700 |
| commit | 5cc3c938da3dfde636b918b8f2fdef33f3c61419 (patch) | |
| tree | 222177fe6dce70fc608698c700de17032105998a /src/lib/flashSale | |
| parent | 238c675eecaf6f4f953d87c4b0a128bfa139cff4 (diff) | |
| parent | 6d9c1067b6e857eb95f12864cc88117350ae6cfb (diff) | |
Merge branch 'new-release' into CR/form-merchant
# Conflicts:
# src/lib/form/components/Merchant.jsx
Diffstat (limited to 'src/lib/flashSale')
| -rw-r--r-- | src/lib/flashSale/components/FlashSale.jsx | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/lib/flashSale/components/FlashSale.jsx b/src/lib/flashSale/components/FlashSale.jsx index f4be279e..9c0e713b 100644 --- a/src/lib/flashSale/components/FlashSale.jsx +++ b/src/lib/flashSale/components/FlashSale.jsx @@ -9,13 +9,23 @@ import { FlashSaleSkeleton } from '../skeleton/FlashSaleSkeleton'; const FlashSale = () => { const [flashSales, setFlashSales] = useState(null); const [isLoading, setIsLoading] = useState(true); + const [duration, setDuration] = useState(); + const calculateRemainingTime = (endDate) => { + const currentTime = new Date(); + const endTime = new Date(endDate); + const remainingTimeInSeconds = (endTime - currentTime) / 1000; + + return Math.max(Math.round(remainingTimeInSeconds), 0); + }; useEffect(() => { const loadFlashSales = async () => { const res = await fetch('/api/flashsale-header'); const { data } = await res.json(); if (data) { setFlashSales(data); + const remainingTime = calculateRemainingTime(data[0]?.endDate); + setDuration(remainingTime); } setIsLoading(false); }; @@ -37,7 +47,7 @@ const FlashSale = () => { <div className='font-medium sm:text-h-lg mt-1.5'> {flashSale.name} </div> - <CountDown initialTime={flashSale.duration} /> + <CountDown initialTime={duration} /> </div> <div className='relative'> @@ -59,7 +69,7 @@ const FlashSale = () => { /> <FlashSaleProduct flashSaleId={flashSale.pricelistId} - duration={flashSale.duration} + duration={duration} /> </div> </div> |
