From d9652e77733a24b329f8d849e700222f06c4331e Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 4 Aug 2023 13:24:58 +0700 Subject: add image backgournd --- .../product/components/Product/ProductMobile.jsx | 122 ++++++++++++++------- 1 file changed, 85 insertions(+), 37 deletions(-) (limited to 'src/lib/product/components/Product/ProductMobile.jsx') diff --git a/src/lib/product/components/Product/ProductMobile.jsx b/src/lib/product/components/Product/ProductMobile.jsx index 2edd1a5f..f0264542 100644 --- a/src/lib/product/components/Product/ProductMobile.jsx +++ b/src/lib/product/components/Product/ProductMobile.jsx @@ -18,6 +18,8 @@ import PromotionType from '@/lib/promotinProgram/components/PromotionType' import { gtagAddToCart } from '@/core/utils/googleTag' import odooApi from '@/core/api/odooApi' import { Button, Spinner } from 'flowbite-react' +import ImageNext from 'next/image' +import CountDown2 from '@/core/components/elements/CountDown/CountDown2' const ProductMobile = ({ product, wishlist, toggleWishlist }) => { const router = useRouter() @@ -30,6 +32,7 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { const [isLoadingSLA, setIsLoadingSLA] = useState(true) const [promotionType, setPromotionType] = useState(false) const [promotionActiveId, setPromotionActiveId] = useState(null) + const [backgorundFlashSale, setBackgorundFlashSale] = useState(null) const getLowestPrice = () => { const prices = product.variants.map((variant) => variant.price) @@ -39,6 +42,14 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { return lowest } + useEffect(() => { + const getBackgound = async () => { + const get = await odooApi('GET', '/api/v1/banner?type=flash-sale-background-banner') + setBackgorundFlashSale(get[0].image) + } + getBackgound() + }, []) + const [activeVariant, setActiveVariant] = useState({ id: null, code: product.code, @@ -69,11 +80,11 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { product.variants = variantData setIsLoadingSLA(false) - if(product.variants.length === 1){ + if (product.variants.length === 1) { setActiveVariant({ id: product.variants[0].id, code: product.variants[0].code, - name: product.variants[0].parent.name , + name: product.variants[0].parent.name, price: product.variants[0].price, stock: product.variants[0].stock, weight: product.variants[0].weight, @@ -143,7 +154,7 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { quantity, programLineId: promotionActiveId, selected: true, - source : 'buy' + source: 'buy' }) router.push(`/shop/checkout?source=buy`) } @@ -156,11 +167,44 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { return ( - {product.name} +
+ {product?.flashSale?.remainingTime > 0 && ( +
+
+ +
+
+
+
+ + {product.lowestPrice.discountPercentage}% + +
+
+ + + {product.flashSale.tag || 'FLASH SALE'} + +
+
+ +
+
+
+
+ )} + {product.name} +
@@ -294,40 +338,44 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { Loading... - ) : selectedVariant ? activeVariant?.sla?.slaDate != '-' ? ( - - ):('-') : ( + {activeVariant?.sla?.slaDate} +
+
+ +
+ + ) : ( + '-' + ) + ) : ( '-' )} -- cgit v1.2.3 From 9595223471946520f5c156e24eceb577fae4c901 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 4 Aug 2023 13:36:47 +0700 Subject: add backgorund image mobile --- src/lib/product/components/Product/ProductMobile.jsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/lib/product/components/Product/ProductMobile.jsx') diff --git a/src/lib/product/components/Product/ProductMobile.jsx b/src/lib/product/components/Product/ProductMobile.jsx index f0264542..d25d0861 100644 --- a/src/lib/product/components/Product/ProductMobile.jsx +++ b/src/lib/product/components/Product/ProductMobile.jsx @@ -45,7 +45,9 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { useEffect(() => { const getBackgound = async () => { const get = await odooApi('GET', '/api/v1/banner?type=flash-sale-background-banner') - setBackgorundFlashSale(get[0].image) + if (get.length > 0) { + setBackgorundFlashSale(get[0].image) + } } getBackgound() }, []) @@ -171,7 +173,11 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { {product?.flashSale?.remainingTime > 0 && (
- +
-- cgit v1.2.3