Skip to content

Commit ce051b7

Browse files
committed
refactor the cookie preferences components
move logic on whether to show the modal to the webstore. change the user decision of accepting or denying cookies to a boolean.
1 parent dded4bf commit ce051b7

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

src/components/CookiePreferences/CookiePreferencesCheck.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import Form from 'react-bootstrap/Form'
33
import PropTypes from 'prop-types'
44
import { useState } from 'react'
55

6-
const CookiePreferencesCheck = ({ cookieConsent, disableCookies, enableCookies }) => {
6+
const CookiePreferencesCheck = ({ cookieConsentValue, disableCookies, enableCookies }) => {
77
// NOTE: the enable/disable cookies functions change the actual value.
88
// the variable below is so the radio buttons update after being clicked.
9-
const [allowed, setAllowed] = useState(cookieConsent)
9+
const [allowed, setAllowed] = useState(cookieConsentValue)
1010

1111
const handleEnablingCookies = () => {
1212
enableCookies()
13-
setAllowed('true')
13+
setAllowed(true)
1414
}
1515

1616
const handleDisablingCookies = () => {
1717
disableCookies()
18-
setAllowed('false')
18+
setAllowed(false)
1919
}
2020

2121
return (
@@ -26,7 +26,7 @@ const CookiePreferencesCheck = ({ cookieConsent, disableCookies, enableCookies }
2626
name='Allow Cookies'
2727
type='radio'
2828
id='allow-cookies'
29-
checked={allowed === 'true'}
29+
checked={allowed}
3030
onChange={() => handleEnablingCookies()}
3131
/>
3232
<Form.Check
@@ -35,15 +35,15 @@ const CookiePreferencesCheck = ({ cookieConsent, disableCookies, enableCookies }
3535
name='Disable Cookies'
3636
type='radio'
3737
id='disable-cookies'
38-
checked={allowed === 'false'}
38+
checked={!allowed}
3939
onChange={() => handleDisablingCookies()}
4040
/>
4141
</Form>
4242
);
4343
}
4444

4545
CookiePreferencesCheck.propTypes = {
46-
cookieConsent: PropTypes.string.isRequired,
46+
cookieConsentValue: PropTypes.bool.isRequired,
4747
disableCookies: PropTypes.func.isRequired,
4848
enableCookies: PropTypes.func.isRequired,
4949
}

src/components/CookiePreferences/CookiePreferencesCheck.stories.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ const Template = (args) => <CookiePreferencesCheck {...args} />
1010

1111
export const Default = Template.bind({})
1212
Default.args = {
13-
cookieConsent: 'false',
13+
cookieConsentValue: false,
1414
disableCookies: () => console.log('disable cookies'),
1515
enableCookies: () => console.log('enable cookies'),
1616
}
17-

src/components/CookiePreferences/CookiePreferencesModal.jsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import Button from 'react-bootstrap/Button'
55
import Modal from 'react-bootstrap/Modal'
66
import { useState } from 'react'
77

8-
const CookiePreferencesModal = ({ cookieConsent, disableCookies, enableCookies }) => {
9-
const [show, setShow] = useState(false)
8+
const CookiePreferencesModal = ({ getCookieConsent, disableCookies, enableCookies }) => {
9+
const [show, setShow] = useState(getCookieConsent)
1010
const handleClose = () => setShow(false)
1111
const handleShow = () => setShow(true)
1212

@@ -20,8 +20,6 @@ const CookiePreferencesModal = ({ cookieConsent, disableCookies, enableCookies }
2020
handleClose()
2121
}
2222

23-
if (!show && (cookieConsent === undefined)) return handleShow()
24-
2523
return (
2624
<Modal
2725
show={show}
@@ -49,7 +47,7 @@ const CookiePreferencesModal = ({ cookieConsent, disableCookies, enableCookies }
4947
}
5048

5149
CookiePreferencesModal.propTypes = {
52-
cookieConsent: PropTypes.string.isRequired,
50+
getCookieConsent: PropTypes.bool.isRequired,
5351
disableCookies: PropTypes.func.isRequired,
5452
enableCookies: PropTypes.func.isRequired,
5553
}

src/components/CookiePreferences/CookiePreferencesModal.stories.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const Template = (args) => <CookiePreferencesModal {...args} />
1010

1111
export const Default = Template.bind({})
1212
Default.args = {
13-
cookieConsent: undefined,
13+
getCookieConsent: true,
1414
disableCookies: () => console.log('disable cookies'),
1515
enableCookies: () => console.log('enable cookies'),
1616
}

0 commit comments

Comments
 (0)