From c4ff871551cfbf3ed759b3d7be735d7039edb6f5 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 30 Jun 2023 14:58:05 +0700 Subject: cart --- src/lib/cart/components/Cart.jsx | 83 +++++++++++++--------- .../promotinProgram/components/PromotionType.jsx | 1 - 2 files changed, 50 insertions(+), 34 deletions(-) (limited to 'src/lib') diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx index 29bbf080..0cbcacd8 100644 --- a/src/lib/cart/components/Cart.jsx +++ b/src/lib/cart/components/Cart.jsx @@ -4,12 +4,7 @@ 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, - getCartApi, - updateItemCart -} from '@/core/utils/cart' +import { addCart, deleteItemCart, getCartApi, updateItemCart } from '@/core/utils/cart' import { CheckIcon, TrashIcon } from '@heroicons/react/24/outline' import { createSlug } from '@/core/utils/slug' import { useRouter } from 'next/router' @@ -39,12 +34,13 @@ const Cart = () => { if (!auth) return }, [auth]) + const getCart = async () => { + const listCart = await getCartApi() + setCart(listCart) + } + useEffect(() => { - const cart = async () => { - const listCart = await getCartApi() - setCart(listCart) - } - cart() + getCart() }, []) useEffect(() => { @@ -102,16 +98,20 @@ const Cart = () => { }, [products]) useEffect(() => { - if(!promotionActiveId) return - - console.log('bajingan') - updateItemCart({ - productId: variantId, - quantity, - programLineId:promotionActiveId, - selected: true - }) - }, [promotionActiveId, variantId, quantity]) + const updateData = () => { + updateItemCart({ + productId: variantId, + quantity, + programLineId: promotionActiveId, + selected: true + }).then(() => { + getCart().then(() => { + setPromotionType(false) + }) + }) + } + updateData() + }, [promotionActiveId]) useEffect(() => { const LoadProductSimilar = async () => { @@ -416,11 +416,17 @@ const Cart = () => {
- Anda Lebih hamat{' '} - - {' '} - {currencyFormat(product.program.price.priceDiscount)} - + {product.program.type.value == 'merchandise' ? ( + <>Selamat anda mendapatkan merchandise indoteknik.com + ) : ( + <> + Selamat! Pembelian anda lebih hemat + + {' '} + {currencyFormat(product.program.price.priceDiscount)} + + + )}
) : ( @@ -434,7 +440,13 @@ const Cart = () => { )}
handlePopUpPromo(product.id, product.quantity, product.program?.id)} + onClick={() => + handlePopUpPromo( + product.id, + product.quantity, + product.program?.id + ) + } className='ml-auto text-red-500 flex gap-x-1 cursor-pointer' >
Cek Promo
@@ -459,7 +471,10 @@ const Cart = () => { )} - + { />
-
-
- {product.program.type.label} -
-
{product.program.name}
+
+ + {product.program.type.label} + +
+
+ {product.program.name}
diff --git a/src/lib/promotinProgram/components/PromotionType.jsx b/src/lib/promotinProgram/components/PromotionType.jsx index 474e0fc2..0e36d2c1 100644 --- a/src/lib/promotinProgram/components/PromotionType.jsx +++ b/src/lib/promotinProgram/components/PromotionType.jsx @@ -18,7 +18,6 @@ const PromotionType = ({ const [promotionType, setPromotionType] = useState(false) const [promos, setPromotionList] = useState(null) const [activeTitle, setActiveTitle] = useState(null) - console.log('promoactiveid', promotionActiveId) useEffect(() => { const id = variantId -- cgit v1.2.3