From c578013c2275dd608956a253cc9a02f298aa693d Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Tue, 24 Sep 2024 22:30:56 +0100 Subject: [PATCH 1/4] Policy output info modal appears every time Fixes #2025 --- src/modals/PolicyImpactPopup.jsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modals/PolicyImpactPopup.jsx b/src/modals/PolicyImpactPopup.jsx index 3ec001c89..d028fad4c 100644 --- a/src/modals/PolicyImpactPopup.jsx +++ b/src/modals/PolicyImpactPopup.jsx @@ -5,7 +5,9 @@ import { useAuth0 } from "@auth0/auth0-react"; import { getCookie, setCookie } from "../data/cookies"; export default function PolicyImpactPopup(props) { - const [needToOpenModal, setNeedToOpenModal] = useState(true); + const [needToOpenModal, setNeedToOpenModal] = useState( + !(getCookie("policyImpactPopup") === "disabled"), + ); const { metadata, showPolicyImpactPopup } = props; const { isAuthenticated } = useAuth0(); @@ -15,7 +17,8 @@ export default function PolicyImpactPopup(props) { // to prevent re-display const consentCookie = getCookie("consent"); if (isAuthenticated && consentCookie === "granted") { - setCookie("policyImpactPopup", "disabled"); + document.cookie = "policyImpactPopup=disabled;max-age=31536000;path=/"; + alert(getCookie("policyImpactPopup")); } // Destroy modal From 2d541b3a7accbc66cb67ea9d336e74a74e82bd67 Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Tue, 24 Sep 2024 23:08:04 +0100 Subject: [PATCH 2/4] Remove unused import --- src/data/cookies.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/data/cookies.js b/src/data/cookies.js index f79c3913e..e7fadcd1d 100644 --- a/src/data/cookies.js +++ b/src/data/cookies.js @@ -13,14 +13,3 @@ export function getCookie(name) { } return fullCookie.split("=")[1]; } - -/** - * Cookie setter function - * @param {String} name - * @param {String} value - * @param {Number|String} [maxAge=31536000] The maximum cookie age, in ms - * @param {String} [path="/"] The cookie path - */ -export function setCookie(name, value, maxAge = 31536000, path) { - document.cookie = `${name}=${value};max-age=${String(maxAge)};path=${path}`; -} From e989da8ce21a7899c6504fba1953b149a13b8dba Mon Sep 17 00:00:00 2001 From: Anthony Volk Date: Thu, 26 Sep 2024 01:38:40 +0200 Subject: [PATCH 3/4] fix: Use helper function for cookie setting --- src/data/cookies.js | 11 +++++++++++ src/modals/PolicyImpactPopup.jsx | 3 +-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/data/cookies.js b/src/data/cookies.js index e7fadcd1d..673bbd1df 100644 --- a/src/data/cookies.js +++ b/src/data/cookies.js @@ -13,3 +13,14 @@ export function getCookie(name) { } return fullCookie.split("=")[1]; } + +/** + * Cookie setter function + * @param {String} name + * @param {String} value + * @param {Number|String} [maxAge=31536000] The maximum cookie age, in ms + * @param {String} [path="/"] The cookie path + */ +export function setCookie(name, value, maxAge = 31536000, path) { + document.cookie = `${name}=${value};max-age=${String(maxAge)};path=${path}`; +} \ No newline at end of file diff --git a/src/modals/PolicyImpactPopup.jsx b/src/modals/PolicyImpactPopup.jsx index d028fad4c..7967a7126 100644 --- a/src/modals/PolicyImpactPopup.jsx +++ b/src/modals/PolicyImpactPopup.jsx @@ -17,8 +17,7 @@ export default function PolicyImpactPopup(props) { // to prevent re-display const consentCookie = getCookie("consent"); if (isAuthenticated && consentCookie === "granted") { - document.cookie = "policyImpactPopup=disabled;max-age=31536000;path=/"; - alert(getCookie("policyImpactPopup")); + setCookie("policyImpactPopup", "disabled", 31536000, "/"); } // Destroy modal From 443f2b845d5d36a23e197b9cd3bc1fe3a835f893 Mon Sep 17 00:00:00 2001 From: Anthony Volk Date: Thu, 26 Sep 2024 01:42:28 +0200 Subject: [PATCH 4/4] chore: Lint --- src/data/cookies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/cookies.js b/src/data/cookies.js index 673bbd1df..f79c3913e 100644 --- a/src/data/cookies.js +++ b/src/data/cookies.js @@ -23,4 +23,4 @@ export function getCookie(name) { */ export function setCookie(name, value, maxAge = 31536000, path) { document.cookie = `${name}=${value};max-age=${String(maxAge)};path=${path}`; -} \ No newline at end of file +}