Skip to content

Commit

Permalink
fix: do not show the CookieBanner in the teaser page
Browse files Browse the repository at this point in the history
  • Loading branch information
DiogoSoaress committed Nov 8, 2024
1 parent b09cd0f commit 8bd2a7a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/config/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const AppRoutes = {
trademark: '/trademark',
token: '/token',
terms: '/terms',
teaser: '/teaser',
privacy: '/privacy',
press: '/press',
pass: '/pass',
Expand Down
7 changes: 5 additions & 2 deletions src/contexts/CookieBannerContext.tsx
Original file line number Diff line number Diff line change
@@ -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<boolean>(ANALYTICS_PREFERENCE_KEY)
Expand All @@ -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)

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const App = ({

<SearchParamsContextProvider>{getLayout(<Component {...pageProps} />)}</SearchParamsContextProvider>

<CookieBanner />
{Component.name !== 'TeaserPage' && <CookieBanner />}
</CookieBannerContextProvider>
</CssVarsProvider>
</CacheProvider>
Expand Down

0 comments on commit 8bd2a7a

Please sign in to comment.