summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHATEC\SPVDEV001 <tri.susilo@altama.co.id>2023-10-30 13:35:12 +0700
committerHATEC\SPVDEV001 <tri.susilo@altama.co.id>2023-10-30 13:35:12 +0700
commit565f6b280b3c4686ad27fdccd05d62d286a30d66 (patch)
tree8257478ad0afdad454fc1d13f04da81ddd30cc20
parent63d5528a04ce8a2667c7a4a81e2d43676111c05e (diff)
fixing speling search
-rw-r--r--src/lib/product/components/ProductSearch.jsx15
1 files changed, 10 insertions, 5 deletions
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'