Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft version of cookie consent feature #1615

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"quill-html-edit-button": "^2.2.12",
"react": "18.2.0",
"react-chartjs-2": "^5.2.0",
"react-cookie-consent": "^8.0.1",
"react-dom": "18.2.0",
"react-gtm-module": "2.0.11",
"react-i18next": "^11.17.1",
Expand Down
29 changes: 29 additions & 0 deletions src/components/common/CookieConsentPopup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import CookieConsent from 'react-cookie-consent'
import SubmitButton from './form/SubmitButton'

type CookieConsentPopupProps = {
handleAcceptCookie: () => void
handleDeclineCookie: () => void
}

const CookieConsentPopup = ({
handleAcceptCookie,
handleDeclineCookie,
}: CookieConsentPopupProps) => {
return (
<CookieConsent
enableDeclineButton
// cookieName="PodkrepiConsent"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we going to need the cookie name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no just because the react-cookie-consent library doesn't track it with different name
Screenshot 2023-10-16 171451
Screenshot 2023-10-16 171739

this is the edited version - @igoychev , please review

onAccept={handleAcceptCookie}
onDecline={handleDeclineCookie}
buttonText={<SubmitButton label="I understand" />}
declineButtonText={<SubmitButton label="Decline" color="error" />}
style={{ paddingRight: '30px' }}
buttonStyle={{ background: 'transparent' }}
declineButtonStyle={{ background: 'transparent' }}>
text for cookies
</CookieConsent>
)
}

export default CookieConsentPopup
25 changes: 22 additions & 3 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useState } from 'react'
import { EmotionCache } from '@emotion/cache'
import { CacheProvider } from '@emotion/react'
import { CssBaseline } from '@mui/material'
Expand All @@ -7,7 +8,7 @@ import { appWithTranslation, useTranslation } from 'next-i18next'
import { AppProps } from 'next/app'
import Head from 'next/head'
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import { getCookieConsentValue, Cookies } from 'react-cookie-consent'

import createEmotionCache from 'common/createEmotionCache'
import theme from 'common/theme'
Expand All @@ -24,6 +25,7 @@ import {
globalSnackbarProps,
globalSnackbarContentProps,
} from 'components/client/layout/NotificationSnackBar/props/global'
import CookieConsentPopup from 'components/common/CookieConsentPopup'

// Client-side cache, shared for the whole session of the user in the browser.
const clientSideEmotionCache = createEmotionCache()
Expand All @@ -46,11 +48,24 @@ function CustomApp({
const { i18n } = useTranslation()
const { initialize, trackEvent } = useGTM()

useEffect(() => {
// Init GTM
const handleAcceptCookie = () => {
initialize({
events: { user_lang: i18n.language },
})
}

const handleDeclineCookie = () => {
Cookies.remove('_ga')
Cookies.remove('_gat')
Cookies.remove('_gid')
}

useEffect(() => {
const isConsent = getCookieConsentValue()
// Init GTM
if (isConsent === 'true') {
handleAcceptCookie()
}
}, [])

// Register route change complete event handlers
Expand Down Expand Up @@ -108,6 +123,10 @@ function CustomApp({
</QueryClientProvider>
</SessionProvider>
</ThemeProvider>
<CookieConsentPopup
handleAcceptCookie={handleAcceptCookie}
handleDeclineCookie={handleDeclineCookie}
/>
</CacheProvider>
)
}
Expand Down
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8960,6 +8960,13 @@ __metadata:
languageName: node
linkType: hard

"js-cookie@npm:^2.2.1":
version: 2.2.1
resolution: "js-cookie@npm:2.2.1"
checksum: 9b1fb980a1c5e624fd4b28ea4867bb30c71e04c4484bb3a42766344c533faa684de9498e443425479ec68609e96e27b60614bfe354877c449c631529b6d932f2
languageName: node
linkType: hard

"js-tokens@npm:^3.0.0 || ^4.0.0, js-tokens@npm:^4.0.0":
version: 4.0.0
resolution: "js-tokens@npm:4.0.0"
Expand Down Expand Up @@ -11370,6 +11377,7 @@ __metadata:
quill-html-edit-button: ^2.2.12
react: 18.2.0
react-chartjs-2: ^5.2.0
react-cookie-consent: ^8.0.1
react-dom: 18.2.0
react-gtm-module: 2.0.11
react-i18next: ^11.17.1
Expand Down Expand Up @@ -11823,6 +11831,17 @@ __metadata:
languageName: node
linkType: hard

"react-cookie-consent@npm:^8.0.1":
version: 8.0.1
resolution: "react-cookie-consent@npm:8.0.1"
dependencies:
js-cookie: ^2.2.1
peerDependencies:
react: ">=16"
checksum: c99f3e40e3091c439956498158b5b8906cce170763836d6fade98a06ce667eca25aaf3bc407e10a6fb72fc44e5178a2ebf14cbbe4e1b5684a74b7d7f484bd359
languageName: node
linkType: hard

"react-devtools-inline@npm:4.4.0":
version: 4.4.0
resolution: "react-devtools-inline@npm:4.4.0"
Expand Down