File tree Expand file tree Collapse file tree 5 files changed +144
-0
lines changed Expand file tree Collapse file tree 5 files changed +144
-0
lines changed Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import Form from 'react-bootstrap/Form'
3
+ import PropTypes from 'prop-types'
4
+ import { useState } from 'react'
5
+
6
+ const CookiePreferencesCheck = ( { cookieConsentValue, disableCookies, enableCookies } ) => {
7
+ // NOTE: the enable/disable cookies functions change the actual value.
8
+ // the state variable below is so the radio buttons update after being clicked.
9
+ // NOTE: cookie values are strings. we are parsing it in state so we don't have to
10
+ // do strict evaluations (===) with strings in the code below.
11
+ const [ allowed , setAllowed ] = useState ( JSON . parse ( cookieConsentValue ) )
12
+
13
+ const handleEnablingCookies = ( ) => {
14
+ enableCookies ( )
15
+ setAllowed ( true )
16
+ }
17
+
18
+ const handleDisablingCookies = ( ) => {
19
+ disableCookies ( )
20
+ setAllowed ( false )
21
+ }
22
+
23
+ return (
24
+ < Form >
25
+ < Form . Check
26
+ inline
27
+ label = 'Allow Cookies'
28
+ name = 'Allow Cookies'
29
+ type = 'radio'
30
+ id = 'allow-cookies'
31
+ checked = { allowed }
32
+ onChange = { ( ) => handleEnablingCookies ( ) }
33
+ />
34
+ < Form . Check
35
+ inline
36
+ label = 'Disable Cookies'
37
+ name = 'Disable Cookies'
38
+ type = 'radio'
39
+ id = 'disable-cookies'
40
+ checked = { ! allowed }
41
+ onChange = { ( ) => handleDisablingCookies ( ) }
42
+ />
43
+ </ Form >
44
+ ) ;
45
+ }
46
+
47
+ CookiePreferencesCheck . propTypes = {
48
+ cookieConsentValue : PropTypes . string . isRequired ,
49
+ disableCookies : PropTypes . func . isRequired ,
50
+ enableCookies : PropTypes . func . isRequired ,
51
+ }
52
+
53
+ export default CookiePreferencesCheck
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import CookiePreferencesCheck from './CookiePreferencesCheck'
3
+
4
+ export default {
5
+ title : 'Components/CookiePreferencesCheck' ,
6
+ component : CookiePreferencesCheck ,
7
+ }
8
+
9
+ const Template = ( args ) => < CookiePreferencesCheck { ...args } />
10
+
11
+ export const Default = Template . bind ( { } )
12
+ Default . args = {
13
+ cookieConsentValue : false ,
14
+ disableCookies : ( ) => console . log ( 'disable cookies' ) ,
15
+ enableCookies : ( ) => console . log ( 'enable cookies' ) ,
16
+ }
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import Link from 'next/link'
3
+ import PropTypes from 'prop-types'
4
+ import Button from 'react-bootstrap/Button'
5
+ import Modal from 'react-bootstrap/Modal'
6
+ import { useState } from 'react'
7
+
8
+ const CookiePreferencesModal = ( { getCookieConsent, disableCookies, enableCookies } ) => {
9
+ const [ show , setShow ] = useState ( getCookieConsent )
10
+ const handleClose = ( ) => setShow ( false )
11
+
12
+ const handleEnablingCookies = ( ) => {
13
+ enableCookies ( )
14
+ handleClose ( )
15
+ }
16
+
17
+ const handleDisablingCookies = ( ) => {
18
+ disableCookies ( )
19
+ handleClose ( )
20
+ }
21
+
22
+ return (
23
+ < Modal
24
+ show = { show }
25
+ onHide = { handleClose }
26
+ backdrop = 'static'
27
+ keyboard = { false }
28
+ >
29
+ < Modal . Header closeButton >
30
+ < Modal . Title > Cookie Preferences</ Modal . Title >
31
+ </ Modal . Header >
32
+ < Modal . Body >
33
+ Please provide your consent below to our use of non-essential cookies on our site.
34
+ You may withdraw your consent at any point by visiting our < Link href = 'legal-notices/cookie-policy' > Cookie Policy</ Link > page.
35
+ </ Modal . Body >
36
+ < Modal . Footer >
37
+ < Button variant = 'primary' onClick = { handleEnablingCookies } >
38
+ Allow Cookies
39
+ </ Button >
40
+ < Button variant = 'secondary' onClick = { handleDisablingCookies } >
41
+ Disable Cookies
42
+ </ Button >
43
+ </ Modal . Footer >
44
+ </ Modal >
45
+ )
46
+ }
47
+
48
+ CookiePreferencesModal . propTypes = {
49
+ getCookieConsent : PropTypes . bool . isRequired ,
50
+ disableCookies : PropTypes . func . isRequired ,
51
+ enableCookies : PropTypes . func . isRequired ,
52
+ }
53
+
54
+ export default CookiePreferencesModal
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import CookiePreferencesModal from './CookiePreferencesModal'
3
+
4
+ export default {
5
+ title : 'Components/CookiePreferencesModal' ,
6
+ component : CookiePreferencesModal ,
7
+ }
8
+
9
+ const Template = ( args ) => < CookiePreferencesModal { ...args } />
10
+
11
+ export const Default = Template . bind ( { } )
12
+ Default . args = {
13
+ getCookieConsent : true ,
14
+ disableCookies : ( ) => console . log ( 'disable cookies' ) ,
15
+ enableCookies : ( ) => console . log ( 'enable cookies' ) ,
16
+ }
17
+
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ import AdditionalInfo from './AdditionalInfo/AdditionalInfo'
7
7
import BlankRequestForm from './BlankRequestForm/BlankRequestForm'
8
8
import Button from './Button/Button'
9
9
import CollapsibleSection from './CollapsibleSection/CollapsibleSection'
10
+ import CookiePreferencesCheck from './CookiePreferences/CookiePreferencesCheck'
11
+ import CookiePreferencesModal from './CookiePreferences/CookiePreferencesModal'
10
12
import Image from './Image/Image'
11
13
import Link from './Link/Link'
12
14
import Loading from './Loading/Loading'
@@ -23,6 +25,8 @@ export {
23
25
BlankRequestForm ,
24
26
Button ,
25
27
CollapsibleSection ,
28
+ CookiePreferencesCheck ,
29
+ CookiePreferencesModal ,
26
30
Image ,
27
31
Link ,
28
32
Loading ,
You can’t perform that action at this time.
0 commit comments