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/ProductMobile.jsx | 71 +++++++++++++++++++++- 1 file changed, 69 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 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 From dc5e9f0f6a1b3fd2211f6daf87c055abe47f0023 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Tue, 25 Jul 2023 16:40:59 +0700 Subject: default activevariant --- .../product/components/Product/ProductMobile.jsx | 51 ++++++++++++++-------- 1 file changed, 32 insertions(+), 19 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 46a6af75..3f13f980 100644 --- a/src/lib/product/components/Product/ProductMobile.jsx +++ b/src/lib/product/components/Product/ProductMobile.jsx @@ -56,6 +56,35 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { (variant.attributes.length > 0 ? variant.attributes.join(', ') : product.name) })) + 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) + if(product.variants.length === 1){ + setActiveVariant({ + id: product.variants[0].id, + code: product.variants[0].code, + name: product.variants[0].parent.name , + price: product.variants[0].price, + stock: product.variants[0].stock, + weight: product.variants[0].weight, + sla: product.variants[0].sla, + hasProgram: product.variants[0].hasProgram + }) + } + } + fetchData() + }, [product]) + useEffect(() => { if (!selectedVariant && variantOptions.length == 1) { setSelectedVariant(variantOptions[0]) @@ -79,6 +108,7 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { hasProgram: variant.hasProgram }) } + console.log('ini adalah active', activeVariant) }, [selectedVariant, product]) const validAction = () => { @@ -111,23 +141,6 @@ 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}`, @@ -274,7 +287,7 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { Loading... - ) : activeVariant?.sla?.slaDate != '-' ? ( + ) : selectedVariant ? activeVariant?.sla?.slaDate != '-' ? (
- ) : ( + ):('-') : ( '-' )} -- cgit v1.2.3 From 5ff46d23cb3632124c2846c247a98773eb9d649a Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Tue, 25 Jul 2023 16:50:52 +0700 Subject: delete console log --- src/lib/product/components/Product/ProductMobile.jsx | 1 - 1 file changed, 1 deletion(-) (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 3f13f980..91de173a 100644 --- a/src/lib/product/components/Product/ProductMobile.jsx +++ b/src/lib/product/components/Product/ProductMobile.jsx @@ -108,7 +108,6 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { hasProgram: variant.hasProgram }) } - console.log('ini adalah active', activeVariant) }, [selectedVariant, product]) const validAction = () => { -- cgit v1.2.3