From f99e0aba70efad0deb907d8e27f09fc9f527c8a4 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 17 Feb 2023 17:07:50 +0700 Subject: Refactor --- src/pages/shop/quotation/finish.js | 39 ----------- src/pages/shop/quotation/index.js | 140 ------------------------------------- 2 files changed, 179 deletions(-) delete mode 100644 src/pages/shop/quotation/finish.js delete mode 100644 src/pages/shop/quotation/index.js (limited to 'src/pages/shop/quotation') diff --git a/src/pages/shop/quotation/finish.js b/src/pages/shop/quotation/finish.js deleted file mode 100644 index f7983fef..00000000 --- a/src/pages/shop/quotation/finish.js +++ /dev/null @@ -1,39 +0,0 @@ -import WithAuth from "@/components/auth/WithAuth"; -import Link from "@/components/elements/Link"; -import Header from "@/components/layouts/Header"; -import Layout from "@/components/layouts/Layout"; -import { useAuth } from "@/core/utils/auth"; -import { EnvelopeIcon } from "@heroicons/react/24/outline"; -import { useRouter } from "next/router"; - -export default function FinishQuotation() { - const router = useRouter(); - const { id } = router.query; - const [ auth ] = useAuth(); - - return ( - - -
- -
-
- - - -
-

- Terima Kasih { auth?.name } -

-

- Penawaran harga kamu di Indoteknik.com berhasil dikirimkan, tim kami akan segera menghubungi anda. -

- { id && ( - Lihat Penawaran - )} - Ke Halaman Utama -
- - - ); -} \ No newline at end of file diff --git a/src/pages/shop/quotation/index.js b/src/pages/shop/quotation/index.js deleted file mode 100644 index e1c196db..00000000 --- a/src/pages/shop/quotation/index.js +++ /dev/null @@ -1,140 +0,0 @@ -import WithAuth from "@/components/auth/WithAuth"; -import LineDivider from "@/components/elements/LineDivider"; -import Link from "@/components/elements/Link"; -import AppBar from "@/components/layouts/AppBar"; -import Layout from "@/components/layouts/Layout"; -import VariantCard from "@/components/variants/VariantCard"; -import apiOdoo from "@/core/utils/apiOdoo"; -import { useAuth } from "@/core/utils/auth"; -import { deleteItemCart, getCart } from "@/core/utils/cart"; -import currencyFormat from "@/core/utils/currencyFormat"; -import { useRouter } from "next/router"; -import { useEffect, useState } from "react"; -import { toast } from "react-hot-toast"; - -export default function Quotation() { - const router = useRouter(); - const [ auth ] = useAuth(); - const [ products, setProducts ] = useState([]); - const [ totalAmount, setTotalAmount ] = useState(0); - const [ totalDiscountAmount, setTotalDiscountAmount ] = useState(0); - - useEffect(() => { - const getProducts = async () => { - let cart = getCart(); - let productIds = Object - .values(cart) - .filter((itemCart) => itemCart.selected == true) - .map((itemCart) => itemCart.product_id); - if (productIds.length > 0) { - productIds = productIds.join(','); - let dataProducts = await apiOdoo('GET', `/api/v1/product_variant/${productIds}`); - dataProducts = dataProducts.map((product) => ({ - ...product, - quantity: cart[product.id].quantity, - selected: cart[product.id].selected, - })); - setProducts(dataProducts); - } - }; - getProducts(); - }, [ router, auth ]); - - useEffect(() => { - if (products) { - let calculateTotalAmount = 0; - let calculateTotalDiscountAmount = 0; - products.forEach(product => { - calculateTotalAmount += product.price.price * product.quantity; - calculateTotalDiscountAmount += (product.price.price - product.price.price_discount) * product.quantity; - }); - setTotalAmount(calculateTotalAmount); - setTotalDiscountAmount(calculateTotalDiscountAmount); - } - }, [products]); - - const submitQuotation = async () => { - let productOrder = products.map((product) => ({ 'product_id': product.id, 'quantity': product.quantity })); - let data = { - 'partner_shipping_id': auth.partner_id, - 'partner_invoice_id': auth.partner_id, - 'order_line': JSON.stringify(productOrder) - }; - const quotation = await apiOdoo('POST', `/api/v1/partner/${auth.partner_id}/sale_order/checkout`, data); - for (const product of products) { - deleteItemCart(product.id); - } - if (quotation?.id) { - router.push(`/shop/quotation/finish?id=${quotation.id}`); - return; - }; - toast.error('Terdapat kesalahan internal, hubungi kami'); - } - return ( - - - - -
-

Produk

- {products.map((product, index) => ( - - ))} -
- - - -
-
-

Ringkasan Penawaran

-

{products.length} Barang

-
-
-
-
-

Total Belanja

-

{currencyFormat(totalAmount)}

-
-
-

Total Diskon

-

{'- ' + currencyFormat(totalDiscountAmount)}

-
-
-

Subtotal

-

{currencyFormat(totalAmount - totalDiscountAmount)}

-
-
-

PPN 11% (Incl.)

-

{currencyFormat((totalAmount - totalDiscountAmount) * 0.11)}

-
-
-
-
-

Grand Total

-

{currencyFormat(totalAmount - totalDiscountAmount)}

-
-

*) Belum termasuk biaya pengiriman

-

- Dengan melakukan pembelian melalui website Indoteknik, saya menyetujui Syarat & Ketentuan yang berlaku -

-
- - - -
- -
-
-
- ) -} \ No newline at end of file -- cgit v1.2.3