From a5c1d9514b515e82d19bd6dfd0142c10e5f14cb5 Mon Sep 17 00:00:00 2001 From: Tim Glaser Date: Thu, 2 Jul 2020 14:43:50 -0700 Subject: [PATCH] feat: Add cookies dialog --- src/components/CookieApprovalDialog.js | 85 +++++++++++++++++--------- 1 file changed, 55 insertions(+), 30 deletions(-) diff --git a/src/components/CookieApprovalDialog.js b/src/components/CookieApprovalDialog.js index f4bded451..a44e7d7d7 100644 --- a/src/components/CookieApprovalDialog.js +++ b/src/components/CookieApprovalDialog.js @@ -1,41 +1,66 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import PropTypes from 'prop-types'; +import Cookies from 'js-cookie'; import Button from './Button'; import styles from './CookieApprovalDialog.module.scss'; +const gdprConsentCookieName = 'newrelic-gdpr-consent'; + const CookieApprovalDialog = ({ className }) => { + const [isCookieSet, setIsCookieSet] = useState(true); + + useEffect(() => { + setIsCookieSet(Cookies.get(gdprConsentCookieName) !== undefined); + }, []); + + function writeCookie(answer) { + const currentEnvironment = + process.env.ENV || process.env.NODE_ENV || 'development'; + const options = { expires: 365 /* days */ }; + if (currentEnvironment !== 'development') { + options.domain = 'newrelic.com'; + } + + Cookies.set(gdprConsentCookieName, String(!!answer), options); + setIsCookieSet(true); + } + return ( -
-
-
-

- This site uses cookies{' '} - - 🍪 - -

-

- We rely on cookies to play videos, remember your preferences, and - analyze our website traffic. You consent to our cookies if you click - “OK”. -

-
-
- - + !isCookieSet && ( +
+
+
+

+ This site uses cookies{' '} + + 🍪 + +

+

+ We rely on cookies to play videos, remember your preferences, and + analyze our website traffic. You consent to our cookies if you + click “OK”. +

+
+
+ + +
-
+ ) ); };