summaryrefslogtreecommitdiff
path: root/src/lib/product/components/Product
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-10-21 10:06:54 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-10-21 10:06:54 +0700
commita001da95b9c03167656aec8a573cf60c12164b3f (patch)
tree54c8432bf9b1ec21648c6fae9faf94066c96987f /src/lib/product/components/Product
parent5c1f114b9e9feb256a49bfd60ed60c72823bca7c (diff)
parentbf33b9a9493aeab84e72647fad384bed43feabd5 (diff)
Merge branch 'master' into refactor/all
Diffstat (limited to 'src/lib/product/components/Product')
-rw-r--r--src/lib/product/components/Product/ProductDesktop.jsx27
-rw-r--r--src/lib/product/components/Product/ProductMobile.jsx11
2 files changed, 18 insertions, 20 deletions
diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index 701750b2..a8cca416 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -25,6 +25,7 @@ import { useProductCartContext } from '@/contexts/ProductCartContext'
import { Box, Skeleton, Tooltip } from '@chakra-ui/react'
import { Info } from 'lucide-react'
import Breadcrumb from './Breadcrumb'
+import { sellingProductFormat } from '@/core/utils/formatValue'
const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
const router = useRouter()
@@ -44,21 +45,9 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
const { setRefreshCart, refreshCart } = useProductCartContext()
- const getLowestPrice = useCallback(() => {
- const prices = product.variants.map((variant) => ({
- price: variant.price,
- isFlashsale: variant.isFlashsale
- }))
- const lowest = prices.reduce((lowest, price) => {
- return price.price < lowest.price ? price : lowest
- }, prices[0])
- return lowest
- }, [product])
-
useEffect(() => {
- const lowest = getLowestPrice()
- setLowestPrice(lowest)
- }, [getLowestPrice])
+ setLowestPrice({ price: product?.lowestPrice })
+ }, [product])
useEffect(() => {
const getBackgound = async () => {
@@ -418,7 +407,7 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
</div>
</div>
- <div className='w-[25%]'>
+ <div className='w-[30%]'>
{product.variants.length > 1 && product.lowestPrice.priceDiscount > 0 && (
<div className='text-gray_r-12/80'>Harga mulai dari: </div>
)}
@@ -447,7 +436,11 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
)}
</div>
)} */}
-
+ {product?.qtySold > 0 && (
+ <div className='text-gray_r-9'>
+ {sellingProductFormat(product?.qtySold) + ' Terjual'}
+ </div>
+ )}
{lowestPrice?.isFlashsale && lowestPrice?.price.discountPercentage > 0 ? (
<>
<div className='flex gap-x-1 items-center mt-2'>
@@ -632,7 +625,7 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
rel='noopener noreferrer'
target='_blank'
>
- Call for price
+ Call for Inquiry
</a>
)}
</div>
diff --git a/src/lib/product/components/Product/ProductMobile.jsx b/src/lib/product/components/Product/ProductMobile.jsx
index 70ac1cbc..ef2c0002 100644
--- a/src/lib/product/components/Product/ProductMobile.jsx
+++ b/src/lib/product/components/Product/ProductMobile.jsx
@@ -21,6 +21,7 @@ import ImageNext from 'next/image'
import CountDown2 from '@/core/components/elements/CountDown/CountDown2'
import Breadcrumb from './Breadcrumb'
import useAuth from '@/core/hooks/useAuth'
+import { sellingProductFormat } from '@/core/utils/formatValue'
const ProductMobile = ({ product, wishlist, toggleWishlist }) => {
const router = useRouter()
@@ -62,7 +63,8 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => {
price: getLowestPrice(),
stock: product.stockTotal,
weight: product.weight,
- hasProgram: false
+ hasProgram: false,
+ qtySold: product.qtySold
})
const variantOptions = product.variants?.map((variant) => {
@@ -105,7 +107,8 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => {
stock: variant.stock,
weight: variant.weight,
hasProgram: variant.hasProgram,
- isFlashsale: variant.isFlashsale
+ isFlashsale: variant.isFlashsale,
+ qtySold: variant.qtySold
}
setActiveVariant(newActiveVariant)
@@ -245,7 +248,9 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => {
</button>
</div>
<h1 className='leading-6 font-medium mb-3'>{activeVariant?.name}</h1>
-
+ {product?.qtySold > 0 && (
+ <div className='text-gray_r-9'>{sellingProductFormat(activeVariant?.qtySold) + ' Terjual'}</div>
+ )}
{product.variants.length > 1 &&
activeVariant.price.priceDiscount > 0 &&
!selectedVariant && (