-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7008 from uktrade/feat/export-wins-review-cookie-…
…page Feat/export wins review cookie page
- Loading branch information
Showing
19 changed files
with
581 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { TASK__START } from '../../actions' | ||
import multiinstance from '../../utils/multiinstance' | ||
|
||
export default multiinstance({ | ||
name: 'Task/RecentResult', | ||
actionPattern: /.*/, | ||
idProp: 'name', | ||
reducer: (state, { type, id, onSuccessDispatch, result }) => { | ||
switch (type) { | ||
case TASK__START: | ||
return { | ||
...state, | ||
[id]: { | ||
...state?.[id], | ||
successActionType: onSuccessDispatch, | ||
}, | ||
} | ||
case state?.[id]?.successActionType: | ||
return { | ||
...state, | ||
[id]: { result }, | ||
} | ||
default: | ||
return state | ||
} | ||
}, | ||
component: ({ children, id, ...props }) => children(props[id]?.result), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react' | ||
import { H2 } from 'govuk-react' | ||
|
||
import { FieldRadios, Form } from '../../../../components' | ||
import Layout from '../Layout' | ||
|
||
const CookiePage = () => ( | ||
<Layout title="Export Wins cookie policy"> | ||
<H2>How cookies are used in Export Wins</H2> | ||
<p>Export wins puts small files (known as 'cookies') onto your computer.</p> | ||
<p> | ||
Cookies are used to measure how to use the website so it can be updated | ||
and improved based on your needs. | ||
</p> | ||
<p> | ||
Export Wins cookies never contain personally identifiable information. | ||
</p> | ||
<H2>Analytics cookies</H2> | ||
<p> | ||
We use Google Analytics software to collect information about how you use | ||
Export Wins. We do this to help make sure the site is meeting the needs of | ||
its users and to help us make improvements. Google Analytics stores | ||
information about: | ||
</p> | ||
<ul> | ||
<li>the pages you visit</li> | ||
<li>how long you spend on each page</li> | ||
<li>how you got to the site</li> | ||
<li>what you click on while you're visiting the site</li> | ||
</ul> | ||
<p>We don't allow Google to use or share our analytics data.</p> | ||
<Form | ||
analyticsFormName="cookie-page-form" | ||
id="cookieConsent" | ||
submissionTaskName="save cookie preference" | ||
initialValuesTaskName="load cookie preference" | ||
submissionTaskResultToValues={(cookieConsent) => ({ cookieConsent })} | ||
transformInitialValues={(cookieConsent) => ({ cookieConsent })} | ||
transformPayload={({ cookieConsent }) => cookieConsent} | ||
submitButtonLabel="Save cookie settings" | ||
> | ||
<FieldRadios | ||
label="Do you want to accept analytics cookies?" | ||
name="cookieConsent" | ||
required="Choose one option" | ||
options={[ | ||
{ label: 'Yes', value: 'granted' }, | ||
{ label: 'No', value: 'denied' }, | ||
]} | ||
/> | ||
</Form> | ||
</Layout> | ||
) | ||
|
||
export default CookiePage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { put, take } from 'redux-saga/effects' | ||
import { eventChannel } from 'redux-saga' | ||
|
||
const storageChannel = eventChannel((emit) => { | ||
window.addEventListener('storage', emit) | ||
return () => window.removeEventListener(emit) | ||
}) | ||
|
||
/** | ||
* This ensures that when the user sets their cookie preference | ||
* in one browser tab, all the other tabs will pick up the change. | ||
*/ | ||
// TODO: Once Redux state is persisted in session storage, this should not be needed | ||
export function* cookiePreferenceChangeSaga() { | ||
while (true) { | ||
const { key, newValue } = yield take(storageChannel) | ||
if (key === 'cookie-consent') { | ||
yield put({ | ||
type: 'RESOURCE', | ||
name: 'load cookie preference', | ||
id: 'cookieConsent', | ||
result: newValue, | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Cookies from 'js-cookie' | ||
|
||
export const COOKIE_CONSENT_COOKIE_NAME = 'cookie-consent' | ||
export const GRANTED = 'granted' | ||
export const DENIED = 'denied' | ||
|
||
export const loadCookiePreference = () => | ||
localStorage.getItem(COOKIE_CONSENT_COOKIE_NAME) | ||
|
||
export const saveCookiePreference = (payload) => { | ||
if (!window.gtag) { | ||
throw Error( | ||
'window.gtag not defined, you probably forgot to set the GOOGLE_TAG_MANAGER_KEY env var.' | ||
) | ||
} | ||
if (![GRANTED, DENIED].includes(payload)) { | ||
throw Error('Payload must be "granted" or "denied"') | ||
} | ||
|
||
localStorage.setItem(COOKIE_CONSENT_COOKIE_NAME, payload) | ||
|
||
window.gtag('consent', 'update', { | ||
analytics_storage: payload, | ||
}) | ||
|
||
if (payload === DENIED) { | ||
for (const cookieName in Cookies.get()) { | ||
Cookies.remove(cookieName) | ||
} | ||
} | ||
|
||
return payload | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.