From 4a05c21f583e1482acb126d51aafe5cbce49707f Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Mon, 10 Apr 2023 09:57:16 +0700
Subject: fix bug cart and search

---
 src/lib/cart/components/Cart.jsx | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

(limited to 'src/lib/cart/components/Cart.jsx')

diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx
index 46b2b811..49fa46e6 100644
--- a/src/lib/cart/components/Cart.jsx
+++ b/src/lib/cart/components/Cart.jsx
@@ -14,9 +14,7 @@ import Spinner from '@/core/components/elements/Spinner/Spinner'
 import Alert from '@/core/components/elements/Alert/Alert'
 import MobileView from '@/core/components/views/MobileView'
 import DesktopView from '@/core/components/views/DesktopView'
-import ProductSearch from '@/lib/product/components/ProductSearch'
 import ProductCard from '@/lib/product/components/ProductCard'
-import useProductSearch from '@/lib/product/hooks/useProductSearch'
 import productSearchApi from '@/lib/product/api/productSearchApi'
 
 const Cart = () => {
@@ -24,7 +22,6 @@ const Cart = () => {
   const [products, setProducts] = useState(null)
   const { cart } = useCart({ enabled: !products })
 
-  const {productSearch} = useProductSearch({'query':{'q':products?.[0].parent.name,'limit' : '10'}});
   const [totalPriceBeforeTax, setTotalPriceBeforeTax] = useState(0)
   const [totalTaxAmount, setTotalTaxAmount] = useState(0)
   const [totalDiscountAmount, setTotalDiscountAmount] = useState(0)
@@ -76,7 +73,8 @@ const Cart = () => {
 
   useEffect(() => {
     const LoadProductSImilar = async () => {
-      const productLoad = await productSearchApi({ query: `q=${products?.[0].parent.name}&limit=10` })
+      const randProductIndex = Math.floor(Math.random() * products.length)
+      const productLoad = await productSearchApi({ query: `q=${products?.[randProductIndex].parent.name}&limit=10` })
 
       setProductRecomendation(productLoad);
 
@@ -432,7 +430,7 @@ const Cart = () => {
           </div>
 
           <div className='col-span-3 pl-4'>
-            <div className='sticky top-32 w-full p-4 rounded border border-gray_r-6 bg-white'>
+            <div className='sticky top-48 w-full p-4 rounded border border-gray_r-6 bg-white'>
               <h1 className='text-title-sm font-semibold mb-6'>Ringkasan Belanja</h1>
               <div className='flex justify-between mb-4'>
                 <div className='text-gray_r-11'>
-- 
cgit v1.2.3

