From 8bd2a7af5d5ba57a12365383e3fe11bb26ad0ca4 Mon Sep 17 00:00:00 2001 From: Diogo Soares <32431609+DiogoSoaress@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:15:38 +0100 Subject: [PATCH] fix: do not show the CookieBanner in the teaser page --- src/config/routes.ts | 1 + src/contexts/CookieBannerContext.tsx | 7 +++++-- src/pages/_app.tsx | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/config/routes.ts b/src/config/routes.ts index 0ac395db4..f02d52831 100644 --- a/src/config/routes.ts +++ b/src/config/routes.ts @@ -4,6 +4,7 @@ export const AppRoutes = { trademark: '/trademark', token: '/token', terms: '/terms', + teaser: '/teaser', privacy: '/privacy', press: '/press', pass: '/pass', diff --git a/src/contexts/CookieBannerContext.tsx b/src/contexts/CookieBannerContext.tsx index f1196b7c5..7721f5f2f 100644 --- a/src/contexts/CookieBannerContext.tsx +++ b/src/contexts/CookieBannerContext.tsx @@ -1,6 +1,8 @@ import { createContext, useCallback, useContext, useEffect, useState } from 'react' import type { ReactNode } from 'react' import { localItem } from '@/services/Storage/local' +import { usePathname } from 'next/navigation' +import { AppRoutes } from '@/config/routes' const ANALYTICS_PREFERENCE_KEY = 'analyticsPreference' const analyticsPreference = localItem(ANALYTICS_PREFERENCE_KEY) @@ -20,6 +22,7 @@ const CookieBannerContext = createContext<{ }) export const CookieBannerContextProvider = ({ children }: { children: ReactNode }) => { + const pathname = usePathname() const [isBannerOpen, setIsBannerOpen] = useState(false) const [isAnalyticsEnabled, setIsAnalyticsEnabled] = useState(false) @@ -36,12 +39,12 @@ export const CookieBannerContextProvider = ({ children }: { children: ReactNode const preference = analyticsPreference.get() // Open cookie banner if no preference is set - if (preference == null) { + if (preference == null && pathname !== AppRoutes.teaser) { openBanner() } else { setIsAnalyticsEnabled(Boolean(preference)) } - }, [openBanner]) + }, [openBanner, pathname]) const storeIsAnalyticsEnabled = useCallback((preference: boolean) => { analyticsPreference.set(preference) diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index fbf5efa38..33dd964ef 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -68,7 +68,7 @@ const App = ({ {getLayout()} - + {Component.name !== 'TeaserPage' && }