Skip to content

Commit e4047f7

Browse files
committed
Cleanup
1 parent 8bbafa3 commit e4047f7

File tree

4 files changed

+101
-191
lines changed

4 files changed

+101
-191
lines changed

apps/web-roo-code/src/components/CookieConsent.tsx

Lines changed: 0 additions & 144 deletions
This file was deleted.
Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
"use client"
22

3-
import React from "react"
4-
import { CookieConsent } from "./CookieConsent"
3+
import React, { useState, useEffect } from "react"
4+
import ReactCookieConsent from "react-cookie-consent"
5+
import { Cookie } from "lucide-react"
6+
import { getDomain } from "tldts"
7+
import { CONSENT_COOKIE_NAME } from "@/lib/constants"
58
import { dispatchConsentEvent } from "@/lib/analytics/consent-manager"
69

710
/**
8-
* Wrapper component for CookieConsent that handles consent callbacks
9-
* This is needed because we can't pass event handlers from server components
11+
* GDPR-compliant cookie consent banner component
12+
* Handles both the UI and consent event dispatching
1013
*/
1114
export function CookieConsentWrapper() {
15+
const [cookieDomain, setCookieDomain] = useState<string | null>(null)
16+
17+
useEffect(() => {
18+
// Get the appropriate domain using tldts
19+
if (typeof window !== "undefined") {
20+
const domain = getDomain(window.location.hostname)
21+
setCookieDomain(domain)
22+
}
23+
}, [])
24+
1225
const handleAccept = () => {
1326
dispatchConsentEvent(true)
1427
}
@@ -17,5 +30,82 @@ export function CookieConsentWrapper() {
1730
dispatchConsentEvent(false)
1831
}
1932

20-
return <CookieConsent onAccept={handleAccept} onDecline={handleDecline} enableDeclineButton={true} />
33+
const extraCookieOptions = cookieDomain
34+
? {
35+
domain: cookieDomain,
36+
}
37+
: {}
38+
39+
const containerClasses = `
40+
fixed bottom-2 left-2 right-2 z-[999]
41+
bg-black/95 dark:bg-white/95
42+
text-white dark:text-black
43+
border-t-neutral-800 dark:border-t-gray-200
44+
backdrop-blur-xl
45+
border-t
46+
font-semibold
47+
rounded-t-lg
48+
px-4 py-4 md:px-8 md:py-4
49+
flex flex-wrap items-center justify-between gap-4
50+
text-sm font-sans
51+
`.trim()
52+
53+
const buttonWrapperClasses = `
54+
flex
55+
flex-row-reverse
56+
items-center
57+
gap-2
58+
`.trim()
59+
60+
const acceptButtonClasses = `
61+
bg-white text-black border-neutral-800
62+
dark:bg-black dark:text-white dark:border-gray-200
63+
hover:opacity-50
64+
transition-opacity
65+
rounded-md
66+
px-4 py-2 mr-2
67+
text-sm font-bold
68+
cursor-pointer
69+
focus:outline-none focus:ring-2 focus:ring-offset-2
70+
`.trim()
71+
72+
const declineButtonClasses = `
73+
dark:bg-white dark:text-black dark:border-gray-200
74+
bg-black text-white border-neutral-800
75+
hover:opacity-50
76+
border border-border
77+
transition-opacity
78+
rounded-md
79+
px-4 py-2
80+
text-sm font-bold
81+
cursor-pointer
82+
focus:outline-none focus:ring-2 focus:ring-offset-2
83+
`.trim()
84+
85+
return (
86+
<div role="banner" aria-label="Cookie consent banner" aria-live="polite">
87+
<ReactCookieConsent
88+
location="bottom"
89+
buttonText="Accept"
90+
declineButtonText="Decline"
91+
cookieName={CONSENT_COOKIE_NAME}
92+
expires={365}
93+
enableDeclineButton={true}
94+
onAccept={handleAccept}
95+
onDecline={handleDecline}
96+
containerClasses={containerClasses}
97+
buttonClasses={acceptButtonClasses}
98+
buttonWrapperClasses={buttonWrapperClasses}
99+
declineButtonClasses={declineButtonClasses}
100+
extraCookieOptions={extraCookieOptions}
101+
disableStyles={true}
102+
ariaAcceptLabel={`Accept`}
103+
ariaDeclineLabel={`Decline`}>
104+
<div className="flex items-center gap-2">
105+
<Cookie className="size-5 hidden md:block" />
106+
<span>Like most of the internet, we use cookies. Are you OK with that?</span>
107+
</div>
108+
</ReactCookieConsent>
109+
</div>
110+
)
21111
}

apps/web-roo-code/src/lib/analytics/consent-manager.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,24 @@
11
/**
2-
* Consent Manager - Handles cookie consent state for analytics
3-
* Works with react-cookie-consent library
2+
* Simple consent event system
3+
* Dispatches events when cookie consent changes
44
*/
55

6+
import { getCookieConsentValue } from "react-cookie-consent"
67
import { CONSENT_COOKIE_NAME } from "../constants"
78

8-
/**
9-
* Event name for consent changes
10-
*/
119
export const CONSENT_EVENT = "cookieConsentChanged"
1210

1311
/**
1412
* Check if user has given consent for analytics cookies
13+
* Uses react-cookie-consent's built-in function
1514
*/
1615
export function hasConsent(): boolean {
17-
// Only check on client side
18-
if (typeof window === "undefined") {
19-
return false
20-
}
21-
22-
// Check if the consent cookie exists and has value "true"
23-
const cookies = document.cookie.split(";")
24-
for (const cookie of cookies) {
25-
const [name, value] = cookie.trim().split("=")
26-
if (name === CONSENT_COOKIE_NAME && value === "true") {
27-
return true
28-
}
29-
}
30-
31-
return false
16+
if (typeof window === "undefined") return false
17+
return getCookieConsentValue(CONSENT_COOKIE_NAME) === "true"
3218
}
3319

3420
/**
3521
* Dispatch a consent change event
36-
* This is used to notify providers when consent status changes
3722
*/
3823
export function dispatchConsentEvent(consented: boolean): void {
3924
if (typeof window !== "undefined") {

apps/web-roo-code/src/lib/constants.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,5 @@ export const INTERNAL_LINKS = {
3131
PRIVACY_POLICY_WEBSITE: "/privacy",
3232
}
3333

34-
import { getDomain } from "tldts"
35-
3634
// Cookie consent settings
3735
export const CONSENT_COOKIE_NAME = "roo-code-cookie-consent"
38-
39-
/**
40-
* Get the appropriate domain for cookie consent
41-
* Uses tldts to extract the domain from the current hostname
42-
* Falls back to environment variable or roocode.com
43-
* Never returns null/undefined - always returns a valid domain string
44-
*/
45-
export function getConsentCookieDomain(): string {
46-
if (typeof window === "undefined") {
47-
// Server-side fallback
48-
return process.env.CONSENT_COOKIE_DOMAIN || "roocode.com"
49-
}
50-
51-
// Extract the domain using tldts - this can return null for invalid hostnames
52-
const domain = getDomain(window.location.hostname)
53-
54-
// Always return a valid string, never null/undefined
55-
return domain || process.env.CONSENT_COOKIE_DOMAIN || "roocode.com"
56-
}

0 commit comments

Comments
 (0)