Skip to content

Commit d5c5fe4

Browse files
authored
Merge pull request #197 from scientist-softserv/316-cookie-policy
316-cookie-policy components
2 parents 1274a8c + 81a848f commit d5c5fe4

File tree

5 files changed

+144
-0
lines changed

5 files changed

+144
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+

src/components/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import AdditionalInfo from './AdditionalInfo/AdditionalInfo'
77
import BlankRequestForm from './BlankRequestForm/BlankRequestForm'
88
import Button from './Button/Button'
99
import CollapsibleSection from './CollapsibleSection/CollapsibleSection'
10+
import CookiePreferencesCheck from './CookiePreferences/CookiePreferencesCheck'
11+
import CookiePreferencesModal from './CookiePreferences/CookiePreferencesModal'
1012
import Image from './Image/Image'
1113
import Link from './Link/Link'
1214
import Loading from './Loading/Loading'
@@ -23,6 +25,8 @@ export {
2325
BlankRequestForm,
2426
Button,
2527
CollapsibleSection,
28+
CookiePreferencesCheck,
29+
CookiePreferencesModal,
2630
Image,
2731
Link,
2832
Loading,

0 commit comments

Comments
 (0)