From 6115a7b9e9e1cd2231c946609cb1ceac6d167386 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Thu, 12 Oct 2023 13:21:00 +0700
Subject: banner promotion page search

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

(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 ef4580d6..1072b2ae 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -15,6 +15,8 @@ import { useRouter } from 'next/router'
 import searchSpellApi from '@/core/api/searchSpellApi'
 import Link from '@/core/components/elements/Link/Link'
 import whatsappUrl from '@/core/utils/whatsappUrl'
+import { Image } from '@chakra-ui/react'
+import odooApi from '@/core/api/odooApi'
 
 const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
   const router = useRouter()
@@ -25,6 +27,8 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
   const { productSearch } = useProductSearch({ query: { ...query, q, limit } })
   const [products, setProducts] = useState(null)
   const [spellings, setSpellings] = useState(null)
+  const [bannerPromotionHeader, setBannerPromotionHeader] = useState(null)
+  const [bannerPromotionFooter, setBannerPromotionFooter] = useState(null)
   const popup = useActive()
   const numRows = [30, 50, 80, 100]
 
@@ -117,6 +121,20 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
     params = toQuery(params)
     router.push(`${prefixUrl}?${params}`)
   }
+  const getBanner = async () => {
+    if (router.pathname.includes('search')) {
+      const getBannerHeader = await odooApi('GET', '/api/v1/banner?type=promotion-header')
+      const getBannerFooter = await odooApi('GET', '/api/v1/banner?type=promotion-footer')
+      var randomIndex = Math.floor(Math.random() * getBannerHeader.length)
+      var randomIndexFooter = Math.floor(Math.random() * getBannerFooter.length)
+      setBannerPromotionHeader(getBannerHeader[randomIndex])
+      setBannerPromotionFooter(getBannerFooter[randomIndexFooter])
+    }
+  }
+
+  useEffect(() => {
+    getBanner()
+  }, [])
 
   useEffect(() => {
     setProducts(productSearch.data?.response?.products)
@@ -230,6 +248,16 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
             />
           </div>
           <div className='w-9/12 pl-6'>
+            {bannerPromotionHeader && bannerPromotionHeader?.image && (
+              <div className='mb-3'>
+                <Image
+                  src={bannerPromotionHeader?.image}
+                  alt=''
+                  className='object-cover object-center h-full mx-auto'
+                />
+              </div>
+            )}
+
             <h1 className='text-2xl mb-2 font-semibold'>Hasil Pencarian</h1>
             <div className='flex justify-between items-center mb-2'>
               <div className='mb-2 leading-6 text-gray_r-11'>
@@ -332,6 +360,15 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
                 className='!justify-end'
               />
             </div>
+            {bannerPromotionFooter && bannerPromotionFooter?.image && (
+              <div className='mb-3'>
+                <Image
+                  src={bannerPromotionFooter?.image}
+                  alt=''
+                  className='object-cover object-center h-full mx-auto'
+                />
+              </div>
+            )}
           </div>
         </div>
       </DesktopView>
-- 
cgit v1.2.3

