From 51726bd7e8e69535590d70327ebd340ffaf96abd Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Wed, 25 Oct 2023 09:50:46 +0700 Subject: show brand logo di page search --- src/lib/product/components/ProductSearch.jsx | 36 +++++++++++++++++++++++++++- src/pages/api/shop/brands.js | 6 ++++- 2 files changed, 40 insertions(+), 2 deletions(-) (limited to 'src') 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) => ( {spelling} @@ -331,6 +354,17 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) )} + {isBrand && isBrand.logo && ( +
+

Brand Pencarian {q}

+ +
+ )} +

Hasil Pencarian

Date: Mon, 30 Oct 2023 09:30:25 +0700 Subject: show brand logo in page search if search is brand --- src/lib/product/components/ProductSearch.jsx | 9 ++------- src/pages/api/shop/brands.js | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx index 50936d9a..190d026b 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -86,13 +86,8 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) 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) - } - }) - } + setIsBrand(brand?.data[0]) + } checkIfBrand() }, [q]) diff --git a/src/pages/api/shop/brands.js b/src/pages/api/shop/brands.js index 85ebee56..2025da70 100644 --- a/src/pages/api/shop/brands.js +++ b/src/pages/api/shop/brands.js @@ -13,9 +13,9 @@ export default async function handler(req, res) { params = 'level_s:prioritas' break case 'search': - params = `{!func}strdist(name_s, "${req?.query?.q}",edit)` + params = `name_s:${req?.query?.q}` sort = '' - rows = 10 + rows = 1 break; default: params = `name_s:${req.query.params}` -- cgit v1.2.3 From 63d5528a04ce8a2667c7a4a81e2d43676111c05e Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Mon, 30 Oct 2023 10:13:41 +0700 Subject: logo brand di page search mobile --- src/lib/product/components/ProductSearch.jsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx index 190d026b..b25311cf 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -87,7 +87,6 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/brands?params=search&q=${q}` ) setIsBrand(brand?.data[0]) - } checkIfBrand() }, [q]) @@ -225,6 +224,12 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) {productSearch.isLoading && }
+ {isBrand && isBrand.logo && ( +
+

Brand Pencarian {q}

+ +
+ )}

Produk

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') 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 ? (