summaryrefslogtreecommitdiff
path: root/src/lib/product/components/Product/ProductDesktop.jsx
diff options
context:
space:
mode:
authortrisusilo <tri.susilo@altama.co.id>2023-07-27 03:10:38 +0000
committertrisusilo <tri.susilo@altama.co.id>2023-07-27 03:10:38 +0000
commitadae7d08d1f172c9927ebb9ed9e5247ef85690d4 (patch)
tree50cba6376227966d3083e3ad3b68628b1d8a6561 /src/lib/product/components/Product/ProductDesktop.jsx
parent0e8d4375dad12cbf07f8ff484ef547c15ae4c0cc (diff)
parent46c208194cb80be3a4ce2d42ad817551b9b2a18d (diff)
Merged in Hotfix/action_click_button_beli (pull request #32)
Hotfix/action click button beli
Diffstat (limited to 'src/lib/product/components/Product/ProductDesktop.jsx')
-rw-r--r--src/lib/product/components/Product/ProductDesktop.jsx55
1 files changed, 41 insertions, 14 deletions
diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index 9be65bfb..dfff91d7 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -1,5 +1,4 @@
import Image from '@/core/components/elements/Image/Image'
-import ImageNext from 'next/image'
import Link from '@/core/components/elements/Link/Link'
import DesktopView from '@/core/components/views/DesktopView'
import currencyFormat from '@/core/utils/currencyFormat'
@@ -15,10 +14,7 @@ import BottomPopup from '@/core/components/elements/Popup/BottomPopup'
import ProductCard from '../ProductCard'
import productSimilarApi from '../../api/productSimilarApi'
import whatsappUrl from '@/core/utils/whatsappUrl'
-import { gtagAddToCart } from '@/core/utils/googleTag'
import odooApi from '@/core/api/odooApi'
-import { last } from 'lodash-contrib'
-import { m } from 'framer-motion'
import { Button, Spinner } from 'flowbite-react'
import PromotionType from '@/lib/promotinProgram/components/PromotionType'
import useAuth from '@/core/hooks/useAuth'
@@ -72,25 +68,27 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
return isValid
}
- const updateCart = (variantId, quantity) => {
+ const updateCart = (variantId, quantity, source) => {
+ let dataUpdate
if (product.variants.length > 1) {
let variantIndex = product.variants.findIndex((varian) => varian.id == variantId)
- updateItemCart({
+ dataUpdate = {
productId: variantId,
quantity,
programLineId: product.variants[variantIndex].programActive,
selected: true,
- source: 'buy'
- })
+ source: source === 'buy' ? 'buy' : null
+ }
} else {
- updateItemCart({
+ dataUpdate = {
productId: variantId,
quantity,
programLineId: promotionActiveId,
selected: true,
- source: 'buy'
- })
+ source: source === 'buy' ? 'buy' : null
+ }
}
+ updateItemCart(dataUpdate)
}
const handleAddToCart = (variantId) => {
@@ -102,7 +100,8 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
if (!validQuantity(quantity)) return
- updateCart(variantId, quantity)
+ let source = 'cart'
+ updateCart(variantId, quantity, source)
setAddCartAlert(true)
}
@@ -110,7 +109,8 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
const quantity = variantQuantityRefs.current[variant].value
if (!validQuantity(quantity)) return
- updateCart(variant, quantity)
+ let source = 'buy'
+ updateCart(variant, quantity, source)
router.push(`/shop/checkout?source=buy`)
}
@@ -264,7 +264,34 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
)}
</div>
</div>
- <div className='flex p-3 '>
+ {product.variants.length === 1 && (
+ <div className='flex p-3 '>
+ <div className='w-1/4 text-gray_r-12/70'>Stock</div>
+ <div className='w-3/4'>
+ {isLoadingSLA && (
+ <div className=''>
+ <Spinner aria-label='Center-aligned spinner example' />
+ </div>
+ )}
+ {product?.variants[0].sla?.qty > 0 && (
+ <span>{product?.variants[0].sla?.qty}</span>
+ )}
+ {product?.variants[0].sla?.qty == 0 && (
+ <a
+ href={whatsappUrl('product', {
+ name: product.name,
+ manufacture: product?.manufacture?.name,
+ url: createSlug('/shop/product/', product.name, product.id, true)
+ })}
+ className='text-danger-500 font-medium'
+ >
+ Tanya Admin
+ </a>
+ )}
+ </div>
+ </div>
+ )}
+ <div className={`flex p-3 ${product.variants.length > 1 ? '' : 'bg-gray_r-4'} `}>
<div className='w-1/4 text-gray_r-12/70'>Berat Barang</div>
<div className='w-3/4'>
{product?.weight > 0 && <span>{product?.weight} KG</span>}