11import React , { useContext } from 'react' ;
2- import { graphql , useStaticQuery } from 'gatsby' ;
2+ import { graphql , useStaticQuery , navigate } from 'gatsby' ;
33import { CssBaseline } from '@material-ui/core' ;
4+ import Alert from '@material-ui/lab/Alert' ;
45import { createMuiTheme , ThemeProvider } from '@material-ui/core/styles' ;
6+ import Button from '@material-ui/core/Button' ;
7+ import Typography from '@material-ui/core/Typography' ;
58import DefaultAppBar from '../DefaultAppBar' ;
69import Footer from '../Footer' ;
710import { MainContext } from '../../contexts/MainContextProvider' ;
811import ThemeSelector from '../../utils/ThemeSelector' ;
912import './index.css' ;
13+ import { setHasAcceptedCookieNotice } from '../../reducers/MainReducer/Actions' ;
1014
1115const Layout = ( { children } ) => {
12- const [ state ] = useContext ( MainContext ) ;
13- const { themeIndex, themeColorIndex } = state ;
16+ const [ state , dispatch ] = useContext ( MainContext ) ;
17+ const { themeIndex, themeColorIndex, hasAcceptedCookieNotice } = state ;
1418 const data = useStaticQuery ( graphql `query {
1519 site {
1620 siteMetadata {
@@ -37,11 +41,53 @@ const Layout = ({ children }) => {
3741 } ,
3842 } ) ;
3943
44+ /**
45+ * Accept cookies
46+ */
47+ const acceptCookies = ( ) => {
48+ dispatch ( setHasAcceptedCookieNotice ( true ) ) ;
49+ } ;
50+
51+ /**
52+ * Go to the GDPR site
53+ */
54+ const gotoGdpr = ( ) => {
55+ navigate ( 'http://ec.europa.eu/ipg/basics/legal/cookies/index_en.htm' ) ;
56+ } ;
57+
4058 return (
4159 < ThemeProvider theme = { theme } >
4260 < CssBaseline />
4361 < DefaultAppBar title = { data . site . siteMetadata . title } />
4462 { children }
63+ { hasAcceptedCookieNotice ? null : (
64+ < Alert
65+ severity = "warning"
66+ style = { { position : 'sticky' , bottom : 0 , marginTop : 10 } }
67+ >
68+ < Typography >
69+ We might use cookies to ensure that we give you the best experience on our website.
70+ If you continue to use this site we will assume that you are happy with it.
71+ </ Typography >
72+
73+ < Button
74+ variant = "contained"
75+ color = "secondary"
76+ onClick = { gotoGdpr }
77+ style = { { marginRight : 5 } }
78+ >
79+ Decline
80+ </ Button >
81+
82+ < Button
83+ variant = "contained"
84+ color = "primary"
85+ onClick = { acceptCookies }
86+ >
87+ Agree
88+ </ Button >
89+ </ Alert >
90+ ) }
4591 < Footer
4692 facebookUrl = { data . site . siteMetadata . facebook }
4793 githubUrl = { data . site . siteMetadata . github }
0 commit comments