summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-08-23 14:04:44 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-08-23 14:04:44 +0700
commit500c6cf822114a82ca90c70b212e2f969f4d30da (patch)
tree941b8d53b8dc024166878c1eec6b3e56c73a348e
parent56be886ad93b2bb8bc82fbd14410b3a85662c1d6 (diff)
<iman> add ready stock
-rw-r--r--src/api/productApi.js5
-rw-r--r--src/components/ui/PopularProduct.jsx23
2 files changed, 24 insertions, 4 deletions
diff --git a/src/api/productApi.js b/src/api/productApi.js
index 009d95ef..4a29b59d 100644
--- a/src/api/productApi.js
+++ b/src/api/productApi.js
@@ -2,8 +2,11 @@ import axios from 'axios'
export const popularProductApi = () => {
return async () => {
+ const today = new Date();
+ const dayOfYear = Math.floor((today - new Date(today.getFullYear(), 0, 0)) / 86400000);
+ const page = (dayOfYear % 24) + 1;
const dataPopularProducts = await axios(
- `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?q=*&page=1&orderBy=popular-weekly&priceFrom=1`
+ `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?q=*&page=${page}&orderBy=stock&priceFrom=1`
)
return dataPopularProducts.data.response
}
diff --git a/src/components/ui/PopularProduct.jsx b/src/components/ui/PopularProduct.jsx
index bbbd18bc..92b2a1b6 100644
--- a/src/components/ui/PopularProduct.jsx
+++ b/src/components/ui/PopularProduct.jsx
@@ -5,6 +5,7 @@ import { useQuery } from 'react-query'
import { PopularProductSkeleton } from '../skeleton/PopularProductSkeleton'
import DesktopView from '@/core/components/views/DesktopView'
import ProductCard from '@/lib/product/components/ProductCard'
+import Link from '@/core/components/elements/Link/Link'
const PopularProduct = () => {
const popularProduct = useQuery('popularProduct', popularProductApi())
@@ -16,15 +17,31 @@ const PopularProduct = () => {
<>
<MobileView>
<div className='px-4'>
- <div className='font-semibold mb-4'>Produk Banyak Dilihat</div>
+ <div className='font-semibold mb-4 flex justify-between items-center'><p>
+ Produk Ready Stock
+ </p>
+ <Link
+ href='/shop/search?orderBy=stock'
+ className=''
+ >
+ <p className='text-danger-500 font-semibold'>Lihat Semua</p>
+ </Link></div>
<ProductSlider products={popularProduct.data} simpleTitle />
</div>
</MobileView>
<DesktopView>
<div className='border border-gray_r-6 h-full overflow-auto'>
- <div className='font-semibold text-center p-4 bg-gray_r-1 border-b border-gray_r-6 sticky top-0 z-10'>
- Produk Banyak Dilihat
+ <div className='font-semibold text-center p-4 bg-gray_r-1 border-b border-gray_r-6 sticky top-0 z-10 flex justify-between items-center'>
+ <p>
+ Produk Ready Stock
+ </p>
+ <Link
+ href='/shop/search?orderBy=stock'
+ className=''
+ >
+ <p className='text-danger-500 font-semibold'>Lihat Semua</p>
+ </Link>
</div>
<div className='h-full divide-y divide-gray_r-6'>
{popularProduct.data &&