From f15a7f8a4387d215abd1051ee520adca8944fa05 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 28 Mar 2023 16:32:45 +0700 Subject: checkout, quotation --- src/lib/cart/components/Cart.jsx | 2 +- src/lib/checkout/components/Checkout.jsx | 53 +++++++--------------- src/lib/invoice/components/Invoice.jsx | 10 ++-- .../product/components/Product/ProductDesktop.jsx | 18 +++++++- src/lib/product/components/ProductSearch.jsx | 12 ++--- .../components/Skeleton/ProductSearchSkeleton.jsx | 6 ++- src/lib/quotation/components/Quotation.jsx | 37 ++++++++++----- src/lib/transaction/components/Transaction.jsx | 14 +++--- 8 files changed, 79 insertions(+), 73 deletions(-) (limited to 'src/lib') diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx index 7ebee14b..8d995103 100644 --- a/src/lib/cart/components/Cart.jsx +++ b/src/lib/cart/components/Cart.jsx @@ -115,7 +115,7 @@ const Cart = () => { const selectedProduct = () => { if (!products) return [] - return products?.filter((product) => product.selected == true) + return products?.filter((product) => product?.selected == true) } const deleteProduct = (productId) => { diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 048bb24e..ffb33eb7 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -78,7 +78,7 @@ const Checkout = () => { } const dataProducts = await CartApi({ variantIds }) - const productsWithQuantity = dataProducts.map(async (product) => { + const productsWithQuantity = dataProducts?.map(async (product) => { const productPrice = await variantPriceApi({ id: product.id }) return { ...product, @@ -87,12 +87,16 @@ const Checkout = () => { discountPercentage: productPrice.discount, priceDiscount: productPrice.priceExcludeAfterDiscount }, - quantity: query.quantity ? query.quantity : getItemCart({ productId: product.id }).quantity + quantity: query.quantity + ? query.quantity + : getItemCart({ productId: product.id }).quantity } }) - Promise.all(productsWithQuantity).then((resolvedProducts) => { - setProducts(resolvedProducts) - }) + if (productsWithQuantity) { + Promise.all(productsWithQuantity).then((resolvedProducts) => { + setProducts(resolvedProducts) + }) + } } loadProducts() }, [router]) @@ -150,6 +154,8 @@ const Checkout = () => { window.location.href = payment.data.redirectUrl } + const taxTotal = (totalAmount - totalDiscountAmount) * 0.11 + return ( <> @@ -202,14 +208,14 @@ const Checkout = () => {
PPN 11% (Incl.)
-
{currencyFormat((totalAmount - totalDiscountAmount) * 0.11)}
+
{currencyFormat(taxTotal)}

Grand Total
- {currencyFormat(totalAmount - totalDiscountAmount)} + {currencyFormat(totalAmount - totalDiscountAmount + taxTotal)}

*) Belum termasuk biaya pengiriman

@@ -232,31 +238,6 @@ const Checkout = () => { -
-
Metode Pembayaran
-
-
setPaymentMethod('manual')} - > - Bank BCA (PT. Indoteknik Dotcom) -
8870-4000-81
-
-
setPaymentMethod('midtrans')} - > - Midtrans Payment -
-
-
- - -
Purchase Order
@@ -286,7 +267,7 @@ const Checkout = () => { onClick={checkout} disabled={isLoading || !products || products?.length == 0} > - {isLoading ? 'Loading...' : 'Bayar'} + {isLoading ? 'Loading...' : 'Lanjut Pembayaran'}
@@ -402,8 +383,8 @@ const Checkout = () => {
{currencyFormat(totalAmount - totalDiscountAmount)}
-
PPN 11% (Incl.)
-
{currencyFormat((totalAmount - totalDiscountAmount) * 0.11)}
+
PPN 11%
+
{currencyFormat(taxTotal)}
@@ -412,7 +393,7 @@ const Checkout = () => {
Grand Total
- {currencyFormat(totalAmount - totalDiscountAmount)} + {currencyFormat(totalAmount - totalDiscountAmount + taxTotal)}

diff --git a/src/lib/invoice/components/Invoice.jsx b/src/lib/invoice/components/Invoice.jsx index 211d1ae1..6012e4ea 100644 --- a/src/lib/invoice/components/Invoice.jsx +++ b/src/lib/invoice/components/Invoice.jsx @@ -152,9 +152,7 @@ const Invoice = ({ id }) => {

: {invoice?.data?.invoiceDate}
Purchase Order
-
- : {invoice?.data?.purchaseOrderName || '-'} -
+
: {invoice?.data?.purchaseOrderName || '-'}
Ketentuan Pembayaran
: {invoice?.data?.paymentTerm}
@@ -252,13 +250,13 @@ const Invoice = ({ id }) => { {currencyFormat(-totalDiscountAmount)} -
PPN 11% (Incl.)
-
{currencyFormat(totalAmount * 0.11)}
-
Grand Total
{currencyFormat(invoice.data?.amountTotal)}
+ +
PPN 11% (Incl.)
+
{currencyFormat(totalAmount * 0.11)}
diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx index 2f73d124..79e7bb45 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -11,8 +11,10 @@ import { updateItemCart } from '@/core/utils/cart' import useVariantPrice from '@/lib/variant/hooks/useVariantPrice' import useProductPrice from '../../hooks/useProductPrice' import PriceSkeleton from '@/core/components/elements/Skeleton/PriceSkeleton' +import { useRouter } from 'next/router' const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { + const router = useRouter() const { productPrice } = useProductPrice({ id: product.id }) const [informationTab, setInformationTab] = useState(informationTabOptions[0].value) @@ -41,6 +43,12 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { toast.success('Berhasil menambahkan ke keranjang') } + const handleBuy = (variantId) => { + const quantity = variantQuantityRefs.current[variantId].value + if (!validQuantity(quantity)) return + router.push(`/shop/checkout?productId=${variantId}&quantity=${quantity}`) + } + const variantSectionRef = useRef(null) const goToVariantSection = () => { if (variantSectionRef.current) { @@ -193,7 +201,11 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { > Keranjang - @@ -264,7 +276,9 @@ const VariantPrice = ({ id }) => { {variantPrice?.data?.priceExcludeAfterDiscount > 0 ? ( currencyFormat(variantPrice?.data?.priceExcludeAfterDiscount) ) : ( - Call for price + + Call for price + )} ) diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx index b5d7c974..b00d68a4 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -41,11 +41,6 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => { } ) - const [open, setOpen] = useState(1) - - const handleOpen = (value) => { - setOpen(open === value ? 0 : value) - } const orderOptions = [ { value: 'price-asc', label: 'Harga Terendah' }, { value: 'price-desc', label: 'Harga Tertinggi' }, @@ -69,13 +64,10 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => { } }, [query, products, productSearch]) - if (productSearch.isLoading) { - return - } - return ( <> + {productSearch.isLoading && }

Produk

@@ -178,6 +170,7 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {