summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortrisusilo <tri.susilo@altama.co.id>2023-07-25 09:48:57 +0000
committertrisusilo <tri.susilo@altama.co.id>2023-07-25 09:48:57 +0000
commit6f7df4cbdc809c452c7371ab2b1c700b8e02cfdc (patch)
tree556dc16a61d6b3c1a11081ed6d1df9512c5bc509
parent75d0aef31ab798fad2bd77cfc7482234d780aa1f (diff)
parent5ff46d23cb3632124c2846c247a98773eb9d649a (diff)
Merged in Feature/SLA (pull request #20)
Feature/SLA
-rw-r--r--src/lib/product/components/Product/ProductMobile.jsx50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/lib/product/components/Product/ProductMobile.jsx b/src/lib/product/components/Product/ProductMobile.jsx
index 46a6af75..91de173a 100644
--- a/src/lib/product/components/Product/ProductMobile.jsx
+++ b/src/lib/product/components/Product/ProductMobile.jsx
@@ -57,6 +57,35 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => {
}))
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])
}
@@ -111,23 +140,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 +286,7 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => {
<Spinner aria-label='Alternate spinner button example' />
<span className='pl-3'>Loading...</span>
</Button>
- ) : activeVariant?.sla?.slaDate != '-' ? (
+ ) : selectedVariant ? activeVariant?.sla?.slaDate != '-' ? (
<button
type='button'
title={`Masa Persiapan Barang ${activeVariant?.sla?.slaDate}`}
@@ -307,7 +319,7 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => {
</svg>
</div>
</button>
- ) : (
+ ):('-') : (
'-'
)}
</span>