Skip to content

Commit

Permalink
feat: added cookieExpires config. Setted it by default to 6 month
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed Feb 11, 2022
1 parent b2a1ad6 commit 96e3534
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ yarn add volto-gdpr-privacy -W
Wherever you want to add the component, import and use it like this:

```jsx
import { GdprPrivacyManager } from '@collective/volto-gdpr-privacy';
import { GdprPrivacyManager } from "@collective/volto-gdpr-privacy";

const YourAppComponent = () => <GdprPrivacyManager />;
```
Expand All @@ -32,7 +32,7 @@ export const settings = {
appExtras: [
...defaultSettings.appExtras,
{
match: '',
match: "",
component: GdprPrivacyManager,
},
],
Expand All @@ -47,7 +47,7 @@ In your config file, provide a configuration to define:
- default title and description suggested in control panel

```jsx
config.settings.gdprPrivacyConfig = {
config.settings["volto-gdpr-privacy"] = {
defaultPanelConfig: defaultPanelConfig, //Default control-panel configuration.
settings: {
/******
Expand All @@ -65,13 +65,21 @@ config.settings.gdprPrivacyConfig = {
};
```

#### Cookie expires

It's possibile to define a cookie expire time. By default it's 6 month, but you could change your expiration days in the config:

```jsx
config.settings["volto-gdpr-privacy"]?.cookieExpires=1 //setting cookie expiration after 1 day
```
#### Panel configuration
Until control panel is not available, a default control-panel configuration is used.
You could extend [defaultPanelConfig.js](src/config/defaultPanelConfig.js) configuration, or create your configuration and pass it in the config file:
```jsx
config.settings.gdprPrivacyConfig = {
config.settings['volto-gdpr-privacy] = {
defaultPanelConfig: defaultPanelConfig, //Default control-panel configuration.
//...
},
Expand Down
6 changes: 3 additions & 3 deletions src/actions/gdprPrivacyConfig.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import config from '@plone/volto/registry';
export const GDPR_PRIVACY_CONFIG_GET = 'GDPR_PRIVACY_CONFIG_GET';
import config from "@plone/volto/registry";
export const GDPR_PRIVACY_CONFIG_GET = "GDPR_PRIVACY_CONFIG_GET";

export function getGdprPrivacyConfig() {
const defaultConfig =
config.settings['volto-gdpr-privacy'].defaultPanelConfig;
config.settings["volto-gdpr-privacy"]?.defaultPanelConfig;
return {
type: GDPR_PRIVACY_CONFIG_GET,
defaultConfig,
Expand Down
16 changes: 11 additions & 5 deletions src/helpers/Cookies.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import cookie from 'react-cookie';
export const COOKIES_PREFIX = 'vgdpr_';
import cookie from "react-cookie";
import config from "@plone/volto/registry";

export const getExpirationDate = (date = null, expiringDays = 365) => {
export const COOKIES_PREFIX = "vgdpr_";

export const getExpirationDate = (date = null, expiringDays) => {
const days =
expiringDays ??
config.settings["volto-gdpr-privacy"]?.cookieExpires ??
6 * 30; //default: 6 month
const expireDate = date ? new Date(date) : new Date();
expireDate.setTime(expireDate.getTime() + expiringDays * 24 * 60 * 60 * 1000);
return expireDate;
Expand All @@ -15,11 +21,11 @@ export default class Cookies {
set(name, value, cookieExpiration) {
cookie.save(COOKIES_PREFIX + name, value, {
expires: cookieExpiration || getExpirationDate(),
path: '/',
path: "/",
});
}

remove(name) {
cookie.remove(COOKIES_PREFIX + name, { path: '/' });
cookie.remove(COOKIES_PREFIX + name, { path: "/" });
}
}

0 comments on commit 96e3534

Please sign in to comment.