summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHATEC\SPVDEV001 <tri.susilo@altama.co.id>2023-08-04 10:23:11 +0700
committerHATEC\SPVDEV001 <tri.susilo@altama.co.id>2023-08-04 10:23:11 +0700
commit9010695979e4fb39a021901fa8b2b0be9efd3c77 (patch)
tree59ccde34be41f0ffdc8ce89eaf03f5e89037cee2 /src
parent510ead4e768e35d4130eed1ef7ea85fbf91e2e9c (diff)
parent47d81f5b23a96611db07f92203d03fc761a68db9 (diff)
Merge branch 'master' into CR/flash_sale
Diffstat (limited to 'src')
-rw-r--r--src/api/productApi.js2
-rw-r--r--src/lib/product/components/Product/ProductDesktop.jsx16
2 files changed, 14 insertions, 4 deletions
diff --git a/src/api/productApi.js b/src/api/productApi.js
index feb91257..009d95ef 100644
--- a/src/api/productApi.js
+++ b/src/api/productApi.js
@@ -3,7 +3,7 @@ import axios from 'axios'
export const popularProductApi = () => {
return async () => {
const dataPopularProducts = await axios(
- `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?q=*&page=1&orderBy=popular-weekly`
+ `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?q=*&page=1&orderBy=popular-weekly&priceFrom=1`
)
return dataPopularProducts.data.response
}
diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index 123ee708..f6c998e2 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -57,9 +57,10 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
const setVariantQuantityRef = (variantId) => (element) => {
if (element) {
let variantIndex = product.variants.findIndex((varian) => varian.id == variantId)
- product.variants[variantIndex].quantity = element.value
+ product.variants[variantIndex].quantity = element?.value
}
variantQuantityRefs.current[variantId] = element
+
}
const validQuantity = (quantity) => {
@@ -109,6 +110,15 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
setAddCartAlert(true)
}
+ const handleQuantityChange = (variantId) => (event) => {
+ const { value } = event.target;
+ const variantIndex = product.variants.findIndex((variant) => variant.id === variantId);
+ if (variantIndex !== -1) {
+ product.variants[variantIndex].quantity = parseInt(value, 10); // Pastikan untuk mengubah ke tipe number jika diperlukan
+ // Lakukan sesuatu jika nilai quantity diubah
+ }
+ };
+
const handleBuy = (variant) => {
const quantity = variantQuantityRefs.current[variant].value
if (!validQuantity(quantity)) return
@@ -456,7 +466,7 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
type='number'
className='form-input w-16 py-2 text-center bg-gray_r-1'
ref={setVariantQuantityRef(product.variants[0].id)}
- onChange={setVariantQuantityRef(product.variants[0].id)}
+ onChange={handleQuantityChange(product.variants[0].id)}
defaultValue={1}
/>
<button
@@ -623,7 +633,7 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
type='number'
className='form-input w-16 py-2 text-center bg-gray_r-1'
ref={setVariantQuantityRef(variant.id)}
- onChange={setVariantQuantityRef(variant.id)}
+ onChange={handleQuantityChange(variant.id)}
defaultValue={1}
/>
</td>