'use client' import { Button } from '@thedaviddias/design-system/button' import { logger } from '@thedaviddias/logging' import { X } from 'lucide-react' import Link from 'next/link' import { useEffect, useState } from 'react' import { getRoute } from '@/lib/routes' const COOKIE_CONSENT_KEY = 'cookie-consent' const COOKIE_CONSENT_VERSION = '1.0' interface CookieConsent { version: string essential: boolean analytics: boolean functional: boolean timestamp: number } /** * Cookie consent banner component that provides GDPR-compliant cookie consent management */ export function CookieConsentBanner() { const [isVisible, setIsVisible] = useState(false) const [isLoading, setIsLoading] = useState(true) useEffect(() => { // Check if user has already provided consent const savedConsent = localStorage.getItem(COOKIE_CONSENT_KEY) if (savedConsent) { try { const consent: CookieConsent = JSON.parse(savedConsent) // Check if consent is for current version and not older than 1 year const oneYearAgo = Date.now() - 365 * 24 * 60 * 60 * 1000 if (consent.version === COOKIE_CONSENT_VERSION && consent.timestamp > oneYearAgo) { setIsVisible(false) setIsLoading(false) return } } catch (error) { logger.error('Error parsing cookie consent:', { data: error, tags: { type: 'component' } }) } } // Show banner if no valid consent found setIsVisible(true) setIsLoading(false) }, []) /** * Saves cookie consent preferences to localStorage and dispatches update event */ const saveConsent = (analyticsConsent: boolean, functionalConsent: boolean) => { const consent: CookieConsent = { version: COOKIE_CONSENT_VERSION, essential: true, // Essential cookies are always accepted analytics: analyticsConsent, functional: functionalConsent, timestamp: Date.now() } localStorage.setItem(COOKIE_CONSENT_KEY, JSON.stringify(consent)) // Dispatch custom event for other parts of the app to listen to window.dispatchEvent( new CustomEvent('cookieConsentUpdated', { detail: consent }) ) setIsVisible(false) } if (isLoading || !isVisible) { return null } return (
We use cookies to enhance your experience
We use essential cookies to make our website work and analytics cookies to understand how you interact with our website. Functional cookies help us remember your preferences. You can manage your preferences or learn more in our{' '} Cookie Policy {' '} and{' '} Privacy Policy .