-
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.
- Loading branch information
Showing
8 changed files
with
651 additions
and
234 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
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
131 changes: 131 additions & 0 deletions
131
src/components/manage/Blocks/DiscodataOpenlayersMapBlock/PrivacyProtection.jsx
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,131 @@ | ||
import React, { useState } from 'react'; | ||
import VisibilitySensor from 'react-visibility-sensor'; | ||
import { Placeholder } from 'semantic-ui-react'; | ||
import cookie from 'react-cookie'; | ||
import ReactTooltip from 'react-tooltip'; | ||
import { Button, Checkbox, Message, Image } from 'semantic-ui-react'; | ||
import Icon from '@plone/volto/components/theme/Icon/Icon'; | ||
import infoSVG from '@plone/volto/icons/info.svg'; | ||
import { settings } from '~/config'; | ||
|
||
import 'volto-embed/css/embed-styles.css'; | ||
|
||
const key = (domain_key) => `accept-${domain_key}`; | ||
|
||
const getExpDays = () => | ||
typeof settings.embedCookieExpirationDays !== 'undefined' | ||
? settings.embedCookieExpirationDays | ||
: 90; | ||
|
||
function saveCookie(domain_key) { | ||
const date = new Date(); | ||
date.setDate(date.getDate() + getExpDays()); | ||
|
||
cookie.save(key(domain_key), 'true', { | ||
path: '/', | ||
expires: date, | ||
}); | ||
} | ||
|
||
function canShow(domain_key) { | ||
return cookie.load(key(domain_key)) === 'true'; | ||
} | ||
|
||
export default ({ children, data = {}, block, onShow, ...rest }) => { | ||
const { dataprotection = {} } = data; | ||
const [visible, setVisibility] = useState(false); | ||
const defaultShow = canShow(dataprotection.privacy_cookie_key); | ||
const [show, setShow] = useState(defaultShow); | ||
const [remember, setRemember] = useState(defaultShow); | ||
|
||
return ( | ||
<VisibilitySensor | ||
onChange={(isVisible) => { | ||
!visible && isVisible && setVisibility(true); | ||
}} | ||
partialVisibility={true} | ||
offset={{ bottom: 200 }} | ||
> | ||
{visible ? ( | ||
<> | ||
{!dataprotection.enabled || show ? ( | ||
children | ||
) : ( | ||
<div className="privacy-protection" {...rest}> | ||
<div className="overlay"> | ||
<div className="wrapped"> | ||
{dataprotection.type === 'big' ? ( | ||
<Message> | ||
<div | ||
className="privacy-statement" | ||
dangerouslySetInnerHTML={{ | ||
__html: dataprotection.privacy_statement, | ||
}} | ||
/> | ||
</Message> | ||
) : ( | ||
'' | ||
)} | ||
<div className="privacy-button"> | ||
{dataprotection.type === 'small' ? ( | ||
<span | ||
className="floating-icon mr-1" | ||
data-tip={dataprotection.privacy_statement} | ||
> | ||
<Icon | ||
className="firefox-icon" | ||
name={infoSVG} | ||
size="20" | ||
color="#D63D27" | ||
/> | ||
</span> | ||
) : ( | ||
'' | ||
)} | ||
<Button | ||
primary | ||
onClick={() => { | ||
setShow(true); | ||
if (onShow) { | ||
onShow(); | ||
} | ||
if (remember) { | ||
saveCookie(dataprotection.privacy_cookie_key); | ||
} | ||
}} | ||
> | ||
Show external content | ||
</Button> | ||
</div> | ||
|
||
<div className="privacy-toggle"> | ||
<Checkbox | ||
toggle | ||
label="Remember my choice" | ||
id={`remember-choice-${block}`} | ||
onChange={(ev, { checked }) => { | ||
setRemember(checked); | ||
}} | ||
checked={remember} | ||
/> | ||
</div> | ||
|
||
<p className="discreet"> | ||
Your choice will be saved in a cookie managed by{' '} | ||
{settings.ownDomain || '.eea.europa.eu'} that will expire in{' '} | ||
{getExpDays()} days. | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
)} | ||
<ReactTooltip /> | ||
</> | ||
) : ( | ||
<Placeholder style={{ height: '100%', width: '100%' }}> | ||
<Placeholder.Image rectangular /> | ||
</Placeholder> | ||
)} | ||
</VisibilitySensor> | ||
); | ||
}; |
Oops, something went wrong.