summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHATEC\SPVDEV001 <tri.susilo@altama.co.id>2023-07-17 14:23:13 +0700
committerHATEC\SPVDEV001 <tri.susilo@altama.co.id>2023-07-17 14:23:13 +0700
commit96cdb9a7b7ac9751f85d7967a3cdd1c04da42fbd (patch)
treeb5a862983ef66e256ec67c1d592f8403fee000ac /src
parentd61b3ca0213395099e4cea9ace8172d4e622fb52 (diff)
sla
Diffstat (limited to 'src')
-rw-r--r--src/lib/product/components/Product/ProductDesktop.jsx76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index 6a87d022..21757f78 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -15,6 +15,10 @@ import ProductCard from '../ProductCard'
import productSimilarApi from '../../api/productSimilarApi'
import whatsappUrl from '@/core/utils/whatsappUrl'
import { gtagAddToCart } from '@/core/utils/googleTag'
+import odooApi from '@/core/api/odooApi'
+import { last } from 'lodash-contrib'
+import { m } from 'framer-motion'
+import { Button, Spinner } from 'flowbite-react'
const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
const router = useRouter()
@@ -22,6 +26,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
const [lowestPrice, setLowestPrice] = useState(null)
const [addCartAlert, setAddCartAlert] = useState(false)
+ const [isLoadingSLA, setIsLoadingSLA] = useState(true)
const getLowestPrice = useCallback(() => {
const prices = product.variants.map((variant) => variant.price)
@@ -99,6 +104,23 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
if (!productSimilarInBrand) loadProductSimilarInBrand()
}, [product, productSimilarInBrand])
+ 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])
+
return (
<DesktopView>
<div className='container mx-auto pt-10'>
@@ -300,6 +322,8 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
<tr>
<th>Part Number</th>
<th>Varian</th>
+ <th>Stock</th>
+ <th>Persiapan Barang</th>
<th>Harga</th>
<th>Jumlah</th>
<th>Action</th>
@@ -311,6 +335,58 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
<td>{variant.code}</td>
<td>{variant.attributes.join(', ') || '-'}</td>
<td>
+ {isLoadingSLA ? (
+ <div className='text-center'>
+ <Spinner aria-label='Center-aligned spinner example' />
+ </div>
+ ) : (
+ variant?.sla?.qty
+ )}
+ </td>
+ <td className='flex justify-center'>
+ {isLoadingSLA ? (
+ <Button color='gray'>
+ <Spinner aria-label='Alternate spinner button example' />
+ <span className='pl-3'>Loading...</span>
+ </Button>
+ ) : variant?.sla?.slaDate != '-' ? (
+ <button
+ type='button'
+ title={`Masa Persiapan Barang ${variant?.sla?.slaDate}`}
+ className={`flex gap-x-1 items-center p-2 rounded-lg w-full ${
+ variant?.sla?.slaDate === 'indent' ? 'bg-indigo-900' : 'btn-light'
+ }`}
+ >
+ <div
+ className={`flex-1 text-caption-1 ${
+ variant?.sla?.slaDate === 'indent' ? 'text-white' : ''
+ }`}
+ >
+ {variant?.sla?.slaDate}
+ </div>
+ <div className='flex-end'>
+ <svg
+ aria-hidden='true'
+ fill='none'
+ stroke='currentColor'
+ stroke-width='1.5'
+ className={`w-7 h-7 ${
+ variant?.sla?.slaDate === 'indent' ? 'text-white' : ''
+ }`}
+ >
+ <path
+ d='M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z'
+ stroke-linecap='round'
+ stroke-linejoin='round'
+ ></path>
+ </svg>
+ </div>
+ </button>
+ ) : (
+ '-'
+ )}
+ </td>
+ <td>
{variant.price.discountPercentage > 0 &&
variant.price.priceDiscount > 0 && (
<>