From bc8e76f00eaa74eb0cc51b79662a53ef34a3ed67 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 24 Mar 2023 17:05:47 +0700 Subject: - --- src/lib/product/components/ProductCard.jsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/lib/product/components/ProductCard.jsx') diff --git a/src/lib/product/components/ProductCard.jsx b/src/lib/product/components/ProductCard.jsx index 3454d4fd..5710e9ea 100644 --- a/src/lib/product/components/ProductCard.jsx +++ b/src/lib/product/components/ProductCard.jsx @@ -2,8 +2,20 @@ import Image from '@/core/components/elements/Image/Image' import Link from '@/core/components/elements/Link/Link' import currencyFormat from '@/core/utils/currencyFormat' import { createSlug } from '@/core/utils/slug' +import { useEffect, useState } from 'react' +import productPriceApi from '../api/productPriceApi' const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { + const [price, setPrice] = useState(null) + + useEffect(() => { + const loadPrice = async () => { + const dataPrice = await productPriceApi({ id: product.id }) + // console.log(dataPrice) + } + loadPrice() + }) + if (variant == 'vertical') { return (
-- cgit v1.2.3 From 1f20fafef46b4eecaf0dd1b91592f3214e8144d3 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Sat, 25 Mar 2023 12:24:03 +0700 Subject: variant and product price --- src/lib/product/components/ProductCard.jsx | 111 ++++++++++++++++++----------- 1 file changed, 71 insertions(+), 40 deletions(-) (limited to 'src/lib/product/components/ProductCard.jsx') diff --git a/src/lib/product/components/ProductCard.jsx b/src/lib/product/components/ProductCard.jsx index 5710e9ea..e48ab88a 100644 --- a/src/lib/product/components/ProductCard.jsx +++ b/src/lib/product/components/ProductCard.jsx @@ -2,20 +2,11 @@ import Image from '@/core/components/elements/Image/Image' import Link from '@/core/components/elements/Link/Link' import currencyFormat from '@/core/utils/currencyFormat' import { createSlug } from '@/core/utils/slug' -import { useEffect, useState } from 'react' -import productPriceApi from '../api/productPriceApi' +import useProductPrice from '../hooks/useProductPrice' +import { LazyLoadComponent } from 'react-lazy-load-image-component' +import PriceSkeleton from '@/core/components/elements/Skeleton/PriceSkeleton' const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { - const [price, setPrice] = useState(null) - - useEffect(() => { - const loadPrice = async () => { - const dataPrice = await productPriceApi({ id: product.id }) - // console.log(dataPrice) - } - loadPrice() - }) - if (variant == 'vertical') { return (
@@ -57,22 +48,9 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { > {product?.name} - {product?.lowestPrice?.discountPercentage > 0 && ( -
-
- {currencyFormat(product?.lowestPrice?.price)} -
-
{product?.lowestPrice?.discountPercentage}%
-
- )} - -
- {product?.lowestPrice?.priceDiscount > 0 ? ( - currencyFormat(product?.lowestPrice?.priceDiscount) - ) : ( - Call for price - )} -
+ + + {product?.stockTotal > 0 && (
Ready Stock
@@ -128,30 +106,83 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { {product?.name} - {product?.lowestPrice?.discountPercentage > 0 && ( + + + + {product?.stockTotal > 0 && ( +
+
Ready Stock
+
{product?.stockTotal > 5 ? '> 5' : '< 5'}
+
+ )} +
+
+ ) + } +} + +const ProductCardPrice = ({ variant, id }) => { + const { productPrice } = useProductPrice({ id }) + + if (productPrice.isLoading) return + + if (variant == 'vertical') { + return ( + productPrice.isFetched && ( + <> + {productPrice?.data?.discount > 0 && (
-
{product?.lowestPrice?.discountPercentage}%
-
- {currencyFormat(product?.lowestPrice?.price)} +
+ {currencyFormat( + productPrice?.data?.priceStartFrom || productPrice?.data?.priceExclude + )}
+
{productPrice?.data?.discount}%
)}
- {product?.lowestPrice?.priceDiscount > 0 ? ( - currencyFormat(product?.lowestPrice?.priceDiscount) + {productPrice?.data?.priceExcludeAfterDiscount > 0 ? ( + currencyFormat( + productPrice?.data?.priceDiscStartFrom || + productPrice?.data?.priceExcludeAfterDiscount + ) ) : ( Call for price )}
- {product?.stockTotal > 0 && ( -
-
Ready Stock
-
{product?.stockTotal > 5 ? '> 5' : '< 5'}
+ + ) + ) + } + + if (variant == 'horizontal') { + return ( + productPrice.isFetched && ( + <> + {productPrice?.data?.discount > 0 && ( +
+
{productPrice?.data?.discount}%
+
+ {currencyFormat( + productPrice?.data?.priceStartFrom || productPrice?.data?.priceExclude + )} +
)} -
-
+ +
+ {productPrice?.data?.priceExcludeAfterDiscount > 0 ? ( + currencyFormat( + productPrice?.data?.priceDiscStartFrom || + productPrice?.data?.priceExcludeAfterDiscount + ) + ) : ( + Call for price + )} +
+ + ) ) } } -- cgit v1.2.3