From a63b03fffdf46ecddecf356d1d00d6582add75cf Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 6 Aug 2024 17:05:01 +0700
Subject: <iman> update cart pop up

---
 .../components/elements/Navbar/NavbarDesktop.jsx   | 35 +++++++++++-----------
 1 file changed, 18 insertions(+), 17 deletions(-)

(limited to 'src/core/components/elements/Navbar/NavbarDesktop.jsx')

diff --git a/src/core/components/elements/Navbar/NavbarDesktop.jsx b/src/core/components/elements/Navbar/NavbarDesktop.jsx
index 49c4cd6e..c0e9b383 100644
--- a/src/core/components/elements/Navbar/NavbarDesktop.jsx
+++ b/src/core/components/elements/Navbar/NavbarDesktop.jsx
@@ -7,7 +7,7 @@ import IndoteknikLogo from '@/images/logo.png';
 import Cardheader from '@/lib/cart/components/Cartheader';
 import Quotationheader from '@/lib/quotation/components/QuotationHeader'
 import Category from '@/lib/category/components/Category';
-import { useProductQuotationContext } from '@/contexts/ProductQuotationContext'
+import { useProductCartContext } from '@/contexts/ProductCartContext';
 import {
   ChevronDownIcon,
   DocumentCheckIcon,
@@ -41,8 +41,9 @@ const NavbarDesktop = () => {
 
   const [cartCount, setCartCount] = useState(0);
   const [quotationCount, setQuotationCount] = useState(0);
-  // const { setProductQuotation, refreshQuotation, setRefreshQuotation, isLoading, setIsloading } = useProductQuotationContext()
-
+  const { productCart, setProductCart, refreshCart, setRefreshCart, isLoading, setIsloading, productQuotation, setProductQuotation, refreshQuotation, setRefreshQuotation } =
+  useProductCartContext();
+  const [pendingTransactions, setPendingTransactions] = useState([])
   const [templateWA, setTemplateWA] = useState(null);
   const [payloadWA, setPayloadWa] = useState(null);
   const [urlPath, setUrlPath] = useState(null);
@@ -51,15 +52,22 @@ const NavbarDesktop = () => {
 
   const { product } = useProductContext();
   const { isOpen, onOpen, onClose } = useDisclosure();
-
+  
   const query = {
     context: 'quotation',
     site:
-      (auth?.webRole === null && auth?.site ? auth.site : null),
+    (auth?.webRole === null && auth?.site ? auth.site : null),
   };
   
-  const { transactions } = useTransactions({query});
-  const pendingTransactions = transactions?.data?.saleOrders.filter(transaction => transaction.status === 'draft');
+  const { transactions } = useTransactions({ query });
+  const data = transactions?.data?.saleOrders.filter(
+    (transaction) => transaction.status === 'draft'
+  );
+
+  useEffect(() => {
+    setProductQuotation(data);
+    setPendingTransactions(data);
+  }, [transactions.data]);
   
   
   useEffect(() => {
@@ -83,7 +91,7 @@ const NavbarDesktop = () => {
       };
       cart();
     };
-    handleCartChange();
+    handleCartChange(); 
     
     window.addEventListener('localStorageChange', handleCartChange);
     
@@ -91,12 +99,6 @@ const NavbarDesktop = () => {
       window.removeEventListener('localStorageChange', handleCartChange);
     };
   }, []);
-  
-  // useEffect(() => {
-  //   setProductQuotation(pendingTransactions)
-  // }, [transactions, ])
-  // console.log("Pending Transactions", pendingTransactions); 
-  // console.log("pendingTransactions.length", pendingTransactions.length); 
 
   useEffect(() => {
     const handleQuotationChange = () => {
@@ -112,8 +114,8 @@ const NavbarDesktop = () => {
     return () => {
       window.removeEventListener('localStorageChange', handleQuotationChange);
     };
-  }, []);
-  console.log("quotationCount",quotationCount)
+  }, [pendingTransactions]);
+  
   return (
     <DesktopView>
       <TopBanner />
@@ -176,7 +178,6 @@ const NavbarDesktop = () => {
             <Search />
           </div>
           <div className='flex gap-x-4 items-center'>
-
             <Quotationheader quotationCount={quotationCount} />
 
             <Cardheader cartCount={cartCount} />
-- 
cgit v1.2.3

