overleaf-cep/services/web/frontend/js/features/cookie-banner/index.ts
Tim Down 0778bab910 Merge pull request #27254 from overleaf/td-project-dashboard-cookie-banner
Implement React cookie banner on project dashboard

GitOrigin-RevId: 95d2778d7ce7cb3054a06b06486b815a3453a623
2025-07-22 08:06:05 +00:00

32 lines
811 B
TypeScript

import {
CookieConsentValue,
cookieBannerRequired,
hasMadeCookieChoice,
setConsent,
} from '@/features/cookie-banner/utils'
function toggleCookieBanner(hidden: boolean) {
const cookieBannerEl = document.querySelector('.cookie-banner')
if (cookieBannerEl) {
cookieBannerEl.classList.toggle('hidden', hidden)
}
}
if (cookieBannerRequired()) {
document
.querySelectorAll('[data-ol-cookie-banner-set-consent]')
.forEach(el => {
el.addEventListener('click', function (e) {
e.preventDefault()
toggleCookieBanner(true)
const consentType = el.getAttribute(
'data-ol-cookie-banner-set-consent'
) as CookieConsentValue | null
setConsent(consentType)
})
})
if (!hasMadeCookieChoice()) {
toggleCookieBanner(false)
}
}