From 7ada2eab1773629a3f74fe1a16ba78227953f912 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Sat, 14 Oct 2023 09:03:10 +0700 Subject: add fillterby brand di kolom pencarian --- src/core/components/elements/Navbar/Search.jsx | 42 +++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'src/core/components/elements/Navbar') diff --git a/src/core/components/elements/Navbar/Search.jsx b/src/core/components/elements/Navbar/Search.jsx index f4a8ab3a..e4f89103 100644 --- a/src/core/components/elements/Navbar/Search.jsx +++ b/src/core/components/elements/Navbar/Search.jsx @@ -3,12 +3,18 @@ import { MagnifyingGlassIcon } from '@heroicons/react/24/outline' import { useCallback, useEffect, useRef, useState } from 'react' import Link from '../Link/Link' import { useRouter } from 'next/router' +import { getIdFromSlug, getNameFromSlug } from '@/core/utils/slug' const Search = () => { const router = useRouter() const queryRef = useRef() + const { slug = '' } = router.query const [query, setQuery] = useState(router.query.q || '') const [suggestions, setSuggestions] = useState([]) + const [segment, setSegment] = useState(null) + const [optionSegment, setOptionSegment] = useState(null) + const [optoinSelected, setOptionSelected] = useState(getNameFromSlug(slug) || 'default') + const [pathSegments, setPathSegments] = useState(router?.asPath.split('/') || []) const loadSuggestion = useCallback(() => { if (query && document.activeElement == queryRef.current) { @@ -26,14 +32,29 @@ const Search = () => { } else { setSuggestions([]) } + setFilterSearch() }, [loadSuggestion, query]) const handleSubmit = (e) => { e.preventDefault() - if (query) { - router.push(`/shop/search?q=${query}`) + if (optionSegment && optoinSelected !== 'default' && optoinSelected) { + router.push(`/shop/${segment}/${slug}?q=${query}`) } else { - queryRef.current.focus() + if (query) { + router.push(`/shop/search?q=${query}`) + } else { + queryRef.current.focus() + } + } + } + + const handleSelectChange = async (e) => { + await setOptionSelected(e.target.value) + } + const setFilterSearch = async () => { + if (router.pathname.includes('brands') && pathSegments[3]) { + await setSegment(pathSegments[2]) + await setOptionSegment(getNameFromSlug(slug)) } } @@ -46,10 +67,23 @@ const Search = () => { return ( <>
+ {segment && ( + + )} + setQuery(e.target.value)} -- cgit v1.2.3 From 6aa5fa70cf5ccd2825e5657ec1a90e370dea3bcf Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 16 Oct 2023 11:16:33 +0700 Subject: Fix buy action before and after login --- src/core/components/elements/Navbar/NavbarDesktop.jsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/core/components/elements/Navbar') diff --git a/src/core/components/elements/Navbar/NavbarDesktop.jsx b/src/core/components/elements/Navbar/NavbarDesktop.jsx index fb94e4a6..d9f5658e 100644 --- a/src/core/components/elements/Navbar/NavbarDesktop.jsx +++ b/src/core/components/elements/Navbar/NavbarDesktop.jsx @@ -40,7 +40,7 @@ const NavbarDesktop = () => { const router = useRouter() const { product } = useProductContext() - + useEffect(() => { if (router.pathname === '/shop/product/[slug]') { setPayloadWa({ @@ -110,7 +110,9 @@ const NavbarDesktop = () => {
Quotation - + + + { +