Skip to content

Commit 8c60b50

Browse files
committed
feat: added v2 notice
1 parent 36f65fc commit 8c60b50

File tree

5 files changed

+69
-5
lines changed

5 files changed

+69
-5
lines changed

src/components/Layout/index.jsx

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
import React, { useContext } from 'react';
2-
import { graphql, useStaticQuery, navigate } from 'gatsby';
2+
import { graphql, navigate, useStaticQuery } from 'gatsby';
33
import { CssBaseline } from '@mui/material';
44
import Alert from '@mui/material/Alert';
55
import { createTheme, ThemeProvider } from '@mui/material/styles';
66
import Button from '@mui/material/Button';
77
import Typography from '@mui/material/Typography';
8+
import Dialog from '@mui/material/Dialog';
9+
import DialogActions from '@mui/material/DialogActions';
10+
import DialogContent from '@mui/material/DialogContent';
11+
import DialogContentText from '@mui/material/DialogContentText';
12+
import DialogTitle from '@mui/material/DialogTitle';
813
import DefaultAppBar from '../DefaultAppBar';
914
import Footer from '../Footer';
1015
import { MainContext } from '../../contexts/MainContextProvider';
1116
import ThemeSelector from '../../utils/ThemeSelector';
1217
import './index.css';
13-
import { setHasAcceptedCookieNotice } from '../../reducers/MainReducer/Actions';
18+
import { disableV2Notice, setHasAcceptedCookieNotice } from '../../reducers/MainReducer/Actions';
1419

1520
const Layout = ({ children }) => {
1621
const [state, dispatch] = useContext(MainContext);
17-
const { themeIndex, themeColorIndex, hasAcceptedCookieNotice } = state;
22+
const {
23+
themeIndex, themeColorIndex, hasAcceptedCookieNotice, hasTriedVersion2,
24+
} = state;
1825
const data = useStaticQuery(graphql`query {
1926
site {
2027
siteMetadata {
@@ -41,15 +48,29 @@ const Layout = ({ children }) => {
4148
});
4249

4350
/**
44-
* Accept cookies
51+
* Accept the cookie notice
4552
*/
4653
const acceptCookies = () => {
4754
dispatch(setHasAcceptedCookieNotice(true));
4855
};
4956

5057
/**
51-
* Go to the GDPR site
58+
* Disable the new version of the site
5259
*/
60+
const disableV2 = () => {
61+
dispatch(disableV2Notice());
62+
};
63+
64+
/**
65+
* Go to the new version of the site
66+
*/
67+
const tryV2 = () => {
68+
window.location.href = window.location.href.replace('codedead.com', 'v2.codedead.com');
69+
};
70+
71+
/**
72+
* Go to the GDPR site
73+
*/
5374
const gotoGdpr = () => {
5475
navigate('https://commission.europa.eu/resources-partners/europa-web-guide_en');
5576
};
@@ -59,6 +80,35 @@ const Layout = ({ children }) => {
5980
<CssBaseline />
6081
<DefaultAppBar title={data.site.siteMetadata.title} />
6182
{children}
83+
{!hasTriedVersion2 ? (
84+
<Dialog
85+
open={!hasTriedVersion2}
86+
onClose={disableV2}
87+
aria-labelledby="v2-alert-dialog-title"
88+
aria-describedby="v2-alert-dialog-description"
89+
>
90+
<DialogTitle id="alert-dialog-title">
91+
New website design!
92+
</DialogTitle>
93+
<DialogContent>
94+
<DialogContentText id="v2-alert-dialog-description">
95+
We&apos;re redesigning our website to make it more user-friendly
96+
and visually appealing.
97+
98+
Keep in mind that this is still a work in progress and some
99+
features may not be available yet.
100+
101+
Would you like to try the new design?
102+
</DialogContentText>
103+
</DialogContent>
104+
<DialogActions>
105+
<Button onClick={disableV2}>No</Button>
106+
<Button onClick={tryV2} autoFocus>
107+
Yes please!
108+
</Button>
109+
</DialogActions>
110+
</Dialog>
111+
) : null}
62112
{hasAcceptedCookieNotice ? null : (
63113
<Alert
64114
severity="warning"

src/contexts/MainContextProvider/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const initState = {
1616
},
1717
blogLimit: 0,
1818
hasAcceptedCookieNotice,
19+
hasTriedVersion2: false,
1920
};
2021

2122
export const MainContext = createContext(initState);

src/reducers/MainReducer/Actions/actionTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export const SET_PAGE_INDEX = 'SET_PAGE_INDEX';
22
export const SET_THEME_INDEX = 'SET_THEME_INDEX';
33
export const SET_BLOG_LIMIT = 'SET_BLOG_LIMIT';
44
export const SET_HAS_ACCEPTED_COOKIE_NOTICE = 'HAS_ACCEPTED_COOKIE_NOTICE';
5+
export const DISABLE_V2_NOTICE = 'DISABLE_V2_NOTICE';

src/reducers/MainReducer/Actions/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
DISABLE_V2_NOTICE,
23
SET_BLOG_LIMIT,
34
SET_HAS_ACCEPTED_COOKIE_NOTICE,
45
SET_PAGE_INDEX,
@@ -24,3 +25,8 @@ export const setHasAcceptedCookieNotice = (hasAccepted) => ({
2425
type: SET_HAS_ACCEPTED_COOKIE_NOTICE,
2526
payload: hasAccepted,
2627
});
28+
29+
export const disableV2Notice = () => ({
30+
type: DISABLE_V2_NOTICE,
31+
payload: true,
32+
});

src/reducers/MainReducer/index.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
DISABLE_V2_NOTICE,
23
SET_BLOG_LIMIT,
34
SET_HAS_ACCEPTED_COOKIE_NOTICE,
45
SET_PAGE_INDEX,
@@ -29,6 +30,11 @@ const MainReducer = (state, action) => {
2930
...state,
3031
hasAcceptedCookieNotice: action.payload,
3132
};
33+
case DISABLE_V2_NOTICE:
34+
return {
35+
...state,
36+
hasTriedVersion2: action.payload,
37+
};
3238
default:
3339
return state;
3440
}

0 commit comments

Comments
 (0)