From 637c22f1886cecf7307ced88dc951134d466a3fa Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Mon, 19 Jun 2023 15:46:03 +0700
Subject: checkout

---
 src/core/components/elements/Navbar/NavbarDesktop.jsx | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

(limited to 'src/core/components/elements/Navbar/NavbarDesktop.jsx')

diff --git a/src/core/components/elements/Navbar/NavbarDesktop.jsx b/src/core/components/elements/Navbar/NavbarDesktop.jsx
index 26edd5a4..733f5422 100644
--- a/src/core/components/elements/Navbar/NavbarDesktop.jsx
+++ b/src/core/components/elements/Navbar/NavbarDesktop.jsx
@@ -13,7 +13,7 @@ import Category from '@/lib/category/components/Category'
 import { useEffect, useState } from 'react'
 import useAuth from '@/core/hooks/useAuth'
 import NavbarUserDropdown from './NavbarUserDropdown'
-import { getCart } from '@/core/utils/cart'
+import { getCountCart } from '@/core/utils/cart'
 import TopBanner from './TopBanner'
 import whatsappUrl from '@/core/utils/whatsappUrl'
 
@@ -27,7 +27,11 @@ const NavbarDesktop = () => {
 
   useEffect(() => {
     const handleCartChange = () => {
-      setCartCount(Object.keys(getCart()).length)
+      const cart = async () => {
+        const listCart = await getCountCart()
+        setCartCount(listCart)
+      }
+      cart()
     }
     handleCartChange()
 
-- 
cgit v1.2.3


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

---
 .../components/elements/Navbar/NavbarDesktop.jsx   | 26 +++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

(limited to 'src/core/components/elements/Navbar/NavbarDesktop.jsx')

diff --git a/src/core/components/elements/Navbar/NavbarDesktop.jsx b/src/core/components/elements/Navbar/NavbarDesktop.jsx
index 26edd5a4..eb1bc48c 100644
--- a/src/core/components/elements/Navbar/NavbarDesktop.jsx
+++ b/src/core/components/elements/Navbar/NavbarDesktop.jsx
@@ -16,6 +16,10 @@ import NavbarUserDropdown from './NavbarUserDropdown'
 import { getCart } from '@/core/utils/cart'
 import TopBanner from './TopBanner'
 import whatsappUrl from '@/core/utils/whatsappUrl'
+import { useRouter } from 'next/router'
+import { getAuth } from '@/core/utils/auth'
+import { createSlug, getIdFromSlug } from '@/core/utils/slug'
+import productApi from '@/lib/product/api/productApi'
 
 const Search = dynamic(() => import('./Search'))
 
@@ -25,6 +29,11 @@ const NavbarDesktop = () => {
 
   const [cartCount, setCartCount] = useState(0)
 
+  const [templateWA, setTemplateWA] = useState(null)
+  const [payloadWA, setPayloadWa] = useState(null)
+
+  const router = useRouter()
+
   useEffect(() => {
     const handleCartChange = () => {
       setCartCount(Object.keys(getCart()).length)
@@ -32,6 +41,21 @@ 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')
+    }
 
     return () => {
       window.removeEventListener('localStorageChange', handleCartChange)
@@ -92,7 +116,7 @@ const NavbarDesktop = () => {
               Wishlist
             </Link>
             <a
-              href={whatsappUrl()}
+              href={whatsappUrl(templateWA, payloadWA)}
               target='_blank'
               rel='noreferrer'
               className='flex items-center gap-x-1 !text-gray_r-12/80'
-- 
cgit v1.2.3

