-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
❇️ Refactor cookie consent and allow multiple cookie policies to be set
#2376 (#2396) * ✨ Allow to set multiple cookie policy #2376 * ♻️ Refactor cookiepolicy #2376 * 🐛 Fix 500 in other paGES #2376 * ✨ Backward compatability #2376 * ♻️ Refactor vookiepolicy query #2396 * Fix news iframe query #2376 * 🔨 Script to migrate cookiepolicy #2376 * ♻️ Simplify cookiepolicy query #2376
- Loading branch information
Showing
22 changed files
with
146 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Use this folder to create scripts for content migration. | ||
|
||
## Steps: | ||
|
||
1. Inside sanityv3 folder run `pnpx sanity migration create "Issue <ISSUE_NO>"` to create a migration script folder. You can choose the appropriate template or start with a basic one. | ||
2. Open the `index.ts` file which is just created and modify the script. | ||
3. Login to sanity from the cli using SSO `pnpm sanity login --sso <sso_slug>` | ||
4. Run `pnpm sanity migration run issue-<ISSUE_NO> --project=<PROJECT_ID> --dataset=<DATASET>` for dry run, and verify the patches. | ||
5. Run `pnpm sanity migration run issue-<ISSUE_NO> --project=<PROJECT_ID> --dataset=<DATASET> --no-dry-run` to migrate. |
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,12 @@ | ||
import { defineMigration, set } from 'sanity/migrate' | ||
|
||
export default defineMigration({ | ||
title: 'Issue 2376', | ||
documentTypes: ['page', 'event', 'news', 'magazine'], | ||
migrate: { | ||
string(node, path, context) { | ||
if (['none', 'marketing', 'statistics'].includes(node) && path[path.length - 1] === 'cookiePolicy') | ||
return set([node]) | ||
}, | ||
}, | ||
}) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,18 @@ | ||
import { useRouter } from 'next/router' | ||
import { useEffect, useState } from 'react' | ||
import { ConsentType } from './useConsentState' | ||
|
||
const getConsentState = (consentType: ConsentType): boolean => { | ||
// Prevents SSR issues | ||
if (typeof window !== 'undefined') { | ||
switch (consentType) { | ||
case 'statistics': | ||
return window.Cookiebot?.consent.statistics | ||
case 'marketing': | ||
return window.Cookiebot?.consent.marketing | ||
default: | ||
return false | ||
} | ||
} | ||
return false | ||
} | ||
import { checkCookieConsent } from '../../common/helpers/checkCookieConsent' | ||
import { CookieType } from '../../types' | ||
|
||
/** | ||
* Returns true if the consent is given for the given consentType. | ||
* @param consentType Can be either marketing or statistics | ||
* @returns | ||
*/ | ||
export default function useConsent(consentType: ConsentType): boolean | undefined { | ||
const [consent, setConsent] = useState<boolean>(getConsentState(consentType)) | ||
export default function useConsent(consentType: CookieType[]): boolean | undefined { | ||
const [consent, setConsent] = useState<boolean>(checkCookieConsent(consentType)) | ||
const router = useRouter() | ||
useEffect(() => { | ||
setConsent(getConsentState(consentType)) | ||
setConsent(checkCookieConsent(consentType)) | ||
}, [consentType, router.asPath]) | ||
return consent | ||
} |
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
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
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
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
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
Oops, something went wrong.