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

---
 src/lib/quotation/components/Quotationheader.jsx | 67 +++++++++++++++++++-----
 1 file changed, 55 insertions(+), 12 deletions(-)

(limited to 'src/lib/quotation/components/Quotationheader.jsx')

diff --git a/src/lib/quotation/components/Quotationheader.jsx b/src/lib/quotation/components/Quotationheader.jsx
index 141b731e..9f0f17a6 100644
--- a/src/lib/quotation/components/Quotationheader.jsx
+++ b/src/lib/quotation/components/Quotationheader.jsx
@@ -1,16 +1,15 @@
 import { useCallback, useEffect, useMemo, useState } from 'react';
-import { getQuotationApi } from '../api/QuotationApi';
-import currencyFormat from '@/core/utils/currencyFormat';
 import { createSlug } from '@/core/utils/slug';
 import useAuth from '@/core/hooks/useAuth';
 import { useRouter } from 'next/router';
 import odooApi from '@/core/api/odooApi';
-import { useProductQuotationContext } from '@/contexts/ProductQuotationContext';
+import { useProductCartContext } from '@/contexts/ProductCartContext';
 import Image from '@/core/components/elements/Image/Image';
 import whatsappUrl from '@/core/utils/whatsappUrl';
 import { AnimatePresence, motion } from 'framer-motion';
 import style from '../../../../src-migrate/modules/cart/styles/item-promo.module.css';
 import useTransactions from '../../transaction/hooks/useTransactions';
+import currencyFormat from '@/core/utils/currencyFormat';
 const { DocumentCheckIcon, PhotoIcon } = require('@heroicons/react/24/outline');
 const { default: Link } = require('next/link');
 
@@ -20,14 +19,14 @@ const Quotationheader = (quotationCount) => {
     context: 'quotation',
     site: auth?.webRole === null && auth?.site ? auth.site : null,
   };
-
+  
   const router = useRouter();
   const [subTotal, setSubTotal] = useState(null);
   const [buttonLoading, SetButtonTerapkan] = useState(false);
   const itemLoading = [1, 2, 3];
   const [countQuotation, setCountQuotation] = useState(null);
-  const { productQuotation, setProductQuotation, refreshQuotation, setRefreshQuotation, isLoading, setIsloading } =
-    useProductQuotationContext();
+  const { productCart, setProductCart, refreshCart, setRefreshCart, isLoading, setIsloading, productQuotation, setProductQuotation, refreshQuotation, setRefreshQuotation } =
+  useProductCartContext();
 
   const [isHovered, setIsHovered] = useState(false);
   const [isTop, setIsTop] = useState(true);
@@ -49,12 +48,12 @@ const Quotationheader = (quotationCount) => {
       refreshCartf();
     }
   };
+  let { transactions } = useTransactions({ query });
   const refreshCartf = useCallback(async () => {
     setIsloading(true);
-    let { transactions } = await useTransactions({ query });
     let pendingTransactions = transactions?.data?.saleOrders.filter(transaction => transaction.status === 'draft');
     setProductQuotation(pendingTransactions);
-    setCountQuotation(pendingTransactions.length);
+    setCountQuotation(pendingTransactions?.length ? pendingTransactions?.length : pendingTransactions?.length);
     setIsloading(false);
   }, [setProductQuotation, setIsloading]);
 
@@ -66,7 +65,7 @@ const Quotationheader = (quotationCount) => {
   }, [refreshQuotation, refreshCartf, setRefreshQuotation]);
 
   useEffect(() => {
-    setCountQuotation(quotationCount.cartCount);
+    setCountQuotation(quotationCount.quotationCount);
   }, [quotationCount]);
 
   useEffect(() => {
@@ -85,6 +84,8 @@ const Quotationheader = (quotationCount) => {
     router.push('/shop/quotation');
   };
 
+  console.log("quotation",qotation)
+
   return (
     <div className='relative group'>
       <div>
@@ -105,7 +106,7 @@ const Quotationheader = (quotationCount) => {
             )}
           </div>
           <span>
-            Daftar
+            List
             <br />
             Quotation
           </span>
@@ -137,7 +138,7 @@ const Quotationheader = (quotationCount) => {
               >
                 <div className='p-2 flex justify-between items-center'>
                   <h5 className='text-base font-semibold leading-none'>Daftar Quotation</h5>
-                  <Link href='/shop/cart' class='text-sm font-medium text-red-600 underline'>
+                  <Link href='/my/quotations' class='text-sm font-medium text-red-600 underline'>
                     Lihat Semua
                   </Link>
                 </div>
@@ -150,7 +151,7 @@ const Quotationheader = (quotationCount) => {
                         <Link href='/login' className='text-red-600 underline leading-6'>
                           Login
                         </Link>{' '}
-                        Untuk Melihat Daftar Keranjang Belanja Anda
+                        Untuk Melihat Daftar Quotation Anda
                       </p>
                     </div>
                   )}
@@ -176,6 +177,48 @@ const Quotationheader = (quotationCount) => {
                       </p>
                     </div>
                   )}
+                  {auth && qotation.length > 0 && !isLoading && (
+                    <>
+                      <ul role='list' className='divide-y divide-gray-200 dark:divide-gray-700'>
+                        {qotation &&
+                          qotation?.map((product, index) => (
+                            <>
+                              <li className='py-1 sm:py-2'>
+                                <div className='flex justify-between border p-1 flex-col gap-y-2'>
+                                  <div className='flex justify-between'>
+                                    <p className='tanggal text-base'>{product.dateOrder}</p>
+                                    <p className='badge-red h-fit md:text-caption-2 whitespace-nowrap'>Pending Quotation</p>
+                                  </div>
+                                  <div className='bagian tengah flex justify-between'>
+                                    <div className='no transaksi '>  
+                                      <p className='text-base'>
+                                        No. Transaksi
+                                      </p>
+                                      <p className='font-semibold text-red-500'>
+                                        {product.name}
+                                      </p>
+                                    </div>
+                                    <div className='purchase'>
+                                    <p className='text-base'>
+                                    No. Purchase Order
+                                      </p>
+                                      <p className='font-semibold text-red-500'>
+                                      {product.purchaseOrderFile}
+                                      </p>
+                                    </div>
+                                  </div>
+                                  <div className='bagian bawah flex justify-between'>
+                                    <p className='font-semibold'>Total</p>
+                                    <p className='font-semibold'>{currencyFormat(product.amountTotal)}</p>
+                                  </div>
+                                </div>
+                              </li>
+                            </>
+                          ))}
+                      </ul>
+                      <hr />
+                    </>
+                  )}
                 </div>
               </motion.div>
             </motion.div>
-- 
cgit v1.2.3

