From 51726bd7e8e69535590d70327ebd340ffaf96abd Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Wed, 25 Oct 2023 09:50:46 +0700
Subject: show brand logo di page search

---
 src/lib/product/components/ProductSearch.jsx | 36 +++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

(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 3740d264..50936d9a 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -18,6 +18,8 @@ import whatsappUrl from '@/core/utils/whatsappUrl'
 import { HStack, Image, Tag, TagCloseButton, TagLabel } from '@chakra-ui/react'
 import odooApi from '@/core/api/odooApi'
 import { formatCurrency } from '@/core/utils/formatValue'
+import axios from 'axios'
+import Skeleton from 'react-loading-skeleton'
 
 const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) => {
   const router = useRouter()
@@ -34,6 +36,7 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
   const [spellings, setSpellings] = useState(null)
   const [bannerPromotionHeader, setBannerPromotionHeader] = useState(null)
   const [bannerPromotionFooter, setBannerPromotionFooter] = useState(null)
+  const [isBrand, setIsBrand] = useState(null)
   const popup = useActive()
   const numRows = [30, 50, 80, 100]
   const [brandValues, setBrand] = useState(
@@ -78,6 +81,22 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
     }
   }, [productFound, query, spellings])
 
+  useEffect(() => {
+    const checkIfBrand = async () => {
+      const brand = await axios(
+        `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/brands?params=search&q=${q}`
+      )
+      if (brand.data.length > 0) {
+        brand.data.map((brand) => {
+          if (brand.name.toLowerCase() === q.toLowerCase()) {
+            setIsBrand(brand)
+          }
+        })
+      }
+    }
+    checkIfBrand()
+  }, [q])
+
   const brands = []
   for (
     let i = 0;
@@ -148,7 +167,11 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
   const SpellingComponent = useMemo(() => {
     return (
       <>
-        {spellings?.length > 0 ? <>Mungkin yang anda cari </> : <>Produk yang cari anda tidak ada</>}
+        {spellings?.length > 0 ? (
+          <>Mungkin yang anda cari </>
+        ) : (
+          <>Produk yang cari anda tidak ada</>
+        )}
         {spellings?.map((spelling, i) => (
           <Link href={`/shop/search?q=${spelling}`} key={i} className='inline'>
             {spelling}
@@ -331,6 +354,17 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
               </div>
             )}
 
+            {isBrand && isBrand.logo && (
+              <div className='mb-3'>
+                <h1 className='text-2xl mb-2 font-semibold'>Brand Pencarian {q}</h1>
+                <Image
+                  src={isBrand?.logo}
+                  alt=''
+                  className='object-cover object-center h-[100px]'
+                />
+              </div>
+            )}
+
             <h1 className='text-2xl mb-2 font-semibold'>Hasil Pencarian</h1>
             <FilterChoicesComponent
               brandValues={brandValues}
-- 
cgit v1.2.3


From 0a1413aec32fddc433a34bf7d03d8681dedc266d Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Mon, 30 Oct 2023 09:30:25 +0700
Subject: show brand logo in page search if search is brand

---
 src/lib/product/components/ProductSearch.jsx | 9 ++-------
 1 file changed, 2 insertions(+), 7 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 50936d9a..190d026b 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -86,13 +86,8 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
       const brand = await axios(
         `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/brands?params=search&q=${q}`
       )
-      if (brand.data.length > 0) {
-        brand.data.map((brand) => {
-          if (brand.name.toLowerCase() === q.toLowerCase()) {
-            setIsBrand(brand)
-          }
-        })
-      }
+      setIsBrand(brand?.data[0])
+     
     }
     checkIfBrand()
   }, [q])
-- 
cgit v1.2.3


From 63d5528a04ce8a2667c7a4a81e2d43676111c05e Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Mon, 30 Oct 2023 10:13:41 +0700
Subject: logo brand di page search mobile

---
 src/lib/product/components/ProductSearch.jsx | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

(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 190d026b..b25311cf 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -87,7 +87,6 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
         `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/brands?params=search&q=${q}`
       )
       setIsBrand(brand?.data[0])
-     
     }
     checkIfBrand()
   }, [q])
@@ -225,6 +224,12 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
       <MobileView>
         {productSearch.isLoading && <ProductSearchSkeleton />}
         <div className='p-4 pt-0'>
+          {isBrand && isBrand.logo && (
+            <div className='mb-3'>
+              <h1 className='mb-2 font-semibold text-h-sm'>Brand Pencarian {q}</h1>
+              <Image src={isBrand?.logo} alt='' className='object-cover object-center h-[60px]' />
+            </div>
+          )}
           <h1 className='mb-2 font-semibold text-h-sm'>Produk</h1>
           <FilterChoicesComponent
             brandValues={brandValues}
-- 
cgit v1.2.3


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


From 87a004c0fcf256e1e92653767a630c01ad21ad5a Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Sat, 18 Nov 2023 11:33:28 +0700
Subject: add brand link di page search

---
 src/lib/product/components/ProductSearch.jsx | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 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 a4e9ecbb..29bb987e 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -20,6 +20,7 @@ import odooApi from '@/core/api/odooApi'
 import { formatCurrency } from '@/core/utils/formatValue'
 import axios from 'axios'
 import Skeleton from 'react-loading-skeleton'
+import { createSlug } from '@/core/utils/slug'
 
 const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) => {
   const router = useRouter()
@@ -87,13 +88,16 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
       const brand = await axios(
         `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/brands?params=search&q=${search}`
       )
+      console.log('ini brand', brand)
       if (brand.data.length > 0) {
         setIsBrand(brand?.data[0])
       } else {
         setIsBrand(null)
       }
     }
-    checkIfBrand()
+    if (router.pathname.includes('search')) {
+      checkIfBrand()
+    }
   }, [q])
 
   const brands = []
@@ -362,11 +366,12 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
             {isBrand && isBrand.logo && (
               <div className='mb-3'>
                 <h1 className='text-2xl mb-2 font-semibold'>Brand Pencarian {q}</h1>
-                <Image
-                  src={isBrand?.logo}
-                  alt=''
-                  className='object-cover object-center h-[100px]'
-                />
+                <Link
+                  href={createSlug('/shop/brands/', isBrand.name, isBrand.id)}
+                  className='inline'
+                >
+                  <Image src={isBrand?.logo} alt='' className='object-cover object-center h-24' />
+                </Link>
               </div>
             )}
 
-- 
cgit v1.2.3

