-
Notifications
You must be signed in to change notification settings - Fork 1
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 #124 from communitiesuk/cookies-back-link
Cookies back link
- Loading branch information
Showing
7 changed files
with
114 additions
and
82 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "uk_gov_dash_components", | ||
"version": "1.29.0", | ||
"version": "1.29.1", | ||
"description": "Dash components for Gov UK", | ||
"repository": { | ||
"type": "git", | ||
|
@@ -20,7 +20,8 @@ | |
"build:backends": "dash-generate-components ./src/lib/components uk_gov_dash_components -p package-info.json --r-prefix 'govuk' --jl-prefix 'govuk' --ignore \\.test\\.", | ||
"build:backends-activated": "(. venv/bin/activate || venv\\scripts\\activate && npm run build:py_and_r)", | ||
"build": "npm run build:js && npm run build:backends", | ||
"build:activated": "npm run build:js && npm run build:backends-activated" | ||
"build:activated": "npm run build:js && npm run build:backends-activated", | ||
"dist": "npm run build && python setup.py sdist bdist_wheel" | ||
}, | ||
"author": "DLUHC GovUk <[email protected]>", | ||
"license": "MIT", | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,38 @@ | ||
import React from 'react'; | ||
|
||
import { createContext, useState } from "react"; | ||
import { createContext, useState, useEffect } from "react"; | ||
|
||
import Cookies from "js-cookie"; | ||
|
||
export const CookieContext = createContext(); | ||
|
||
export const CookieProvider = ({ children }) => { | ||
const [cookieStateIsSet, setCookieStateIsSet] = useState(false); | ||
const [cookieAccepted, setCookieAccepted] = useState(null); | ||
|
||
const | ||
today = new Date(), | ||
[year, month, day] = [today.getFullYear(), today.getMonth(), today.getDate()], | ||
cookieExpiryDate = new Date(year + 1, month, day).toUTCString(); | ||
|
||
// Set initial cookie values on load | ||
useEffect(() => { | ||
|
||
if (!Cookies.get('cookies_preferences_set')) { | ||
document.cookie = `cookies_preferences_set=false; expires=${cookieExpiryDate}; path=/` | ||
setCookieStateIsSet(false); | ||
} | ||
|
||
if (!Cookies.get('cookies_policy')) { | ||
document.cookie = `cookies_policy=${encodeURIComponent('{"essential":true,"usage":false,"preferences":false}')}; expires=${cookieExpiryDate};`; | ||
setCookieStateIsSet(false); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<CookieContext.Provider value={{ cookieStateIsSet, setCookieStateIsSet, cookieAccepted, setCookieAccepted }}> | ||
{children} | ||
</CookieContext.Provider> | ||
); | ||
}; | ||
}; | ||
|
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.