From d2ac3371d30464801924539350ddb50eb42eb007 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Wed, 21 Jun 2023 13:19:30 +0700 Subject: handling cart --- src/lib/cart/components/Cart.jsx | 29 ++++++++++------- .../promotinProgram/components/PromotionType.jsx | 37 ++++++++++++++++++---- 2 files changed, 48 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx index 31aa034d..a9113e75 100644 --- a/src/lib/cart/components/Cart.jsx +++ b/src/lib/cart/components/Cart.jsx @@ -4,7 +4,15 @@ import Image from '@/core/components/elements/Image/Image' import NextImage from 'next/image' import currencyFormat from '@/core/utils/currencyFormat' import { useEffect, useState } from 'react' -import { addCart, deleteItemCart, getCart, getCartApi, getCartnew, getItemCart, updateItemCart } from '@/core/utils/cart' +import { + addCart, + deleteItemCart, + getCart, + getCartApi, + getCartnew, + getItemCart, + updateItemCart +} from '@/core/utils/cart' import { CheckIcon, TrashIcon } from '@heroicons/react/24/outline' import { createSlug } from '@/core/utils/slug' import { useRouter } from 'next/router' @@ -18,6 +26,7 @@ import ProductCard from '@/lib/product/components/ProductCard' import productSearchApi from '@/lib/product/api/productSearchApi' import whatsappUrl from '@/core/utils/whatsappUrl' import useAuth from '@/core/hooks/useAuth' +import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner' const Cart = () => { const router = useRouter() @@ -25,8 +34,7 @@ const Cart = () => { const [isLoading, setIsLoading] = useState(true) const auth = useAuth() - - const [cart, setCart] = useState(null) + const [cart, setCart] = useState(null) useEffect(() => { if (!auth) return @@ -38,16 +46,15 @@ const Cart = () => { setCart(listCart) } cart() - }) + },[]) useEffect(() => { - if(cart){ + if (cart) { setProducts(cart.products) setIsLoading(false) } }, [cart]) - const [totalPriceBeforeTax, setTotalPriceBeforeTax] = useState(0) const [totalTaxAmount, setTotalTaxAmount] = useState(0) const [totalDiscountAmount, setTotalDiscountAmount] = useState(0) @@ -56,7 +63,6 @@ const Cart = () => { const [productRecomendation, setProductRecomendation] = useState(null) - useEffect(() => { if (!products) return @@ -116,7 +122,7 @@ const Cart = () => { } let qty = quantity productsToUpdate[productIndex].quantity = qty - + setProducts([...productsToUpdate]) addCart(productId, qty, productsToUpdate[productIndex].selected) } @@ -128,8 +134,7 @@ const Cart = () => { let productsToUpdate = products let isSelected = !productsToUpdate[productIndex].selected productsToUpdate[productIndex].selected = isSelected - - + setProducts([...productsToUpdate]) addCart(productId, productsToUpdate[productIndex].quantity, isSelected) } @@ -332,8 +337,8 @@ const Cart = () => { {isLoading && ( -
- +
+
diff --git a/src/lib/promotinProgram/components/PromotionType.jsx b/src/lib/promotinProgram/components/PromotionType.jsx index a6382cb1..8c31cf0d 100644 --- a/src/lib/promotinProgram/components/PromotionType.jsx +++ b/src/lib/promotinProgram/components/PromotionType.jsx @@ -46,6 +46,20 @@ const PromotionType = ({ isModal = false }) => { image: '/path/to/image2.jpg', type: 'Promo Bundling' }, + { + id: 7, + title: 'Promo 5', + description: 'Deskripsi Promo 2', + image: '/path/to/image2.jpg', + type: 'Promo Bundling' + }, + { + id: 8, + title: 'Promo 5', + description: 'Deskripsi Promo 2', + image: '/path/to/image2.jpg', + type: 'Promo Bundling' + }, { id: 6, title: 'Promo 6', @@ -76,12 +90,12 @@ const PromotionType = ({ isModal = false }) => { } const handlePopUp = () => { - if(isModal == false){ + if (isModal == false) { setPromotionType(true) } } return ( -
+
@@ -144,9 +158,15 @@ const PromotionType = ({ isModal = false }) => {

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ut nibh at arcu - commodo auctor. Maecenas efficitur, ipsum sed mollis fermentum, nulla sem ada lah ini ditu kamu dia merek + commodo auctor. Maecenas efficitur, ipsum sed mollis fermentum, nulla sem + ada lah ini ditu kamu dia merek

-
Rp. 999.000
+
+
Rp. 999.000
+
+
+999 Produk Terjual
+
+
@@ -157,7 +177,7 @@ const PromotionType = ({ isModal = false }) => { if (index > 2) { return null } else { - if (index === 2) { + if (index === 2 && promos.length > 2) { return ( <>
{
{promo.title}
-

Lorem ipsum dolor sit amet, consectetur ...

+

+ Lorem ipsum dolor sit amet, consectetur ... +

999900
+
+
+
-- cgit v1.2.3