summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortrisusilo <tri.susilo@altama.co.id>2023-10-30 02:32:42 +0000
committertrisusilo <tri.susilo@altama.co.id>2023-10-30 02:32:42 +0000
commit3196c41e81bce2f012e245e44beb689dcd1fc853 (patch)
tree25f9169a48fabcdcabb4da2621f1196b840241a3 /src/lib
parente8c414325a1e32474e740cc6e7dca8396affc5e3 (diff)
parent0a1413aec32fddc433a34bf7d03d8681dedc266d (diff)
Merged in CR/UI (pull request #111)
CR/UI
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/product/components/ProductSearch.jsx33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx
index d094a25b..190d026b 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()
@@ -28,12 +30,13 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
if (defaultBrand) query.brand = defaultBrand.toLowerCase()
const { productSearch } = useProductSearch({
query: { ...query, q, limit, orderBy },
- operation: 'OR'
+ operation: 'AND'
})
const [products, setProducts] = useState(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,17 @@ 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}`
+ )
+ setIsBrand(brand?.data[0])
+
+ }
+ checkIfBrand()
+ }, [q])
+
const brands = []
for (
let i = 0;
@@ -148,7 +162,11 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null })
const SpellingComponent = useMemo(() => {
return (
<>
- Mungkin yang anda cari{' '}
+ {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 +349,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}