From 9aeb019257787b355f7b51f401d7f417899252f5 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 12 Jan 2023 17:12:31 +0700 Subject: form validation, fix cart, fix checkout, create address --- src/pages/shop/cart.js | 239 +++++++++++++++++++++------------------------ src/pages/shop/checkout.js | 9 +- 2 files changed, 113 insertions(+), 135 deletions(-) (limited to 'src/pages/shop') diff --git a/src/pages/shop/cart.js b/src/pages/shop/cart.js index cdb79178..0c6bbdc3 100644 --- a/src/pages/shop/cart.js +++ b/src/pages/shop/cart.js @@ -149,129 +149,6 @@ 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 && } + { !isLoadingProducts && products.length == 0 && ( +
+ +

Keranjang belanja anda masih kosong.

+ Mulai Belanja +
+ ) } { !isLoadingProducts && products.length > 0 && ( <> @@ -298,13 +185,109 @@ export default function Cart() { - +
+ +
+ +
+ Mohon dicek kembali & pastikan pesanan kamu sudah sesuai dengan yang kamu butuhkan. Atau bisa hubungi kami. +
+
- +
+
+

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)}

+
+ +
+ + +
+
) } diff --git a/src/pages/shop/checkout.js b/src/pages/shop/checkout.js index 5eef98e5..54f93c44 100644 --- a/src/pages/shop/checkout.js +++ b/src/pages/shop/checkout.js @@ -30,7 +30,6 @@ export default function Checkout() { const [totalPriceBeforeTax, setTotalPriceBeforeTax] = useState(0); const [totalTaxAmount, setTotalTaxAmount] = useState(0); const [totalDiscountAmount, setTotalDiscountAmount] = useState(0); - const [isLoading, setIsLoading] = useState(true); const [finishCheckout, setFinishCheckout] = useState(null); const payments = [ @@ -106,10 +105,6 @@ export default function Checkout() { } }, [products]); - useEffect(() => { - if (addresses && products) setIsLoading(false); - }, [addresses, products]); - const submit = async () => { if (!selectedPayment) { toast.error('Mohon pilih metode pembayaran terlebih dahulu', { @@ -151,11 +146,11 @@ export default function Checkout() { ) : ( <> - {isLoading && ( + { !products && !addresses && (
- )} + ) } { products && addresses && ( <> -- cgit v1.2.3