summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/cart/components/Cart.jsx83
-rw-r--r--src/lib/promotinProgram/components/PromotionType.jsx1
2 files changed, 50 insertions, 34 deletions
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 = () => {
</span>
</div>
<div className='flex'>
- Anda Lebih hamat{' '}
- <span className='text-red-600 font-semibold ml-2'>
- {' '}
- {currencyFormat(product.program.price.priceDiscount)}
- </span>
+ {product.program.type.value == 'merchandise' ? (
+ <>Selamat anda mendapatkan merchandise indoteknik.com</>
+ ) : (
+ <>
+ Selamat! Pembelian anda lebih hemat
+ <span className='text-red-600 font-semibold ml-2'>
+ {' '}
+ {currencyFormat(product.program.price.priceDiscount)}
+ </span>
+ </>
+ )}
</div>
</>
) : (
@@ -434,7 +440,13 @@ const Cart = () => {
</>
)}
<div
- onClick={() => 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'
>
<div className='font-semibold'> Cek Promo</div>
@@ -459,7 +471,10 @@ const Cart = () => {
</td>
</tr>
)}
- <tr key={product.id} className='!border-t-0'>
+ <tr
+ key={product.id}
+ className={`${product.isPromo ? '!border-t-0 !border-b-0' : ''}`}
+ >
<td>
<input
type='checkbox'
@@ -554,11 +569,13 @@ const Cart = () => {
/>
</div>
<div className='px-2 text-left'>
- <div className='line-clamp-2 leading-6 !text-gray_r-12 font-normal'>
- <div className='flex border border-solid border-red-600 rounded-md p-1'>
- <span className='text-red-600'>{product.program.type.label}</span>
- </div>
- <div className='mt-2'>{product.program.name}</div>
+ <div className=''>
+ <span className='border border-solid border-red-600 rounded-md p-1 text-red-600'>
+ {product.program.type.label}
+ </span>
+ </div>
+ <div className='mt-2 line-clamp-2 leading-6'>
+ {product.program.name}
</div>
</div>
</td>
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