From 565f6b280b3c4686ad27fdccd05d62d286a30d66 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Mon, 30 Oct 2023 13:35:12 +0700
Subject: fixing speling search

---
 src/lib/product/components/ProductSearch.jsx | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

(limited to 'src/lib/product/components/ProductSearch.jsx')

diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx
index b25311cf..a4e9ecbb 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -25,6 +25,7 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
   const router = useRouter()
   const { page = 1 } = query
   const [q, setQ] = useState(query?.q || '*')
+  const [search, setSearch] = useState(query?.q || '*')
   const [limit, setLimit] = useState(query?.limit || 30)
   const [orderBy, setOrderBy] = useState(router.query?.orderBy || 'popular')
   if (defaultBrand) query.brand = defaultBrand.toLowerCase()
@@ -84,9 +85,13 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
   useEffect(() => {
     const checkIfBrand = async () => {
       const brand = await axios(
-        `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/brands?params=search&q=${q}`
+        `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/brands?params=search&q=${search}`
       )
-      setIsBrand(brand?.data[0])
+      if (brand.data.length > 0) {
+        setIsBrand(brand?.data[0])
+      } else {
+        setIsBrand(null)
+      }
     }
     checkIfBrand()
   }, [q])
@@ -500,14 +505,14 @@ const FilterChoicesComponent = ({
 }) => (
   <div className='flex items-center'>
     <HStack spacing={2} className='flex-wrap'>
-      {brandValues.map((value, index) => (
+      {brandValues?.map((value, index) => (
         <Tag size='lg' key={index} borderRadius='lg' variant='outline' colorScheme='gray'>
           <TagLabel>{value}</TagLabel>
           <TagCloseButton onClick={() => handleDeleteFilter('brands', value)} />
         </Tag>
       ))}
 
-      {categoryValues.map((value, index) => (
+      {categoryValues?.map((value, index) => (
         <Tag size='lg' key={index} borderRadius='lg' variant='outline' colorScheme='gray'>
           <TagLabel>{value}</TagLabel>
           <TagCloseButton onClick={() => handleDeleteFilter('category', value)} />
@@ -519,7 +524,7 @@ const FilterChoicesComponent = ({
           <TagCloseButton onClick={() => handleDeleteFilter('price', priceFrom)} />
         </Tag>
       )}
-      {brandValues.length > 0 || categoryValues.length > 0 || priceFrom || priceTo ? (
+      {brandValues?.length > 0 || categoryValues?.length > 0 || priceFrom || priceTo ? (
         <span>
           <button
             className='btn-transparent py-2 px-5 h-[40px] text-red-700'
-- 
cgit v1.2.3

