diff options
| author | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-06-30 14:58:05 +0700 |
|---|---|---|
| committer | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-06-30 14:58:05 +0700 |
| commit | c4ff871551cfbf3ed759b3d7be735d7039edb6f5 (patch) | |
| tree | 563bf41be846299943a63270bb19f5e73011b311 /src/lib/cart | |
| parent | 927022b91855dba6d64365b68b4d20551256e7db (diff) | |
cart
Diffstat (limited to 'src/lib/cart')
| -rw-r--r-- | src/lib/cart/components/Cart.jsx | 83 |
1 files changed, 50 insertions, 33 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> |
