From 33ccd445bf3e72eafeadc920de0f788af91e57fd Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Tue, 25 Jul 2023 15:23:59 +0700 Subject: sla mobile --- .../product/components/Product/ProductDesktop.jsx | 15 ++++- .../product/components/Product/ProductMobile.jsx | 71 +++++++++++++++++++++- 2 files changed, 83 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx index 41eedc55..a7c1d907 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -397,8 +397,21 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
- ) : ( + ) : variant?.sla?.qty > 0 ? ( variant?.sla?.qty + ) : ( + + Tanya Admin + )} diff --git a/src/lib/product/components/Product/ProductMobile.jsx b/src/lib/product/components/Product/ProductMobile.jsx index 667a4ba1..a5caee92 100644 --- a/src/lib/product/components/Product/ProductMobile.jsx +++ b/src/lib/product/components/Product/ProductMobile.jsx @@ -15,6 +15,8 @@ import { createSlug } from '@/core/utils/slug' import BottomPopup from '@/core/components/elements/Popup/BottomPopup' import whatsappUrl from '@/core/utils/whatsappUrl' import { gtagAddToCart } from '@/core/utils/googleTag' +import odooApi from '@/core/api/odooApi' +import { Button, Spinner } from 'flowbite-react' const ProductMobile = ({ product, wishlist, toggleWishlist }) => { const router = useRouter() @@ -24,6 +26,8 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { const [informationTab, setInformationTab] = useState(informationTabOptions[0].value) const [addCartAlert, setAddCartAlert] = useState(false) + const [isLoadingSLA, setIsLoadingSLA] = useState(true) + const getLowestPrice = () => { const prices = product.variants.map((variant) => variant.price) const lowest = prices.reduce((lowest, price) => { @@ -66,7 +70,8 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { name: variant.parent.name + variantAttributes, price: variant.price, stock: variant.stock, - weight: variant.weight + weight: variant.weight, + sla: variant.sla }) } }, [selectedVariant, product]) @@ -100,6 +105,23 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { router.push(`/shop/checkout?productId=${activeVariant.id}&quantity=${quantity}`) } + useEffect(() => { + const fetchData = async () => { + const promises = product.variants.map(async (variant) => { + const dataSLA = await odooApi('GET', `/api/v1/product_variant/${variant.id}/stock`) + return { + ...variant, + sla: dataSLA + } + }) + const variantData = await Promise.all(promises) + product.variants = variantData + + setIsLoadingSLA(false) + } + fetchData() + }, [product]) + const productSimilarQuery = [ product?.name, `fq=-product_id_i:${product.id}`, @@ -228,6 +250,51 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { active={informationTab == 'specification'} className='rounded border border-gray_r-6 divide-y divide-gray_r-6' > + + + {isLoadingSLA ? ( + + ) : activeVariant?.sla?.slaDate != '-' ? ( + + ) : ( + '-' + )} + + {product?.variantTotal} Varian @@ -343,7 +410,7 @@ const TabContent = ({ children, active, className, ...props }) => ( ) const SpecificationContent = ({ children, label }) => ( -
+
{label} {children}
-- cgit v1.2.3