Skip to content

Commit

Permalink
Fixes #37664 - switch to using js-cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
MariaAga committed Jul 19, 2024
1 parent f824a88 commit 1477aa4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
8 changes: 0 additions & 8 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ function onContentLoad() {

password_caps_lock_hint();

tfm.i18n.intl.ready.then(function() {
var tz = jstz.determine();
$.cookie('timezone', tz.name(), {
path: '/',
secure: location.protocol === 'https:',
});
});

$('.full-value').SelectOnClick();
activate_select2(':root');

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"graphql-tag": "^2.11.0",
"intl": "~1.2.5",
"jed": "^1.1.1",
"js-cookie": "^3.0.5",
"os-browserify": "^0.3.0",
"react-intl": "^2.8.0"
},
Expand Down
7 changes: 4 additions & 3 deletions webpack/assets/javascripts/hosts/tableCheckboxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/* eslint-disable jquery/no-in-array */

import $ from 'jquery';
import Cookies from 'js-cookie';

import {
sprintf,
Expand Down Expand Up @@ -43,7 +44,7 @@ export function hostChecked({ id, checked }) {
multipleAlert.data('multiple', false);
}
}
$.cookie(cookieName, JSON.stringify(foremanSelectedHosts), {
Cookies.set(cookieName, JSON.stringify(foremanSelectedHosts), {
secure: window.location.protocol === 'https:',
});
toggleActions();
Expand All @@ -62,7 +63,7 @@ function rmHostId(id) {

function readFromCookie() {
try {
const r = $.cookie(cookieName);
const r = Cookies.get(cookieName);
if (r) return $.parseJSON(r);
return [];
} catch (err) {
Expand Down Expand Up @@ -116,7 +117,7 @@ $(document).on('ContentLoad', () => {
});

function removeForemanHostsCookie() {
$.removeCookie(cookieName);
Cookies.remove(cookieName);
}

export function resetSelection() {
Expand Down
15 changes: 10 additions & 5 deletions webpack/assets/javascripts/react_app/common/I18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
/* eslint-disable import/no-dynamic-require */
import Jed from 'jed';
import { addLocaleData } from 'react-intl';
import Cookies from 'js-cookie';
import jstz from 'jstz';
import forceSingleton from './forceSingleton';

const htmlElemnt = document.getElementsByTagName('html')[0];
const langAttr = htmlElemnt.getAttribute('lang') || 'en';
const timezoneAttr = htmlElemnt.getAttribute('data-timezone') || 'UTC';

class IntlLoader {
constructor(locale, timezone) {
this.fallbackIntl = !global.Intl;
Expand All @@ -18,6 +24,10 @@ class IntlLoader {
await this.fetchIntl();
const localeData = require(/* webpackChunkName: 'react-intl/locale/[request]' */ `react-intl/locale-data/${this.locale}`);
addLocaleData(localeData);
Cookies.set('timezone', jstz.determine().name(), {
path: '/',
secure: window.location.protocol === 'https:',
});
return true;
}

Expand All @@ -28,11 +38,6 @@ class IntlLoader {
}
}
}

const htmlElemnt = document.getElementsByTagName('html')[0];
const langAttr = htmlElemnt.getAttribute('lang') || 'en';
const timezoneAttr = htmlElemnt.getAttribute('data-timezone') || 'UTC';

export const intl = forceSingleton(
'Intl',
() => new IntlLoader(langAttr, timezoneAttr)
Expand Down

0 comments on commit 1477aa4

Please sign in to comment.