summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/product/components/ProductSearch.jsx36
-rw-r--r--src/pages/api/shop/brands.js6
2 files changed, 40 insertions, 2 deletions
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}
diff --git a/src/pages/api/shop/brands.js b/src/pages/api/shop/brands.js
index e93fe2c9..85ebee56 100644
--- a/src/pages/api/shop/brands.js
+++ b/src/pages/api/shop/brands.js
@@ -12,6 +12,11 @@ export default async function handler(req, res) {
case 'level_s':
params = 'level_s:prioritas'
break
+ case 'search':
+ params = `{!func}strdist(name_s, "${req?.query?.q}",edit)`
+ sort = ''
+ rows = 10
+ break;
default:
params = `name_s:${req.query.params}`
}
@@ -20,7 +25,6 @@ export default async function handler(req, res) {
process.env.SOLR_HOST +
`/solr/brands/select?q=${params}&q.op=OR&indent=true&rows=${rows}&${sort}`
)
-
let dataBrands = responseMap(brands.data.response.docs)
res.status(200).json(dataBrands)