From 03adcb9bff8cb4a2ffcb442f6e8f787ea205feb4 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 19 Dec 2022 17:13:41 +0700 Subject: loading not stop when cart is empty, fix input quantity --- src/components/Layout.js | 2 +- src/pages/shop/cart.js | 6 +++++- src/pages/shop/product/[slug].js | 14 ++++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/components/Layout.js b/src/components/Layout.js index 03b9aa59..fb7748d1 100644 --- a/src/components/Layout.js +++ b/src/components/Layout.js @@ -10,7 +10,7 @@ export default function Layout({ children, ...pageProps }) { diff --git a/src/pages/shop/cart.js b/src/pages/shop/cart.js index 90059d9a..4c954960 100644 --- a/src/pages/shop/cart.js +++ b/src/pages/shop/cart.js @@ -60,8 +60,8 @@ export default function Cart({ previousRoute }) { to_process: false })); setProducts(dataProducts); - setIsLoadingProducts(false); } + setIsLoadingProducts(false); } useEffect(() => { @@ -98,6 +98,10 @@ export default function Cart({ previousRoute }) { const blurQuantity = (productId, quantity) => { quantity = quantity == ('' || 0) ? 1 : parseInt(quantity); + if (typeof quantity === 'number') { + quantity = parseInt(quantity); + quantity = Math.floor(quantity); + } updateCart(productId, quantity); }; diff --git a/src/pages/shop/product/[slug].js b/src/pages/shop/product/[slug].js index b8d29d02..7ce55562 100644 --- a/src/pages/shop/product/[slug].js +++ b/src/pages/shop/product/[slug].js @@ -77,12 +77,18 @@ export default function ProductDetail({ product }) { } }, [selectedVariant, product]); - let onchangeVariant = (e) => { + const onchangeVariant = (e) => { setSelectedVariant(e.target.value); - setQuantity("1"); } - let addItemToCart = () => { + const onChangeQuantity = (e) => { + let inputValue = e.target.value; + inputValue = parseInt(inputValue); + inputValue = Math.floor(inputValue); + setQuantity(inputValue); + } + + const addItemToCart = () => { if (product.variant_total > 1 && !selectedVariant) { toast.error('Pilih varian terlebih dahulu untuk menambahkan ke keranjang', { duration: 2000 }); return false; @@ -148,7 +154,7 @@ export default function ProductDetail({ product }) {
- setQuantity(e.target.value)} /> +
-- cgit v1.2.3