From 3770bcca65e85af7273a3f565b3ca616f852e936 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 10 Jan 2023 05:38:03 +0700 Subject: optimize cart code --- src/pages/shop/cart.js | 246 ++++++++++++++++++++++++++----------------------- 1 file changed, 130 insertions(+), 116 deletions(-) (limited to 'src') diff --git a/src/pages/shop/cart.js b/src/pages/shop/cart.js index e480d117..cdb79178 100644 --- a/src/pages/shop/cart.js +++ b/src/pages/shop/cart.js @@ -42,7 +42,6 @@ export default function Cart() { show: false }); - useEffect(() => { const getProducts = async () => { let cart = getCart(); @@ -150,6 +149,129 @@ export default function Cart() { setProducts([...productsToUpdate]); } + // Components + const CartEmpty = () => ( +
+ +

Keranjang belanja anda masih kosong.

+ Mulai Belanja +
+ ); + + const CartLoader = () => ( +
+ +
+ ); + + const CartWarningAlert = () => { +
+ +
+ +
+ Mohon dicek kembali & pastikan pesanan kamu sudah sesuai dengan yang kamu butuhkan. Atau bisa hubungi kami. +
+
+ }; + + const CartProductList = () => ( +
+
+

Daftar Produk Belanja

+ Cari Produk Lain +
+ {products.map((product, index) => ( +
+
toggleProductSelected(product.id)}> + + {product.parent.name} +
+
+ + {product.parent.name} + +

+ {product.code || '-'} + {product.attributes.length > 0 ? ` | ${product.attributes.join(', ')}` : ''} +

+
+

{currencyFormat(product.price.price_discount)}

+ {product.price.discount_percentage > 0 && ( + <> + {product.price.discount_percentage}% +

{currencyFormat(product.price.price)}

+ + )} +
+
+

{currencyFormat(product.quantity * product.price.price_discount)}

+
+ + + blurQuantity(product.id, e.target.value)} + onChange={(e) => updateQuantity(product.id, e.target.value)} + value={product.quantity} + /> + +
+
+
+
+ ))} +
+ ); + + const ActionButton = () => ( +
+
+

Total

+

{getProductsSelected().length > 0 && ( + <>({ getProductsSelected().length } Barang) + )}

+

{currencyFormat(totalPriceBeforeTax + totalTaxAmount - totalDiscountAmount)}

+
+ +
+ + +
+
+ ); + return ( <> - {isLoadingProducts && ( -
- -
- )} + {isLoadingProducts && } - { !isLoadingProducts && products.length == 0 && ( -
- -

Keranjang belanja anda masih kosong.

- Mulai Belanja -
- ) } + { !isLoadingProducts && products.length == 0 && } { !isLoadingProducts && products.length > 0 && ( <> @@ -184,113 +296,15 @@ export default function Cart() { labels={['Keranjang', 'Pembayaran', 'Selesai']} /> - + - {/* --- Start Alert */} -
- -
- -
- Mohon dicek kembali & pastikan pesanan kamu sudah sesuai dengan yang kamu butuhkan. Atau bisa hubungi kami. -
-
- {/* ---- End Alert */} + - + -
-
-

Daftar Produk Belanja

- Cari Produk Lain -
- {products.map((product, index) => ( -
-
toggleProductSelected(product.id)}> - - {product.parent.name} -
-
- - {product.parent.name} - -

- {product.code || '-'} - {product.attributes.length > 0 ? ` | ${product.attributes.join(', ')}` : ''} -

-
-

{currencyFormat(product.price.price_discount)}

- {product.price.discount_percentage > 0 && ( - <> - {product.price.discount_percentage}% -

{currencyFormat(product.price.price)}

- - )} -
-
-

{currencyFormat(product.quantity * product.price.price_discount)}

-
- - - blurQuantity(product.id, e.target.value)} - onChange={(e) => updateQuantity(product.id, e.target.value)} - value={product.quantity} - /> - -
-
-
-
- ))} -
+ -
-
-

Total

-

{getProductsSelected().length > 0 && ( - <>({ getProductsSelected().length } Barang) - )}

-

{currencyFormat(totalPriceBeforeTax + totalTaxAmount - totalDiscountAmount)}

-
- -
- - -
-
+ ) } -- cgit v1.2.3