diff options
Diffstat (limited to 'src/core/components/layouts/BasicLayout.jsx')
| -rw-r--r-- | src/core/components/layouts/BasicLayout.jsx | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/core/components/layouts/BasicLayout.jsx b/src/core/components/layouts/BasicLayout.jsx index 266223d8..e6bd4de0 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') @@ -33,23 +50,6 @@ const BasicLayout = ({ children }) => { axios.get(`/api/user-activity?page_title=${data.page_title}&url=${data.url}&ip=${data.ip}`) } getIP() - 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 ( <> |
