From f62b2345f463695ef0f8f79830cd76b6e0332821 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Sat, 13 Jan 2024 10:35:22 +0700
Subject: Refactor src migrate folder

---
 src/core/components/layouts/BasicLayout.jsx | 82 ++++++++++++++++-------------
 1 file changed, 44 insertions(+), 38 deletions(-)

(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 9441dbd7..2962a08b 100644
--- a/src/core/components/layouts/BasicLayout.jsx
+++ b/src/core/components/layouts/BasicLayout.jsx
@@ -1,55 +1,61 @@
-import dynamic from 'next/dynamic'
-import BasicFooter from '../elements/Footer/BasicFooter'
-import Image from 'next/image'
-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 productApi from '@/lib/product/api/productApi'
-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'
+import dynamic from 'next/dynamic';
+import Image from 'next/image';
+import { useEffect, useState } from 'react';
+import axios from 'axios';
 
-const Navbar = dynamic(() => import('../elements/Navbar/Navbar'))
-const AnimationLayout = dynamic(() => import('./AnimationLayout'))
+import whatsappUrl from '@/core/utils/whatsappUrl';
+import odooApi from '@/core/api/odooApi';
+import { useRouter } from 'next/router';
+import { useProductContext } from '@/contexts/ProductContext';
+
+const Navbar = dynamic(() => import('../elements/Navbar/Navbar'), {
+  ssr: false,
+});
+const AnimationLayout = dynamic(() => import('./AnimationLayout'), {
+  ssr: false,
+});
+const BasicFooter = dynamic(() => import('../elements/Footer/BasicFooter'), {
+  ssr: false,
+});
 
 const BasicLayout = ({ children }) => {
-  const [templateWA, setTemplateWA] = useState(null)
-  const [payloadWA, setPayloadWa] = useState(null)
-  const [urlPath, setUrlPath] = useState(null)
+  const [templateWA, setTemplateWA] = useState(null);
+  const [payloadWA, setPayloadWa] = useState(null);
+  const [urlPath, setUrlPath] = useState(null);
 
-  const router = useRouter()
+  const router = useRouter();
 
-  const { product } = useProductContext()
+  const { product } = useProductContext();
   useEffect(() => {
-    if (router.pathname === '/shop/product/[slug]' || router.pathname === '/shop/product/variant/[slug]') {
+    if (
+      router.pathname === '/shop/product/[slug]' ||
+      router.pathname === '/shop/product/variant/[slug]'
+    ) {
       setPayloadWa({
         name: product?.name,
         manufacture: product?.manufacture.name,
-        url: process.env.NEXT_PUBLIC_SELF_HOST + router.asPath
-      })
-      setTemplateWA('product')
+        url: process.env.NEXT_PUBLIC_SELF_HOST + router.asPath,
+      });
+      setTemplateWA('product');
 
-      setUrlPath(router.asPath)
+      setUrlPath(router.asPath);
     }
-  }, [product, router])
-
+  }, [product, router]);
 
   useEffect(() => {
     const getIP = async () => {
-      const ip = await odooApi('GET', '/api/ip-address')
+      const ip = await odooApi('GET', '/api/ip-address');
       const data = {
         page_title: document.title,
         url: window.location.href,
-        ip: ip
-      }
-      axios.get(`/api/user-activity?page_title=${data.page_title}&url=${data.url}&ip=${data.ip}`)
-    }
-    getIP()
-  }, [])
+        ip: ip,
+      };
+      axios.get(
+        `/api/user-activity?page_title=${data.page_title}&url=${data.url}&ip=${data.ip}`
+      );
+    };
+    getIP();
+  }, []);
   return (
     <>
       <Navbar />
@@ -82,7 +88,7 @@ const BasicLayout = ({ children }) => {
       </AnimationLayout>
       <BasicFooter />
     </>
-  )
-}
+  );
+};
 
-export default BasicLayout
+export default BasicLayout;
-- 
cgit v1.2.3


From c0b38013bb97a995148b14301d26996ef15d4c7a Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Thu, 25 Jan 2024 09:15:27 +0700
Subject: Disable user activity log

---
 src/core/components/layouts/BasicLayout.jsx | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

(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 2962a08b..13cdfc86 100644
--- a/src/core/components/layouts/BasicLayout.jsx
+++ b/src/core/components/layouts/BasicLayout.jsx
@@ -42,20 +42,20 @@ const BasicLayout = ({ children }) => {
     }
   }, [product, router]);
 
-  useEffect(() => {
-    const getIP = async () => {
-      const ip = await odooApi('GET', '/api/ip-address');
-      const data = {
-        page_title: document.title,
-        url: window.location.href,
-        ip: ip,
-      };
-      axios.get(
-        `/api/user-activity?page_title=${data.page_title}&url=${data.url}&ip=${data.ip}`
-      );
-    };
-    getIP();
-  }, []);
+  // useEffect(() => {
+  //   const getIP = async () => {
+  //     const ip = await odooApi('GET', '/api/ip-address');
+  //     const data = {
+  //       page_title: document.title,
+  //       url: window.location.href,
+  //       ip: ip,
+  //     };
+  //     axios.get(
+  //       `/api/user-activity?page_title=${data.page_title}&url=${data.url}&ip=${data.ip}`
+  //     );
+  //   };
+  //   getIP();
+  // }, []);
   return (
     <>
       <Navbar />
-- 
cgit v1.2.3


From e35595250f9e0408e23d1da3ac30ac1179e2a376 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Sat, 27 Jan 2024 11:46:36 +0700
Subject: Refactor layout

---
 src/core/components/layouts/BasicLayout.jsx | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

(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 13cdfc86..b6e2c59f 100644
--- a/src/core/components/layouts/BasicLayout.jsx
+++ b/src/core/components/layouts/BasicLayout.jsx
@@ -1,15 +1,14 @@
 import dynamic from 'next/dynamic';
 import Image from 'next/image';
 import { useEffect, useState } from 'react';
-import axios from 'axios';
 
+import { useProductContext } from '@/contexts/ProductContext';
 import whatsappUrl from '@/core/utils/whatsappUrl';
-import odooApi from '@/core/api/odooApi';
 import { useRouter } from 'next/router';
-import { useProductContext } from '@/contexts/ProductContext';
 
 const Navbar = dynamic(() => import('../elements/Navbar/Navbar'), {
   ssr: false,
+  loading: () => <div className='h-[156px]' />,
 });
 const AnimationLayout = dynamic(() => import('./AnimationLayout'), {
   ssr: false,
-- 
cgit v1.2.3


From 41f5aa212c69b61c2b101b682e77c8106849076e Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Fri, 9 Feb 2024 09:35:26 +0700
Subject: Add record activity on product

---
 src/core/components/layouts/BasicLayout.jsx | 39 ++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 15 deletions(-)

(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 b6e2c59f..fa41a8ed 100644
--- a/src/core/components/layouts/BasicLayout.jsx
+++ b/src/core/components/layouts/BasicLayout.jsx
@@ -1,8 +1,9 @@
 import dynamic from 'next/dynamic';
 import Image from 'next/image';
-import { useEffect, useState } from 'react';
+import { useCallback, useEffect, useState } from 'react';
 
 import { useProductContext } from '@/contexts/ProductContext';
+import odooApi from '@/core/api/odooApi';
 import whatsappUrl from '@/core/utils/whatsappUrl';
 import { useRouter } from 'next/router';
 
@@ -41,20 +42,28 @@ const BasicLayout = ({ children }) => {
     }
   }, [product, router]);
 
-  // useEffect(() => {
-  //   const getIP = async () => {
-  //     const ip = await odooApi('GET', '/api/ip-address');
-  //     const data = {
-  //       page_title: document.title,
-  //       url: window.location.href,
-  //       ip: ip,
-  //     };
-  //     axios.get(
-  //       `/api/user-activity?page_title=${data.page_title}&url=${data.url}&ip=${data.ip}`
-  //     );
-  //   };
-  //   getIP();
-  // }, []);
+  const recordActivity = useCallback(async () => {
+    const recordedPath = [
+      '/shop/product/[slug]',
+      '/shop/product/variant/[slug]',
+    ];
+
+    if (!recordedPath.includes(router.pathname)) return;
+
+    const ip = await odooApi('GET', '/api/ip-address');
+    const data = new URLSearchParams({
+      page_title: document.title,
+      url: window.location.href,
+      ip,
+    });
+
+    fetch(`/api/user-activity?${data.toString()}`);
+  }, [router.pathname]);
+
+  useEffect(() => {
+    recordActivity();
+  }, [recordActivity]);
+
   return (
     <>
       <Navbar />
-- 
cgit v1.2.3


From 191f6592375ebac9d1530b67e7100a13a6155239 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Wed, 28 Feb 2024 11:23:54 +0700
Subject: Enable record activity log on all page

---
 src/core/components/layouts/BasicLayout.jsx | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

(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 fa41a8ed..13f4af76 100644
--- a/src/core/components/layouts/BasicLayout.jsx
+++ b/src/core/components/layouts/BasicLayout.jsx
@@ -42,13 +42,10 @@ const BasicLayout = ({ children }) => {
     }
   }, [product, router]);
 
-  const recordActivity = useCallback(async () => {
-    const recordedPath = [
-      '/shop/product/[slug]',
-      '/shop/product/variant/[slug]',
-    ];
-
-    if (!recordedPath.includes(router.pathname)) return;
+  const recordActivity = async (pathname) => {
+    const ONLY_ON_PATH = false;
+    const recordedPath = [];
+    if (ONLY_ON_PATH && !recordedPath.includes(pathname)) return;
 
     const ip = await odooApi('GET', '/api/ip-address');
     const data = new URLSearchParams({
@@ -58,11 +55,11 @@ const BasicLayout = ({ children }) => {
     });
 
     fetch(`/api/user-activity?${data.toString()}`);
-  }, [router.pathname]);
+  };
 
   useEffect(() => {
-    recordActivity();
-  }, [recordActivity]);
+    recordActivity(router.pathname);
+  }, [router.pathname]);
 
   return (
     <>
-- 
cgit v1.2.3


From 58267593b6214ecc37489802729a5702116794af Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Thu, 29 Feb 2024 15:31:16 +0700
Subject: Update flashsale section

---
 src/core/components/layouts/BasicLayout.jsx | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

(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 13f4af76..a4f3a856 100644
--- a/src/core/components/layouts/BasicLayout.jsx
+++ b/src/core/components/layouts/BasicLayout.jsx
@@ -1,16 +1,13 @@
 import dynamic from 'next/dynamic';
 import Image from 'next/image';
-import { useCallback, useEffect, useState } from 'react';
+import { useRouter } from 'next/router';
+import { useEffect, useState } from 'react';
 
 import { useProductContext } from '@/contexts/ProductContext';
 import odooApi from '@/core/api/odooApi';
 import whatsappUrl from '@/core/utils/whatsappUrl';
-import { useRouter } from 'next/router';
+import Navbar from '../elements/Navbar/Navbar';
 
-const Navbar = dynamic(() => import('../elements/Navbar/Navbar'), {
-  ssr: false,
-  loading: () => <div className='h-[156px]' />,
-});
 const AnimationLayout = dynamic(() => import('./AnimationLayout'), {
   ssr: false,
 });
-- 
cgit v1.2.3

