diff options
| author | Rafi Zadanly <rafizadanly@gmail.com> | 2022-12-19 17:13:41 +0700 |
|---|---|---|
| committer | Rafi Zadanly <rafizadanly@gmail.com> | 2022-12-19 17:13:41 +0700 |
| commit | 03adcb9bff8cb4a2ffcb442f6e8f787ea205feb4 (patch) | |
| tree | 72d469c10a24c9797099581e186921c8cca2955b /src | |
| parent | b17c4ea8bea0b57a2defbfcf327176a874ec1aed (diff) | |
loading not stop when cart is empty, fix input quantity
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/Layout.js | 2 | ||||
| -rw-r--r-- | src/pages/shop/cart.js | 6 | ||||
| -rw-r--r-- | src/pages/shop/product/[slug].js | 14 |
3 files changed, 16 insertions, 6 deletions
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 }) { <motion.main initial={{ opacity: 0, x: 50, y: 0 }} animate={{ opacity: 1, x: 0, y: 0 }} - exit={{ opacity: 0, x: -100, y: 0 }} + exit={{ opacity: 0, x: 50, y: 0 }} transition={transition} {...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 }) { </div> <div className="w-3/12"> <label htmlFor="quantity" className="form-label mb-1">Jumlah</label> - <input type="number" name="quantity" id="quantity" className="form-input text-center is-invalid" value={quantity} onChange={(e) => setQuantity(e.target.value)} /> + <input type="number" name="quantity" id="quantity" className="form-input text-center is-invalid" value={quantity} onChange={onChangeQuantity} /> </div> </div> |
