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-migrate/modules/cart/components/Item.tsx | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

(limited to 'src-migrate/modules/cart/components/Item.tsx')

diff --git a/src-migrate/modules/cart/components/Item.tsx b/src-migrate/modules/cart/components/Item.tsx
index ab2e7ce1..86d1dc43 100644
--- a/src-migrate/modules/cart/components/Item.tsx
+++ b/src-migrate/modules/cart/components/Item.tsx
@@ -1,5 +1,6 @@
 import style from '../styles/item.module.css'
-
+import odooApi from '~/libs/odooApi';
+import { useEffect, useState } from 'react';
 import { Skeleton, SkeletonProps, Tooltip } from '@chakra-ui/react'
 import { InfoIcon } from 'lucide-react'
 import Image from 'next/image'
@@ -22,6 +23,17 @@ type Props = {
 }
 
 const CartItem = ({ item, editable = true, selfPicking}: Props) => {
+  const [qtyPickUp, setQtyPickUp] = useState(0);
+  useEffect(() => {
+    const fetchData = async () => {
+      const qty_available = await odooApi(
+        'GET',
+        `/api/v1/product_variant/${item.id}/qty_available`
+      );
+      setQtyPickUp(qty_available?.qty);
+    };
+    fetchData();
+  }, [item]);
   return (
     <div className={style.wrapper}>
       {item.cart_type === 'promotion' && (  
@@ -54,11 +66,11 @@ const CartItem = ({ item, editable = true, selfPicking}: Props) => {
         <CartItem.Image item={item} />
 
         <div className={style.details}>
-          {item?.available_quantity > 0 && (
+          {qtyPickUp > 0 && (
             <div className='text-[10px] text-red-500 italic'>
-              {item.quantity <= item?.available_quantity
+              {item.quantity <= qtyPickUp
                 ? '*Barang ini bisa di pickup maksimal pukul 16.00'
-                : `*${item?.available_quantity} Barang ini bisa di pickup maksimal pukul 16.00`}
+                : `*${qtyPickUp} Barang ini bisa di pickup maksimal pukul 16.00`}
             </div>
           )}
           <CartItem.Name item={item} />
-- 
cgit v1.2.3

