From 81abbbabd11df17b5fe795e725f5841273fbf125 Mon Sep 17 00:00:00 2001
From: Miqdad <ahmadmiqdad27@gmail.com>
Date: Thu, 24 Apr 2025 14:31:48 +0700
Subject: <miqdad>  Make Popup Banner show in product detail for non auth user

---
 src-migrate/modules/popup-information/index.tsx | 34 +++++++++++++++++++------
 1 file changed, 26 insertions(+), 8 deletions(-)

(limited to 'src-migrate/modules/popup-information/index.tsx')

diff --git a/src-migrate/modules/popup-information/index.tsx b/src-migrate/modules/popup-information/index.tsx
index d50711cc..5c3bc8fa 100644
--- a/src-migrate/modules/popup-information/index.tsx
+++ b/src-migrate/modules/popup-information/index.tsx
@@ -10,11 +10,21 @@ import dynamic from 'next/dynamic';
 const PagePopupInformation = () => {
   const router = useRouter();
   const isHomePage = router.pathname === '/';
+  // Updated to match your URL structure with /shop/product/
+  const isProductDetail = router.pathname.includes('/shop/product/');
   const auth = getAuth();
   const [active, setActive] = useState<boolean>(false);
   const [data, setData] = useState<any>(null);
   const [loading, setLoading] = useState(true);
+  const [hasClosedPopup, setHasClosedPopup] = useState<boolean>(false);
 
+  useEffect(() => {
+    // Check if user has closed the popup in this session
+    const popupClosed = sessionStorage.getItem('popupClosed');
+    if (popupClosed) {
+      setHasClosedPopup(true);
+    }
+  }, []);
 
   useEffect(() => {
     const getData = async () => {
@@ -26,25 +36,33 @@ const PagePopupInformation = () => {
       setLoading(false);
     };
 
-    if (isHomePage && !auth) {
+    // Show popup if user is on homepage OR product detail page AND not authenticated AND hasn't closed popup
+    if ((isHomePage || isProductDetail) && !auth && !hasClosedPopup) {
       setActive(true);
       getData();
     }
-  }, [isHomePage, auth]);
+  }, [isHomePage, isProductDetail, auth, hasClosedPopup]);
+
+  const handleClose = () => {
+    setActive(false);
+    // Set session storage to remember user closed the popup
+    sessionStorage.setItem('popupClosed', 'true');
+  };
+
   return (
     <div className='group'>
       {data && !loading && (
         <Modal
           active={active}
           className='!w-fit !bg-transparent !border-none overflow-hidden'
-          close={() => setActive(false)}
+          close={handleClose}
           mode='desktop'
         >
-          <div
-            className='w-[350px] md:w-[530px]'
-            onClick={() => setActive(false)}
-          >
-            <Link href={data[0].url === false ? '/' :data[0].url} aria-label='popup'>
+          <div className='w-[350px] md:w-[530px]' onClick={handleClose}>
+            <Link
+              href={data[0].url === false ? '/' : data[0].url}
+              aria-label='popup'
+            >
               <Image
                 src={data[0]?.image}
                 alt={data[0]?.name}
-- 
cgit v1.2.3

