From 70591a6a132d25656e4404d78d6364e21949e81a Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Fri, 20 Oct 2023 09:29:48 +0700
Subject: filter choices

---
 src/lib/product/components/ProductSearch.jsx | 109 ++++++++++++++++++++++++++-
 1 file changed, 107 insertions(+), 2 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 9d59b305..bc69c9dd 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -15,8 +15,9 @@ 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 { HStack, Image, Tag, TagCloseButton, TagLabel } from '@chakra-ui/react'
 import odooApi from '@/core/api/odooApi'
+import { formatCurrency } from '@/core/utils/formatValue'
 
 const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
   const router = useRouter()
@@ -32,6 +33,10 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
   const [bannerPromotionFooter, setBannerPromotionFooter] = useState(null)
   const popup = useActive()
   const numRows = [30, 50, 80, 100]
+  const [brandValues, setBrand] = useState(query?.brand?.split(',') || [])
+  const [categoryValues, setCategory] = useState(query?.category?.split(',') || [])
+  const [priceFrom, setPriceFrom] = useState(query?.priceFrom || null)
+  const [priceTo, setPriceTo] = useState(query?.priceTo || null)
 
   const pageCount = Math.ceil(productSearch.data?.response.numFound / limit)
   const productStart = productSearch.data?.responseHeader.params.start
@@ -98,7 +103,7 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
       categories.push({ name, qty })
     }
   }
-  
+
   /*const categories = productSearch.data?.facetCounts?.facetFields?.categoryName?.filter(
     (value, index) => {
       if (index % 2 === 0) {
@@ -166,12 +171,62 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
     )
   }, [spellings])
 
+  const handleDeleteFilter = async (source, value) => {
+    let params = {
+      q: router.query.q,
+      orderBy: orderBy,
+      brand: brandValues.join(','),
+      category: categoryValues.join(','),
+      priceFrom,
+      priceTo
+    }
+
+    let brands = brandValues
+    let catagories = categoryValues
+    switch (source) {
+      case 'brands':
+        brands = brandValues.filter((item) => item !== value)
+        params.brand = brands.join(',')
+        await setBrand(brands)
+        break
+      case 'category':
+        catagories = categoryValues.filter((item) => item !== value)
+        params.category = catagories.join(',')
+        await setCategory(catagories)
+        break
+      case 'price':
+        params.priceFrom = null
+        params.priceTo = null
+        break
+      case 'delete':
+        params = {
+          q: router.query.q,
+          orderBy: orderBy
+        }
+        break
+    }
+
+    handleSubmitFilter(params)
+  }
+  const handleSubmitFilter = (params) => {
+    params = _.pickBy(params, _.identity)
+    params = toQuery(params)
+    router.push(`${prefixUrl}?${params}`)
+  }
+
   return (
     <>
       <MobileView>
         {productSearch.isLoading && <ProductSearchSkeleton />}
         <div className='p-4 pt-0'>
           <h1 className='mb-2 font-semibold text-h-sm'>Produk</h1>
+          <FilterChoicesComponent
+            brandValues={brandValues}
+            categoryValues={categoryValues}
+            priceFrom={priceFrom}
+            priceTo={priceTo}
+            handleDeleteFilter={handleDeleteFilter}
+          />
 
           <div className='mb-2 leading-6 text-gray_r-11'>
             {!spellings ? (
@@ -271,6 +326,13 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
             )}
 
             <h1 className='text-2xl mb-2 font-semibold'>Hasil Pencarian</h1>
+            <FilterChoicesComponent
+              brandValues={brandValues}
+              categoryValues={categoryValues}
+              priceFrom={priceFrom}
+              priceTo={priceTo}
+              handleDeleteFilter={handleDeleteFilter}
+            />
             <div className='flex justify-between items-center mb-2'>
               <div className='mb-2 leading-6 text-gray_r-11'>
                 {!spellings ? (
@@ -388,3 +450,46 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
 }
 
 export default ProductSearch
+
+const FilterChoicesComponent = ({
+  brandValues,
+  categoryValues,
+  priceFrom,
+  priceTo,
+  handleDeleteFilter
+}) => (
+  <div className='flex items-center'>
+    <HStack spacing={2} className='flex-wrap'>
+      {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) => (
+        <Tag size='lg' key={index} borderRadius='lg' variant='outline' colorScheme='gray'>
+          <TagLabel>{value}</TagLabel>
+          <TagCloseButton onClick={() => handleDeleteFilter('category', value)} />
+        </Tag>
+      ))}
+      {priceFrom && priceTo && (
+        <Tag size='lg' borderRadius='lg' variant='outline' colorScheme='gray'>
+          <TagLabel>{formatCurrency(priceFrom) + '-' + formatCurrency(priceTo)}</TagLabel>
+          <TagCloseButton onClick={() => handleDeleteFilter('price', priceFrom)} />
+        </Tag>
+      )}
+      {brandValues.length > 0 || categoryValues.length > 0 || priceFrom || priceTo ? (
+        <span>
+          <button
+            className='btn-transparent py-2 px-5 h-[40px] text-red-700'
+            onClick={() => handleDeleteFilter('delete')}
+          >
+            Hapus Semua
+          </button>
+        </span>
+      ) : (
+        ''
+      )}
+    </HStack>
+  </div>
+)
-- 
cgit v1.2.3


From b8f5507cda2ede25ebc5433439168a8dadc71ddc Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Fri, 20 Oct 2023 10:26:15 +0700
Subject: fixing serach

---
 src/lib/product/components/ProductSearch.jsx | 9 +++++++--
 1 file changed, 7 insertions(+), 2 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 bc69c9dd..af3d881f 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -26,18 +26,22 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
   const [limit, setLimit] = useState(query?.limit || 30)
   const [orderBy, setOrderBy] = useState(router.query?.orderBy || 'popular')
   if (defaultBrand) query.brand = defaultBrand.toLowerCase()
-  const { productSearch } = useProductSearch({ query: { ...query, q, limit, orderBy } })
+  const { productSearch } = useProductSearch({ query: { ...query, q, limit, orderBy } , operation :  router?.pathname?.includes('brands') ? 'OR' : 'AND' })
   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]
-  const [brandValues, setBrand] = useState(query?.brand?.split(',') || [])
+  const [brandValues, setBrand] = useState(
+    !router.pathname.includes('brands') ? query.brand ? query.brand.split(',') : [] : []
+  )
   const [categoryValues, setCategory] = useState(query?.category?.split(',') || [])
   const [priceFrom, setPriceFrom] = useState(query?.priceFrom || null)
   const [priceTo, setPriceTo] = useState(query?.priceTo || null)
 
+  console.log('ini roiute', router.pathname.includes('brands'))
+
   const pageCount = Math.ceil(productSearch.data?.response.numFound / limit)
   const productStart = productSearch.data?.responseHeader.params.start
   const productRows = limit
@@ -466,6 +470,7 @@ const FilterChoicesComponent = ({
           <TagCloseButton onClick={() => handleDeleteFilter('brands', value)} />
         </Tag>
       ))}
+
       {categoryValues.map((value, index) => (
         <Tag size='lg' key={index} borderRadius='lg' variant='outline' colorScheme='gray'>
           <TagLabel>{value}</TagLabel>
-- 
cgit v1.2.3


From 40c30c5ea9a61ce39e6faf72504a141afa2d1505 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Fri, 20 Oct 2023 11:11:58 +0700
Subject: items center untuk filter urutan dan page limit

---
 src/lib/product/components/ProductSearch.jsx | 10 ++++------
 1 file changed, 4 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 af3d881f..a4e3d872 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -40,8 +40,6 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
   const [priceFrom, setPriceFrom] = useState(query?.priceFrom || null)
   const [priceTo, setPriceTo] = useState(query?.priceTo || null)
 
-  console.log('ini roiute', router.pathname.includes('brands'))
-
   const pageCount = Math.ceil(productSearch.data?.response.numFound / limit)
   const productStart = productSearch.data?.responseHeader.params.start
   const productRows = limit
@@ -337,8 +335,8 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
               priceTo={priceTo}
               handleDeleteFilter={handleDeleteFilter}
             />
-            <div className='flex justify-between items-center mb-2'>
-              <div className='mb-2 leading-6 text-gray_r-11'>
+            <div className='flex justify-between items-center mb-5'>
+              <div className='leading-6 text-gray_r-11'>
                 {!spellings ? (
                   <>
                     Menampilkan&nbsp;
@@ -369,7 +367,7 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
                 <div className='ml-3'>
                   <select
                     name='urutan'
-                    className='form-input mt-2'
+                    className='form-input'
                     value={orderBy}
                     onChange={(e) => handleOrderBy(e)}
                   >
@@ -384,7 +382,7 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
                 <div className='ml-3'>
                   <select
                     name='limit'
-                    className='form-input mt-2'
+                    className='form-input'
                     value={router.query?.limit || ''}
                     onChange={(e) => handleLimit(e)}
                   >
-- 
cgit v1.2.3


From 85e0a7e47db518fb5fb2531b2ea7c6d50408875f Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Fri, 20 Oct 2023 14:02:51 +0700
Subject: logo brand di page brand

---
 src/lib/product/components/ProductSearch.jsx | 41 ++++++++++++++--------------
 1 file changed, 21 insertions(+), 20 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 a4e3d872..630e3a74 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -19,14 +19,17 @@ import { HStack, Image, Tag, TagCloseButton, TagLabel } from '@chakra-ui/react'
 import odooApi from '@/core/api/odooApi'
 import { formatCurrency } from '@/core/utils/formatValue'
 
-const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
+const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) => {
   const router = useRouter()
   const { page = 1 } = query
   const [q, setQ] = useState(query?.q || '*')
   const [limit, setLimit] = useState(query?.limit || 30)
   const [orderBy, setOrderBy] = useState(router.query?.orderBy || 'popular')
   if (defaultBrand) query.brand = defaultBrand.toLowerCase()
-  const { productSearch } = useProductSearch({ query: { ...query, q, limit, orderBy } , operation :  router?.pathname?.includes('brands') ? 'OR' : 'AND' })
+  const { productSearch } = useProductSearch({
+    query: { ...query, q, limit, orderBy },
+    operation: router?.pathname?.includes('brands') ? 'OR' : 'AND'
+  })
   const [products, setProducts] = useState(null)
   const [spellings, setSpellings] = useState(null)
   const [bannerPromotionHeader, setBannerPromotionHeader] = useState(null)
@@ -34,7 +37,7 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
   const popup = useActive()
   const numRows = [30, 50, 80, 100]
   const [brandValues, setBrand] = useState(
-    !router.pathname.includes('brands') ? query.brand ? query.brand.split(',') : [] : []
+    !router.pathname.includes('brands') ? (query.brand ? query.brand.split(',') : []) : []
   )
   const [categoryValues, setCategory] = useState(query?.category?.split(',') || [])
   const [priceFrom, setPriceFrom] = useState(query?.priceFrom || null)
@@ -87,15 +90,6 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
       brands.push({ brand, qty })
     }
   }
-  /*const brandsList = productSearch.data?.facetCounts?.facetFields?.manufactureName?.filter(
-    (value, index) => {
-      if (index % 2 === 0) {
-        const brand = value
-        const qty = index + 1
-        brands.push({ brand, qty })
-      }
-    }
-  )*/
 
   const categories = []
   for (let i = 0; i < productSearch.data?.facetCounts?.facetFields?.categoryName.length; i += 2) {
@@ -106,14 +100,6 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
     }
   }
 
-  /*const categories = productSearch.data?.facetCounts?.facetFields?.categoryName?.filter(
-    (value, index) => {
-      if (index % 2 === 0) {
-        return true
-      }
-    }
-  )*/
-
   const orderOptions = [
     { value: 'price-asc', label: 'Harga Terendah' },
     { value: 'price-desc', label: 'Harga Tertinggi' },
@@ -309,6 +295,21 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => {
       <DesktopView>
         <div className='container mx-auto flex mb-3'>
           <div className='w-3/12'>
+            <div className='p-4'>
+              <div className='text-caption-1 text-gray_r-11 mb-2'>Produk dari brand:</div>
+              {brand?.data?.logo && (
+                <Image
+                  src={brand?.data?.logo}
+                  alt={brand?.data?.name}
+                  className='w-32 p-2 border borde-gray_r-6 rounded'
+                />
+              )}
+              {!brand?.data?.logo && (
+                <div className='bg-danger-500 text-white text-center text-body-1 py-2 px-4 rounded w-fit'>
+                  {brand?.data?.name}
+                </div>
+              )}
+            </div>
             <ProductFilterDesktop
               brands={brands || []}
               categories={categories || []}
-- 
cgit v1.2.3


From 4310c68248520d265879fbc0a2fc094f7f3e3b52 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Fri, 20 Oct 2023 15:06:08 +0700
Subject: feedback testing - filter by brand (ada brand lain yang ikut)

---
 src/lib/product/components/ProductSearch.jsx | 35 +++++++++++++++-------------
 1 file changed, 19 insertions(+), 16 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 630e3a74..d094a25b 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -28,7 +28,7 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
   if (defaultBrand) query.brand = defaultBrand.toLowerCase()
   const { productSearch } = useProductSearch({
     query: { ...query, q, limit, orderBy },
-    operation: router?.pathname?.includes('brands') ? 'OR' : 'AND'
+    operation: 'OR' 
   })
   const [products, setProducts] = useState(null)
   const [spellings, setSpellings] = useState(null)
@@ -295,21 +295,24 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
       <DesktopView>
         <div className='container mx-auto flex mb-3'>
           <div className='w-3/12'>
-            <div className='p-4'>
-              <div className='text-caption-1 text-gray_r-11 mb-2'>Produk dari brand:</div>
-              {brand?.data?.logo && (
-                <Image
-                  src={brand?.data?.logo}
-                  alt={brand?.data?.name}
-                  className='w-32 p-2 border borde-gray_r-6 rounded'
-                />
-              )}
-              {!brand?.data?.logo && (
-                <div className='bg-danger-500 text-white text-center text-body-1 py-2 px-4 rounded w-fit'>
-                  {brand?.data?.name}
-                </div>
-              )}
-            </div>
+            {brand && (
+              <div className='p-4'>
+                <div className='text-caption-1 text-gray_r-11 mb-2'>Produk dari brand:</div>
+                {brand?.data?.logo && (
+                  <Image
+                    src={brand?.data?.logo}
+                    alt={brand?.data?.name}
+                    className='w-32 p-2 border borde-gray_r-6 rounded'
+                  />
+                )}
+                {!brand?.data?.logo && (
+                  <div className='bg-danger-500 text-white text-center text-body-1 py-2 px-4 rounded w-fit'>
+                    {brand?.data?.name}
+                  </div>
+                )}
+              </div>
+            )}
+
             <ProductFilterDesktop
               brands={brands || []}
               categories={categories || []}
-- 
cgit v1.2.3


From 8d2d384509cd21fb76aeec76d82f362995e4851e Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Mon, 23 Oct 2023 15:40:04 +0700
Subject: bugs fix query solr filter brand dan category

---
 src/lib/product/components/ProductSearch.jsx | 2 +-
 1 file changed, 1 insertion(+), 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 d094a25b..79df93f4 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -28,7 +28,7 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
   if (defaultBrand) query.brand = defaultBrand.toLowerCase()
   const { productSearch } = useProductSearch({
     query: { ...query, q, limit, orderBy },
-    operation: 'OR' 
+    operation: 'AND' 
   })
   const [products, setProducts] = useState(null)
   const [spellings, setSpellings] = useState(null)
-- 
cgit v1.2.3


From 84d81890283155056c26058df65939f4837b14b4 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Mon, 23 Oct 2023 15:48:06 +0700
Subject: CR UI - change label if product not found

---
 src/lib/product/components/ProductSearch.jsx | 4 ++--
 1 file changed, 2 insertions(+), 2 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 79df93f4..5fc75930 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -28,7 +28,7 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
   if (defaultBrand) query.brand = defaultBrand.toLowerCase()
   const { productSearch } = useProductSearch({
     query: { ...query, q, limit, orderBy },
-    operation: 'AND' 
+    operation: 'AND'
   })
   const [products, setProducts] = useState(null)
   const [spellings, setSpellings] = useState(null)
@@ -148,7 +148,7 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
   const SpellingComponent = useMemo(() => {
     return (
       <>
-        Mungkin yang anda cari{' '}
+        {spellings?.length > 0 ? <>Mungkin yang anda cari </> : <>Produk yang anda tidak ada</>}
         {spellings?.map((spelling, i) => (
           <Link href={`/shop/search?q=${spelling}`} key={i} className='inline'>
             {spelling}
-- 
cgit v1.2.3


From 7c08e60acc68f4fbd3ff6af756aeae7c1e7b866c Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Tue, 24 Oct 2023 10:02:44 +0700
Subject: change label

---
 src/lib/product/components/ProductSearch.jsx | 2 +-
 1 file changed, 1 insertion(+), 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 5fc75930..3740d264 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -148,7 +148,7 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
   const SpellingComponent = useMemo(() => {
     return (
       <>
-        {spellings?.length > 0 ? <>Mungkin yang anda cari </> : <>Produk yang 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}
-- 
cgit v1.2.3

