Skip to content

Commit

Permalink
Cookie_changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sruthi-Sunder committed Oct 18, 2024
1 parent ae069dc commit a779ed6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/client/assets/javascripts/cookie-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ function deleteCookie(name) {
// If a cookie was set with a specified domain, it needs to be specified when deleted
// If a cookie wasn't set with the domain attribute, it shouldn't be there when deleted
// You can't tell if a cookie was set with a domain attribute or not, so try both options

document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/`
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;domain=${window.location.hostname};path=/`
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;domain=.${window.location.hostname};path=/`
Expand Down
38 changes: 18 additions & 20 deletions src/client/assets/javascripts/cookies-page.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
getConsentCookie,
setConsentCookie,
Cookie
} from './cookie-functions.js'
import { getConsentCookie, setConsentCookie } from './cookie-functions.js'

/**
* Website cookies page
Expand Down Expand Up @@ -76,7 +72,6 @@ class CookiesPage {
savePreferences(event) {
// Stop default form submission behaviour
event.preventDefault()
let item
const preferences = {}

this.$cookieFormFieldsets.forEach(($cookieFormFieldset) => {
Expand All @@ -89,25 +84,28 @@ class CookiesPage {
`input[name="cookies[${cookieType}]"]:checked`
)

item = $selectedItem.value
if ($selectedItem instanceof HTMLInputElement) {
preferences[cookieType] = $selectedItem.value === 'yes'
}
})
if (item === 'yes') {
// Save preferences to cookie and show success notification
setConsentCookie(preferences)
} else {
for (const UACookie of [
'_ga_HVF94VF4NZ',
'_gid',
'_ga',
'phi_cookies_analytics'
]) {
Cookie(UACookie, null)
}
}

// Save preferences to cookie and show success notification
setConsentCookie(preferences)

// for (const UACookie of [
// '_ga_HVF94VF4NZ',
// '_gid',
// '_ga',
// 'phi_cookies_analytics'
// ]) {
// Cookie(UACookie, null)
// }

this.showSuccessNotification()
const cookieBanner = document.querySelector(
"[data-module='govuk-cookie-banner']"
)
cookieBanner.setAttribute('hidden', 'true')
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,12 @@ const config = convict({
doc: 'Backend api url',
format: String,
default: `https://phi-etl-fera-backend.test.cdp-int.defra.cloud`,
default: `https://localhost:3049`,
env: 'BACKEND_API_URL'
},
frontendUrl: {
doc: 'Frontend url',
format: String,
//default: `https://phi-frontend.test.cdp-int.defra.cloud`,
default: `https://localhost:3000`,
default: `https://phi-frontend.test.cdp-int.defra.cloud`,
env: 'FRONTEND_URL'
},

Expand Down

0 comments on commit a779ed6

Please sign in to comment.