diff options
| author | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-09-15 09:32:12 +0700 |
|---|---|---|
| committer | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-09-15 09:32:12 +0700 |
| commit | e5c08cb213d0c6dbfa5a931e03eeccac518ddba1 (patch) | |
| tree | ba9dbba7ae89c35d01bc4bb3f92d09de53f06385 /src/core/components | |
| parent | f90ec98c509fad7146c169d8d762b4c847d07af8 (diff) | |
change get product odoo to solr di page navbar & basiclayout & bugfix redirect login next page null
Diffstat (limited to 'src/core/components')
| -rw-r--r-- | src/core/components/elements/Navbar/NavbarDesktop.jsx | 37 | ||||
| -rw-r--r-- | src/core/components/layouts/BasicLayout.jsx | 17 |
2 files changed, 35 insertions, 19 deletions
diff --git a/src/core/components/elements/Navbar/NavbarDesktop.jsx b/src/core/components/elements/Navbar/NavbarDesktop.jsx index 655c4732..2e4b25fc 100644 --- a/src/core/components/elements/Navbar/NavbarDesktop.jsx +++ b/src/core/components/elements/Navbar/NavbarDesktop.jsx @@ -22,6 +22,7 @@ import productApi from '@/lib/product/api/productApi' import { useSession } from 'next-auth/react' import { AuthContext } from '@/pages/_app' import { TopBannerSkeleton } from '../Skeleton/TopBannerSkeleton' +import { useProductContext } from '@/contexts/ProductContext' const Search = dynamic(() => import('./Search')) const TopBanner = dynamic(() => import('./TopBanner'), { @@ -30,7 +31,7 @@ const TopBanner = dynamic(() => import('./TopBanner'), { const NavbarDesktop = () => { const [isOpenCategory, setIsOpenCategory] = useState(false) - const {authenticated} = useContext(AuthContext) + const { authenticated } = useContext(AuthContext) const auth = useAuth() const [cartCount, setCartCount] = useState(0) @@ -40,7 +41,22 @@ const NavbarDesktop = () => { const [urlPath, setUrlPath] = useState(null) const router = useRouter() - + + const { product } = useProductContext() + + useEffect(() => { + if (router.pathname === '/shop/product/[slug]') { + setPayloadWa({ + name: product?.name, + manufacture: product?.manufacture.name, + url: createSlug('/shop/product/', product?.name, product?.id, true) + }) + setTemplateWA('product') + + setUrlPath(router.asPath) + } + }, [product, router]) + useEffect(() => { const handleCartChange = () => { const cart = async () => { @@ -52,23 +68,6 @@ const NavbarDesktop = () => { handleCartChange() window.addEventListener('localStorageChange', handleCartChange) - if (router.pathname === '/shop/product/[slug]') { - const authToken = getAuth().token - - const { slug } = router.query - const getProduct = async () => { - let product = await productApi({ id: getIdFromSlug(slug), headers: { Token: authToken } }) - setPayloadWa({ - name: product[0]?.name, - manufacture: product[0]?.manufacture.name, - url: createSlug('/shop/product/', product[0]?.name, product[0]?.id, true) - }) - } - getProduct() - setTemplateWA('product') - - setUrlPath(router.asPath) - } return () => { window.removeEventListener('localStorageChange', handleCartChange) diff --git a/src/core/components/layouts/BasicLayout.jsx b/src/core/components/layouts/BasicLayout.jsx index 266223d8..030f916c 100644 --- a/src/core/components/layouts/BasicLayout.jsx +++ b/src/core/components/layouts/BasicLayout.jsx @@ -11,6 +11,7 @@ import { getAuth, setAuth } from '@/core/utils/auth' import { createSlug, getIdFromSlug } from '@/core/utils/slug' import { useSession } from 'next-auth/react' import { setCookie } from 'cookies-next' +import { useProductContext } from '@/contexts/ProductContext' const Navbar = dynamic(() => import('../elements/Navbar/Navbar')) const AnimationLayout = dynamic(() => import('./AnimationLayout')) @@ -22,6 +23,22 @@ const BasicLayout = ({ children }) => { const router = useRouter() + const { product } = useProductContext() + + useEffect(() => { + if (router.pathname === '/shop/product/[slug]') { + setPayloadWa({ + name: product?.name, + manufacture: product?.manufacture.name, + url: createSlug('/shop/product/', product?.name, product?.id, true) + }) + setTemplateWA('product') + + setUrlPath(router.asPath) + } + }, [product, router]) + + useEffect(() => { const getIP = async () => { const ip = await odooApi('GET', '/api/ip-address') |
