From 565f6b280b3c4686ad27fdccd05d62d286a30d66 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" 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') 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 = ({ }) => (
- {brandValues.map((value, index) => ( + {brandValues?.map((value, index) => ( {value} handleDeleteFilter('brands', value)} /> ))} - {categoryValues.map((value, index) => ( + {categoryValues?.map((value, index) => ( {value} handleDeleteFilter('category', value)} /> @@ -519,7 +524,7 @@ const FilterChoicesComponent = ({ handleDeleteFilter('price', priceFrom)} /> )} - {brandValues.length > 0 || categoryValues.length > 0 || priceFrom || priceTo ? ( + {brandValues?.length > 0 || categoryValues?.length > 0 || priceFrom || priceTo ? (