From 9272a07644a75d201753501cfff173b1260963ea Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Wed, 5 Jul 2023 09:29:46 +0700 Subject: cart, checkout dan nav bar mobile --- src/core/components/elements/Appbar/Appbar.jsx | 8 ++- .../components/elements/Navbar/NavbarMobile.jsx | 8 ++- src/lib/cart/components/Cart.jsx | 69 +++++++++++++++++++--- src/lib/checkout/components/Checkout.jsx | 10 ++++ src/lib/variant/components/VariantGroupCard.jsx | 40 +++---------- 5 files changed, 91 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/core/components/elements/Appbar/Appbar.jsx b/src/core/components/elements/Appbar/Appbar.jsx index e19d5f0a..16bccbd5 100644 --- a/src/core/components/elements/Appbar/Appbar.jsx +++ b/src/core/components/elements/Appbar/Appbar.jsx @@ -2,7 +2,7 @@ import { useRouter } from 'next/router' import Link from '../Link/Link' import { HomeIcon, Bars3Icon, ShoppingCartIcon, ChevronLeftIcon } from '@heroicons/react/24/outline' import { useEffect, useState } from 'react' -import { getCart } from '@/core/utils/cart' +import { getCart, getCountCart } from '@/core/utils/cart' /** * The AppBar component is a navigation component used to display a header or toolbar @@ -19,7 +19,11 @@ const AppBar = ({ title }) => { useEffect(() => { const handleCartChange = () => { - setCartCount(Object.keys(getCart()).length) + const cart = async () => { + const listCart = await getCountCart() + setCartCount(listCart) + } + cart() } handleCartChange() diff --git a/src/core/components/elements/Navbar/NavbarMobile.jsx b/src/core/components/elements/Navbar/NavbarMobile.jsx index b69e86e8..704e91b6 100644 --- a/src/core/components/elements/Navbar/NavbarMobile.jsx +++ b/src/core/components/elements/Navbar/NavbarMobile.jsx @@ -6,7 +6,7 @@ import useSidebar from '@/core/hooks/useSidebar' import dynamic from 'next/dynamic' import IndoteknikLogo from '@/images/logo.png' import { useEffect, useState } from 'react' -import { getCart } from '@/core/utils/cart' +import { getCart, getCountCart } from '@/core/utils/cart' import TopBanner from './TopBanner' const Search = dynamic(() => import('./Search')) @@ -18,7 +18,11 @@ const NavbarMobile = () => { useEffect(() => { const handleCartChange = () => { - setCartCount(Object.keys(getCart()).length) + const cart = async () => { + const listCart = await getCountCart() + setCartCount(listCart) + } + cart() } handleCartChange() diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx index f1584f98..224d02d1 100644 --- a/src/lib/cart/components/Cart.jsx +++ b/src/lib/cart/components/Cart.jsx @@ -278,18 +278,18 @@ const Cart = () => {
{product.program ? ( <> -
+
{product.program.type.label}
-
+
{product.program.type.value == 'merchandise' ? ( <>Selamat anda mendapatkan merchandise indoteknik.com ) : ( <> - Selamat! Pembelian anda lebih hemat - + Selamat! Pembelian anda hemat + {' '} - {currencyFormat(product.program.price.priceDiscount)} + {currencyFormat(product.program?.totalSavings)} )} @@ -307,9 +307,12 @@ const Cart = () => { onClick={() => handlePopUpPromo(product.id, product.quantity, product.program?.id) } - className='ml-auto text-red-500 flex gap-x-1 cursor-pointer' + className='ml-auto text-red-500 flex gap-x-0 cursor-pointer' > -
Cek Promo
+
+ {' '} + Cek Promo +
)} -
+
+ toggleSelected(product.id)} @@ -414,6 +418,55 @@ const Cart = () => {
+ {product.program && + product.program.items && + product.program.items.map((item) => ( +
+ + + + {item?.name} + +
+ +
+
+ + {product.program.type.label} + +
+
{item.name}
+
+ + {item.price?.discountPercentage > 0 && ( +
+
+ {currencyFormat(item?.price?.price)} +
+
+ )} +
Gratis
+
+
+ ))} ))} diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 0eaab020..b30f7e43 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -270,6 +270,10 @@ const Checkout = () => {
Total Diskon
- {currencyFormat(cartCheckout?.totalDiscount)}
+
+
Total Hemat
+
- {currencyFormat(cartCheckout?.totalSavings)}
+
Subtotal
{currencyFormat(cartCheckout?.subtotal)}
@@ -549,6 +553,12 @@ const Checkout = () => { - {currencyFormat(cartCheckout?.totalDiscount)}
+
+
Total Hemat
+
+ - {currencyFormat(cartCheckout?.totalSavings)} +
+
Subtotal
{currencyFormat(cartCheckout?.subtotal)}
diff --git a/src/lib/variant/components/VariantGroupCard.jsx b/src/lib/variant/components/VariantGroupCard.jsx index aba6971f..dd5983a9 100644 --- a/src/lib/variant/components/VariantGroupCard.jsx +++ b/src/lib/variant/components/VariantGroupCard.jsx @@ -26,49 +26,25 @@ const VariantGroupCard = ({ variants, ...props }) => { />
-

- {item.name} -

-

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

+
+ + {variant.program.type.label} + +
+

{item.name}

Berat Item : {item.weight} Kg

-
+
{item.price.discountPercentage > 0 && ( <>

{currencyFormat(item.price.price)}

- {item.price.discountPercentage}% )}
-

- {item.price.priceDiscount > 0 - ? currencyFormat(item.price.priceDiscount) + - ' × ' + - item.quantity + - ' Barang' - : ''} -

-

- {item.price.priceDiscount > 0 ? ( - currencyFormat(item.quantity * item.price.priceDiscount) - ) : ( - - Call For Price{' '} - - )} -

+

Gratis

-- cgit v1.2.3