diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-04-24 14:31:48 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-04-24 14:31:48 +0700 |
| commit | 81abbbabd11df17b5fe795e725f5841273fbf125 (patch) | |
| tree | 3013c70a9d5af1f1247a874be29131900ea4a27f /src-migrate/modules/popup-information | |
| parent | d2852cb7b157b4ab7f583b8b5dc61480ea400ea0 (diff) | |
<miqdad> Make Popup Banner show in product detail for non auth user
Diffstat (limited to 'src-migrate/modules/popup-information')
| -rw-r--r-- | src-migrate/modules/popup-information/index.tsx | 34 |
1 files changed, 26 insertions, 8 deletions
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} |
