From ec9e0f90c3d8111d77cc4bfc3c5f56f473428786 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 29 Dec 2022 11:34:04 +0700 Subject: no message --- src/pages/shop/cart.js | 35 +++++++++---------- src/pages/shop/checkout.js | 85 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/pages/shop/cart.js b/src/pages/shop/cart.js index 9fd44410..6fe079b3 100644 --- a/src/pages/shop/cart.js +++ b/src/pages/shop/cart.js @@ -4,6 +4,7 @@ import { TrashIcon, PlusIcon, MinusIcon, + ExclamationCircleIcon, } from "@heroicons/react/24/solid"; import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; import { useRouter } from "next/router"; @@ -41,23 +42,23 @@ export default function Cart() { show: false }); - const getProducts = async () => { - let cart = getCart(); - let productIds = Object.keys(cart); - 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, - to_process: cart[product.id].to_process, - })); - setProducts(dataProducts); - } - setIsLoadingProducts(false); - } - + useEffect(() => { + const getProducts = async () => { + let cart = getCart(); + let productIds = Object.keys(cart); + 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, + to_process: cart[product.id].to_process, + })); + setProducts(dataProducts); + } + setIsLoadingProducts(false); + } getProducts(); }, []); @@ -188,7 +189,7 @@ export default function Cart() { {/* --- Start Alert */}
- +
Mohon dicek kembali & pastikan pesanan kamu sudah sesuai dengan yang kamu butuhkan. Atau bisa hubungi kami.
diff --git a/src/pages/shop/checkout.js b/src/pages/shop/checkout.js index 48cbc10e..b1704cbc 100644 --- a/src/pages/shop/checkout.js +++ b/src/pages/shop/checkout.js @@ -1,9 +1,57 @@ +import { ExclamationCircleIcon } from "@heroicons/react/24/solid"; +import { useEffect, useState } from "react"; +import Alert from "../../components/Alert"; import AppBar from "../../components/AppBar"; import Layout from "../../components/Layout"; +import LineDivider from "../../components/LineDivider"; +import Link from "../../components/Link"; import ProgressBar from "../../components/ProgressBar"; +import apiOdoo from "../../helpers/apiOdoo"; +import { useAuth } from "../../helpers/auth"; +import { getCart } from "../../helpers/cart"; export default function Checkout() { + const [auth, setAuth] = useAuth(); + const [address, setAddress] = useState(null); + const [selectedAddress, setSelectedAddress] = useState(null); + const [products, setProducts] = useState(null); + + useEffect(() => { + const getAddress = async () => { + if (auth?.id) { + const dataAddress = await apiOdoo('GET', `/api/v1/user/${auth.id}/address`); + setAddress(dataAddress); + } + }; + getAddress(); + }, [auth]); + + useEffect(() => { + const getProducts = async () => { + let cart = getCart(); + let productIds = Object + .values(cart) + .filter((itemCart) => itemCart.to_process == 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, + to_process: cart[product.id].to_process, + })); + setProducts(dataProducts); + } + }; + getProducts(); + }, []); + + useEffect(() => { + if (address) setSelectedAddress(address[0]); + }, [address]); + return ( @@ -12,6 +60,41 @@ export default function Checkout() { current={2} labels={['Keranjang', 'Pembayaran', 'Selesai']} /> + + + + +
+ +
+ Jika mengalami kesulitan dalam melakukan pembelian di website Indoteknik. Hubungi kami disini +
+ + + +
+
+

Alamat Pengiriman

+ Ubah Alamat +
+ + { selectedAddress && ( +
+

{ selectedAddress.name }

+

{ selectedAddress.mobile }

+

{ selectedAddress.street } { selectedAddress.street2 }

+
+ ) } +
+ +
) -} \ No newline at end of file +} +// odoo = 1677721600 +// from = 3026531840 +// to = 3355443200 + +// odoo = 629145600 +// from = 2355443200 +// to = 1258291200 \ No newline at end of file -- cgit v1.2.3