@bytebrand/fe-ui-core-autobahn 1.0.172 → 1.0.174
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compat/CookieModal/CookieModal.tsx +15 -1
- package/compat/CookieModal/modals/ManageCookieModal/ManageCookieModal.tsx +6 -1
- package/compat/CookieModal/modals/PreviewCookieModal/PreviewCookieModal.tsx +4 -3
- package/compat/CookieModal/useModal.ts +5 -1
- package/package.json +1 -1
- package/utils/cookieConsent.ts +84 -0
- package/utils/index.ts +8 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import useModal from './useModal';
|
|
3
3
|
import { updateCookieList } from '../../utils/CommonUtils';
|
|
4
|
+
import { OPEN_COOKIE_SETTINGS_EVENT } from '../../utils/cookieConsent';
|
|
4
5
|
import Modal from './Modal';
|
|
5
6
|
|
|
6
7
|
export interface ICookieModal {
|
|
@@ -8,7 +9,7 @@ export interface ICookieModal {
|
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
const CookieModal = ({ handleSentryInit = () => {} }: ICookieModal) => {
|
|
11
|
-
const { isVisible, toggleModal } = useModal();
|
|
12
|
+
const { isVisible, toggleModal, openModal } = useModal();
|
|
12
13
|
const [modal, setModal] = useState('');
|
|
13
14
|
|
|
14
15
|
useEffect(
|
|
@@ -22,6 +23,19 @@ const CookieModal = ({ handleSentryInit = () => {} }: ICookieModal) => {
|
|
|
22
23
|
[]
|
|
23
24
|
);
|
|
24
25
|
|
|
26
|
+
// ADV-268: "Cookie-Einstellungen ändern" (account page) reopens the settings dialog
|
|
27
|
+
useEffect(
|
|
28
|
+
() => {
|
|
29
|
+
const onOpenSettings = () => {
|
|
30
|
+
setModal('MANAGE_COOKIE_MODAL');
|
|
31
|
+
openModal();
|
|
32
|
+
};
|
|
33
|
+
window.addEventListener(OPEN_COOKIE_SETTINGS_EVENT, onOpenSettings);
|
|
34
|
+
return () => window.removeEventListener(OPEN_COOKIE_SETTINGS_EVENT, onOpenSettings);
|
|
35
|
+
},
|
|
36
|
+
[]
|
|
37
|
+
);
|
|
38
|
+
|
|
25
39
|
useEffect(
|
|
26
40
|
() => {
|
|
27
41
|
if (!isVisible) return undefined;
|
|
@@ -8,6 +8,7 @@ import MaterialAccordionGroup from '../../../MdAccordionGroup/MdAccordionGroup';
|
|
|
8
8
|
import MaterialSwitch from '../../../MdSwitch/MdSwitch';
|
|
9
9
|
import { COOKIE_SCHEMA, COOKIE_SCHEMA_LINKS } from '../../../../constants/common';
|
|
10
10
|
import { updateCookieList } from '../../../../utils/CommonUtils';
|
|
11
|
+
import { saveCookieConfig } from '../../../../utils/cookieConsent';
|
|
11
12
|
|
|
12
13
|
import styles from './ManageCookieModal.styl';
|
|
13
14
|
|
|
@@ -44,6 +45,10 @@ const ManageCookieModal = ({ toggleModal, handleSentryInit } : IManageCookieModa
|
|
|
44
45
|
.reduce((acc, item) => ({ ...acc, [item]: !!savedConfig && !savedDisabledMarketing.includes(item) }), {});
|
|
45
46
|
setAnalyticsSwitches(newAnalyticsSwitches);
|
|
46
47
|
setMarketingSwitches(newMarketingSwitches);
|
|
48
|
+
// ADV-268: reopened from the account page, a category whose cookies are all allowed shows
|
|
49
|
+
// its master switch on (it always started off)
|
|
50
|
+
setAnalyticsMasterSwitch(Object.values(newAnalyticsSwitches).every(Boolean));
|
|
51
|
+
setMarketingMasterSwitch(Object.values(newMarketingSwitches).every(Boolean));
|
|
47
52
|
},
|
|
48
53
|
[]
|
|
49
54
|
);
|
|
@@ -86,7 +91,7 @@ const ManageCookieModal = ({ toggleModal, handleSentryInit } : IManageCookieModa
|
|
|
86
91
|
marketing: Object.keys(marketingSwitches).filter(i => !marketingSwitches[i]) || [],
|
|
87
92
|
analytics: Object.keys(analyticsSwitches).filter(i => !analyticsSwitches[i]) || []
|
|
88
93
|
};
|
|
89
|
-
|
|
94
|
+
saveCookieConfig(cookieConfig);
|
|
90
95
|
updateCookieList(handleSentryInit);
|
|
91
96
|
toggleModal();
|
|
92
97
|
};
|
|
@@ -3,6 +3,7 @@ import IconSVG from '../../../../iconsvg/IconSVG';
|
|
|
3
3
|
import Button from '../../../Button/Button';
|
|
4
4
|
import styles from './PreviewCookieModal.styl';
|
|
5
5
|
import { updateCookieList } from '../../../../utils/CommonUtils';
|
|
6
|
+
import { saveCookieConfig } from '../../../../utils/cookieConsent';
|
|
6
7
|
import { COOKIE_SCHEMA } from '../../../../constants/common';
|
|
7
8
|
|
|
8
9
|
interface IPreviewCookieModal {
|
|
@@ -14,16 +15,16 @@ interface IPreviewCookieModal {
|
|
|
14
15
|
const PreviewCookieModal = ({ toggleModal, setModal, handleSentryInit } : IPreviewCookieModal) => {
|
|
15
16
|
const environment = window.location.origin;
|
|
16
17
|
const onAcceptAll = () => {
|
|
17
|
-
|
|
18
|
+
saveCookieConfig({ marketing: [], analytics: [] });
|
|
18
19
|
updateCookieList(handleSentryInit);
|
|
19
20
|
toggleModal();
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
const onDisableAll = () => {
|
|
23
|
-
|
|
24
|
+
saveCookieConfig({
|
|
24
25
|
marketing: Object.values(COOKIE_SCHEMA.marketing).reduce((acc: string[], val: string[]) => acc.concat(val), []),
|
|
25
26
|
analytics: Object.values(COOKIE_SCHEMA.analytics).reduce((acc: string[], val: string[]) => acc.concat(val), [])
|
|
26
|
-
})
|
|
27
|
+
});
|
|
27
28
|
updateCookieList(handleSentryInit);
|
|
28
29
|
toggleModal();
|
|
29
30
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytebrand/fe-ui-core-autobahn",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.174",
|
|
4
4
|
"description": "auto.de md3 (Autobahn) design system — UI primitives, cards, chrome, VDP modules, theme CSS and locales. Ships raw TypeScript source (like fe-ui-core before it); each consumer's bundler compiles it.",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// ADV-268 — the cookie consent store (`localStorage['cookieConfig']`: per category the DISABLED
|
|
2
|
+
// vendor-cookie names, see COOKIE_SCHEMA) plus what the account page needs on top of it:
|
|
3
|
+
// - when the choice last changed (`cookieConfigChangedAt`, ISO), written on every save that
|
|
4
|
+
// changes it — the consent dialogs save through saveCookieConfig;
|
|
5
|
+
// - a window event after each save, so a page showing the state can update live;
|
|
6
|
+
// - openCookieSettings(), which makes the mounted CookieModal show its settings dialog again.
|
|
7
|
+
// Storage access is guarded: with site storage blocked every read returns "no choice yet".
|
|
8
|
+
|
|
9
|
+
import { COOKIE_SCHEMA } from '../constants/common';
|
|
10
|
+
|
|
11
|
+
export const COOKIE_CONFIG_KEY = 'cookieConfig';
|
|
12
|
+
export const COOKIE_CONFIG_CHANGED_AT_KEY = 'cookieConfigChangedAt';
|
|
13
|
+
export const COOKIE_CONSENT_CHANGE_EVENT = 'autode:cookie-consent-change';
|
|
14
|
+
export const OPEN_COOKIE_SETTINGS_EVENT = 'autode:open-cookie-settings';
|
|
15
|
+
|
|
16
|
+
export interface ICookieConfig {
|
|
17
|
+
marketing: string[];
|
|
18
|
+
analytics: string[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type CookieCategoryState = 'on' | 'partial' | 'off';
|
|
22
|
+
|
|
23
|
+
export interface ICookieConsentState {
|
|
24
|
+
/** false until the visitor saved a choice in the cookie dialog */
|
|
25
|
+
decided: boolean;
|
|
26
|
+
/** ISO date of the last change, null when unknown (no choice yet, or saved before it was recorded) */
|
|
27
|
+
changedAt: string | null;
|
|
28
|
+
analytics: CookieCategoryState;
|
|
29
|
+
marketing: CookieCategoryState;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const vendorCookies = (category: 'analytics' | 'marketing'): string[] =>
|
|
33
|
+
Object.values(COOKIE_SCHEMA[category]).reduce((acc: string[], val: string[]) => acc.concat(val), []);
|
|
34
|
+
|
|
35
|
+
const readStorage = (key: string): string | null => {
|
|
36
|
+
try {
|
|
37
|
+
return localStorage.getItem(key);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const saveCookieConfig = (config: ICookieConfig | Record<string, string[]>) => {
|
|
44
|
+
const next = JSON.stringify(config);
|
|
45
|
+
try {
|
|
46
|
+
const previous = localStorage.getItem(COOKIE_CONFIG_KEY);
|
|
47
|
+
localStorage.setItem(COOKIE_CONFIG_KEY, next);
|
|
48
|
+
if (previous !== next || !localStorage.getItem(COOKIE_CONFIG_CHANGED_AT_KEY)) {
|
|
49
|
+
localStorage.setItem(COOKIE_CONFIG_CHANGED_AT_KEY, new Date().toISOString());
|
|
50
|
+
}
|
|
51
|
+
} catch (e) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
window.dispatchEvent(new Event(COOKIE_CONSENT_CHANGE_EVENT));
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const getCookieConsentState = (): ICookieConsentState => {
|
|
58
|
+
let config: Partial<ICookieConfig> | null = null;
|
|
59
|
+
try {
|
|
60
|
+
config = JSON.parse(readStorage(COOKIE_CONFIG_KEY));
|
|
61
|
+
} catch (e) {
|
|
62
|
+
config = null;
|
|
63
|
+
}
|
|
64
|
+
if (!config) return { decided: false, changedAt: null, analytics: 'off', marketing: 'off' };
|
|
65
|
+
|
|
66
|
+
const categoryState = (category: 'analytics' | 'marketing'): CookieCategoryState => {
|
|
67
|
+
const disabled = Array.isArray(config[category]) ? config[category] : [];
|
|
68
|
+
const all = vendorCookies(category);
|
|
69
|
+
const allowed = all.filter((cookie) => !disabled.includes(cookie)).length;
|
|
70
|
+
if (allowed === all.length) return 'on';
|
|
71
|
+
return allowed ? 'partial' : 'off';
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
decided: true,
|
|
76
|
+
changedAt: readStorage(COOKIE_CONFIG_CHANGED_AT_KEY),
|
|
77
|
+
analytics: categoryState('analytics'),
|
|
78
|
+
marketing: categoryState('marketing')
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const openCookieSettings = () => {
|
|
83
|
+
window.dispatchEvent(new Event(OPEN_COOKIE_SETTINGS_EVENT));
|
|
84
|
+
};
|
package/utils/index.ts
CHANGED
|
@@ -62,6 +62,14 @@ export {
|
|
|
62
62
|
updateCookieList
|
|
63
63
|
} from './CommonUtils';
|
|
64
64
|
|
|
65
|
+
export {
|
|
66
|
+
COOKIE_CONSENT_CHANGE_EVENT,
|
|
67
|
+
getCookieConsentState,
|
|
68
|
+
openCookieSettings,
|
|
69
|
+
saveCookieConfig
|
|
70
|
+
} from './cookieConsent';
|
|
71
|
+
export type { CookieCategoryState, ICookieConsentState } from './cookieConsent';
|
|
72
|
+
|
|
65
73
|
export { getEquipment, getEquipmentCount } from '../vehiclesProps/equipment';
|
|
66
74
|
|
|
67
75
|
export type { IDecoratedProps, IEquipmentProps, ICarPropElement } from '../types/types';
|