From 2bceb9142453308b852493adeef09826c156d94a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Genevi=C3=A8ve=20Bastien?= Date: Mon, 12 May 2025 14:35:07 -0400 Subject: [PATCH] survey: add a banner explaining the usage of necessary cookies fixes #921 Add a component displaying a simple cookie banner explaining the use of strictly necessary cookies. The user can click `Accept` to accept the cookies and the banner will disappear forever. --- .../src/apps/participant/index.tsx | 2 ++ .../src/components/pageParts/CookieBanner.tsx | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 packages/evolution-frontend/src/components/pageParts/CookieBanner.tsx diff --git a/packages/evolution-frontend/src/apps/participant/index.tsx b/packages/evolution-frontend/src/apps/participant/index.tsx index 0779d4ef1..c34d1078e 100644 --- a/packages/evolution-frontend/src/apps/participant/index.tsx +++ b/packages/evolution-frontend/src/apps/participant/index.tsx @@ -22,6 +22,7 @@ import appConfig, { setApplicationConfiguration } from 'chaire-lib-frontend/lib/ import '../../styles/survey/styles-participant-survey.scss'; import verifyAuthentication from 'chaire-lib-frontend/lib/services/auth/verifyAuthentication'; import SegmentsSection from '../../components/survey/sectionTemplates/TripsAndSegmentsSection'; +import CookieBanner from '../../components/pageParts/CookieBanner'; setApplicationConfiguration({ homePage: '/survey', templateMapping: { tripsAndSegmentsWithMap: SegmentsSection } }); @@ -51,6 +52,7 @@ const App = (settings?: AppSettings) => { + diff --git a/packages/evolution-frontend/src/components/pageParts/CookieBanner.tsx b/packages/evolution-frontend/src/components/pageParts/CookieBanner.tsx new file mode 100644 index 000000000..451c9826a --- /dev/null +++ b/packages/evolution-frontend/src/components/pageParts/CookieBanner.tsx @@ -0,0 +1,29 @@ +import React, { useState, useEffect } from 'react'; + +const CookieBanner: React.FC = () => { + const [showBanner, setShowBanner] = useState(false); + + useEffect(() => { + // Check if user already accepted cookies + const cookiesAccepted = localStorage.getItem('cookiesAccepted'); + if (!cookiesAccepted) { + setShowBanner(true); + } + }, []); + + const acceptCookies = () => { + localStorage.setItem('cookiesAccepted', 'true'); + setShowBanner(false); + }; + + if (!showBanner) return null; + + return ( +
+

We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies.

+ +
+ ); +}; + +export default CookieBanner; \ No newline at end of file