From abb8427022e2cf509fe5e34e677d263a9d920dcc Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Mon, 24 Jul 2023 15:07:37 +0700
Subject: wa text product

---
 src/core/components/layouts/BasicLayout.jsx | 31 ++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

(limited to 'src/core/components/layouts/BasicLayout.jsx')

diff --git a/src/core/components/layouts/BasicLayout.jsx b/src/core/components/layouts/BasicLayout.jsx
index 70482e12..073303fe 100644
--- a/src/core/components/layouts/BasicLayout.jsx
+++ b/src/core/components/layouts/BasicLayout.jsx
@@ -5,11 +5,21 @@ import whatsappUrl from '@/core/utils/whatsappUrl'
 import { useEffect, useState } from 'react'
 import axios from 'axios'
 import odooApi from '@/core/api/odooApi'
+import { useRouter } from 'next/router'
+import { getURL } from 'next/dist/shared/lib/utils'
+import productApi from '@/lib/product/api/productApi'
+import { getAuth } from '@/core/utils/auth'
+import { createSlug, getIdFromSlug } from '@/core/utils/slug'
 
 const Navbar = dynamic(() => import('../elements/Navbar/Navbar'))
 const AnimationLayout = dynamic(() => import('./AnimationLayout'))
 
 const BasicLayout = ({ children }) => {
+  const [templateWA, setTemplateWA] = useState(null)
+  const [payloadWA, setPayloadWa] = useState(null)
+
+  const router = useRouter()
+
   useEffect(() => {
     const getIP = async () => {
       const ip = await odooApi('GET', '/api/ip-address')
@@ -21,6 +31,23 @@ 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 } })
+        console.log('ini product', product)
+        setPayloadWa({
+          name: product[0]?.name,
+          manufacture: product[0]?.manufacture.name,
+          url: createSlug('/shop/product/', product[0]?.name, product[0]?.id, true)
+        })
+      }
+      getProduct()
+      setTemplateWA('product')
+     
+    }
   }, [])
   return (
     <>
@@ -29,8 +56,10 @@ const BasicLayout = ({ children }) => {
         {children}
         <div className='fixed bottom-4 right-4 sm:bottom-14 sm:right-10 z-50'>
           <a
-            href={whatsappUrl(null)}
+            href={whatsappUrl(templateWA, payloadWA)}
             className='py-2 pl-3 pr-4 rounded-full bg-[#4FB84A] border border-green-300 flex items-center'
+            rel='noopener noreferrer'
+            target='_blank'
           >
             <Image
               src='/images/socials/WHATSAPP.svg'
-- 
cgit v1.2.3

