Skip to content

Commit

Permalink
fix: changes as requested in PR #310 #302
Browse files Browse the repository at this point in the history
  • Loading branch information
ocruze committed Sep 17, 2024
1 parent 1e14075 commit e89a22e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
9 changes: 3 additions & 6 deletions src/consentManagement/createConsentManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function createConsentManagement<
finalityDescription,
personalDataPolicyLinkProps,
consentCallback,
localStorageKeyPrefix
localStorageKeyPrefix = defaultLocalStorageKeyPrefix
} = params;

const finalities = getFinalitiesFromFinalityDescription({
Expand All @@ -39,9 +39,7 @@ export function createConsentManagement<
: finalityDescription
});

const localStorageKey = `${
localStorageKeyPrefix ?? defaultLocalStorageKeyPrefix
} ${finalities.join("-")}`;
const localStorageKey = `${localStorageKeyPrefix} ${finalities.join("-")}`;

const $finalityConsent = createStatefulObservable<FinalityConsent<Finality> | undefined>(() => {
if (!isBrowser) {
Expand Down Expand Up @@ -106,8 +104,7 @@ export function createConsentManagement<
useConsent,
ConsentBannerAndConsentManagement,
FooterConsentManagementItem,
FooterPersonalDataPolicyItem,
consentLocalStorageKey: localStorageKey
FooterPersonalDataPolicyItem
};
}

Expand Down
16 changes: 4 additions & 12 deletions stories/ConsentManagement.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export const {
ConsentBannerAndConsentManagement,
FooterConsentManagementItem,
FooterPersonalDataPolicyItem,
useConsent,
consentLocalStorageKey
useConsent
} = createConsentManagement({
/*
Can be an object or a function that take the current language as argument.
Expand Down Expand Up @@ -122,13 +121,7 @@ export const {
}
*/
},
/*
This optional parameter let's you personalise the key that is used to store user's consents in the localStorage.
The default value is "${defaultLocalStorageKeyPrefix}"
*/
"localStorageKeyPrefix": "company-name/app-name"
}
});
\`\`\`
Expand Down Expand Up @@ -220,8 +213,7 @@ const {
ConsentBannerAndConsentManagement,
FooterConsentManagementItem,
FooterPersonalDataPolicyItem,
useConsent,
consentLocalStorageKey
useConsent
} = createConsentManagement({
"finalityDescription": {
"advertising": {
Expand Down Expand Up @@ -292,7 +284,7 @@ function Story() {
<Button
onClick={() => {
Object.keys(localStorage)
.filter(key => key.startsWith(consentLocalStorageKey))
.filter(key => key.startsWith(defaultLocalStorageKeyPrefix))
.forEach(key => localStorage.removeItem(key));

location.reload();
Expand Down
6 changes: 2 additions & 4 deletions test/integration/vite/src/consentManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ export const {
ConsentBannerAndConsentManagement,
FooterConsentManagementItem,
FooterPersonalDataPolicyItem,
useConsent,
consentLocalStorageKey
useConsent
} = createConsentManagement({
"finalityDescription": ({ lang }) => ({
"advertising": {
Expand Down Expand Up @@ -42,6 +41,5 @@ export const {
}

console.log("callback from gdpr hook");
},
"localStorageKeyPrefix": "company-name/app-name finalityConsent"
}
});

0 comments on commit e89a22e

Please sign in to comment.