Skip to content

Commit e89a22e

Browse files
committed
fix: changes as requested in PR #310 #302
1 parent 1e14075 commit e89a22e

File tree

3 files changed

+9
-22
lines changed

3 files changed

+9
-22
lines changed

src/consentManagement/createConsentManagement.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function createConsentManagement<
2929
finalityDescription,
3030
personalDataPolicyLinkProps,
3131
consentCallback,
32-
localStorageKeyPrefix
32+
localStorageKeyPrefix = defaultLocalStorageKeyPrefix
3333
} = params;
3434

3535
const finalities = getFinalitiesFromFinalityDescription({
@@ -39,9 +39,7 @@ export function createConsentManagement<
3939
: finalityDescription
4040
});
4141

42-
const localStorageKey = `${
43-
localStorageKeyPrefix ?? defaultLocalStorageKeyPrefix
44-
} ${finalities.join("-")}`;
42+
const localStorageKey = `${localStorageKeyPrefix} ${finalities.join("-")}`;
4543

4644
const $finalityConsent = createStatefulObservable<FinalityConsent<Finality> | undefined>(() => {
4745
if (!isBrowser) {
@@ -106,8 +104,7 @@ export function createConsentManagement<
106104
useConsent,
107105
ConsentBannerAndConsentManagement,
108106
FooterConsentManagementItem,
109-
FooterPersonalDataPolicyItem,
110-
consentLocalStorageKey: localStorageKey
107+
FooterPersonalDataPolicyItem
111108
};
112109
}
113110

stories/ConsentManagement.stories.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ export const {
3434
ConsentBannerAndConsentManagement,
3535
FooterConsentManagementItem,
3636
FooterPersonalDataPolicyItem,
37-
useConsent,
38-
consentLocalStorageKey
37+
useConsent
3938
} = createConsentManagement({
4039
/*
4140
Can be an object or a function that take the current language as argument.
@@ -122,13 +121,7 @@ export const {
122121
}
123122
*/
124123
125-
},
126-
127-
/*
128-
This optional parameter let's you personalise the key that is used to store user's consents in the localStorage.
129-
The default value is "${defaultLocalStorageKeyPrefix}"
130-
*/
131-
"localStorageKeyPrefix": "company-name/app-name"
124+
}
132125
});
133126
\`\`\`
134127
@@ -220,8 +213,7 @@ const {
220213
ConsentBannerAndConsentManagement,
221214
FooterConsentManagementItem,
222215
FooterPersonalDataPolicyItem,
223-
useConsent,
224-
consentLocalStorageKey
216+
useConsent
225217
} = createConsentManagement({
226218
"finalityDescription": {
227219
"advertising": {
@@ -292,7 +284,7 @@ function Story() {
292284
<Button
293285
onClick={() => {
294286
Object.keys(localStorage)
295-
.filter(key => key.startsWith(consentLocalStorageKey))
287+
.filter(key => key.startsWith(defaultLocalStorageKeyPrefix))
296288
.forEach(key => localStorage.removeItem(key));
297289

298290
location.reload();

test/integration/vite/src/consentManagement.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ export const {
66
ConsentBannerAndConsentManagement,
77
FooterConsentManagementItem,
88
FooterPersonalDataPolicyItem,
9-
useConsent,
10-
consentLocalStorageKey
9+
useConsent
1110
} = createConsentManagement({
1211
"finalityDescription": ({ lang }) => ({
1312
"advertising": {
@@ -42,6 +41,5 @@ export const {
4241
}
4342

4443
console.log("callback from gdpr hook");
45-
},
46-
"localStorageKeyPrefix": "company-name/app-name finalityConsent"
44+
}
4745
});

0 commit comments

Comments
 (0)