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 +++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src/lib') 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