From bfa3cf8546e1a45941e8388b251b91975f95bfd3 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Wed, 19 Feb 2025 15:28:16 +0700
Subject: <iman> update code dari qty_available ke free_bandengan

---
 src/lib/variant/components/VariantCard.jsx | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

(limited to 'src/lib/variant/components/VariantCard.jsx')

diff --git a/src/lib/variant/components/VariantCard.jsx b/src/lib/variant/components/VariantCard.jsx
index 08b7a97e..d8cd5c93 100644
--- a/src/lib/variant/components/VariantCard.jsx
+++ b/src/lib/variant/components/VariantCard.jsx
@@ -7,12 +7,12 @@ import { createSlug } from '@/core/utils/slug'
 import currencyFormat from '@/core/utils/currencyFormat'
 import { updateItemCart } from '@/core/utils/cart'
 import whatsappUrl from '@/core/utils/whatsappUrl'
-import {useState } from 'react';
+import { useEffect, useState } from 'react';
 import rejectProductApi from '../../../lib/transaction/api/rejectProductApi'
 // import {useTransaction} from 'C:\Users\Indoteknik\next-indoteknik\src\lib\transaction\hooks\useTransaction.js'
 import useTransaction from '../../../lib/transaction/hooks/useTransaction';
 import ImageNext from 'next/image';
-
+import odooApi from '~/libs/odooApi';
 const VariantCard = ({ product, openOnClick = true, buyMore = false }) => {
   const router = useRouter()
   const id = router.query.id
@@ -21,7 +21,7 @@ const VariantCard = ({ product, openOnClick = true, buyMore = false }) => {
   const [isModalOpen, setIsModalOpen] = useState(false);
   const [selectedProduct, setSelectedProduct] = useState(null);
   const [reason, setReason] = useState(''); 
-
+  const [qtyPickUp, setQtyPickUp] = useState(0);
   
 
   const addItemToCart = () => {
@@ -67,6 +67,17 @@ const VariantCard = ({ product, openOnClick = true, buyMore = false }) => {
       toast.error('Gagal reject produk. Silakan coba lagi.');
     }
   };
+
+  useEffect(() => {
+    const fetchData = async () => {
+      const qty_available = await odooApi(
+        'GET',
+        `/api/v1/product_variant/${product.id}/qty_available`
+      );
+      setQtyPickUp(qty_available?.qty);
+    };
+    fetchData();
+  }, [product]);
   
   const Card = () => (
     <div className='flex gap-x-3'>
@@ -118,7 +129,7 @@ const VariantCard = ({ product, openOnClick = true, buyMore = false }) => {
           Berat Item : {product?.weight} Kg x {product?.quantity} Barang
         </p>
         <p className='text-[10px] text-red-500 italic mt-2'>
-          {product.availableQuantity} barang ini bisa di pickup maksimal pukul
+          {qtyPickUp} barang ini bisa di pickup maksimal pukul
           16.00
         </p>
         <div className='flex flex-wrap gap-x-1 items-center mt-auto'>
-- 
cgit v1.2.3

