diff --git a/source/i18n.js b/source/i18n.js index ce175dc27..412e17b6d 100644 --- a/source/i18n.js +++ b/source/i18n.js @@ -2,16 +2,12 @@ import i18next from 'i18next' import queryString from 'query-string' import { initReactI18next } from 'react-i18next' import enTranslations from './locales/en.yaml' -import { getIframeOption, parseDataAttributes } from './utils' - -let getFromSessionStorage = where => - typeof sessionStorage !== 'undefined' ? sessionStorage[where] : null - -let setToSessionStorage = (where, what) => - typeof sessionStorage !== 'undefined' && - do { - sessionStorage[where] = what - } +import { + getFromSessionStorage, + getIframeOption, + parseDataAttributes, + setToSessionStorage +} from './utils' let lang = getIframeOption('lang') || diff --git a/source/sites/mon-entreprise.fr/App.js b/source/sites/mon-entreprise.fr/App.js index dc0df1d71..ada37929c 100644 --- a/source/sites/mon-entreprise.fr/App.js +++ b/source/sites/mon-entreprise.fr/App.js @@ -21,7 +21,7 @@ import { retrievePersistedSimulation } from '../../storage/persistSimulation' import ReactPiwik from '../../Tracker' -import { inIframe } from '../../utils' +import { inIframe, setToSessionStorage } from '../../utils' import './App.css' import Footer from './layout/Footer/Footer' import Header from './layout/Header/Header' @@ -60,9 +60,7 @@ const middlewares = [ class InFranceRoute extends Component { componentDidMount() { - if (typeof sessionStorage !== 'undefined') { - sessionStorage['lang'] = this.props.language - } + setToSessionStorage('lang', this.props.language) } render() { const paths = constructLocalizedSitePath(this.props.language) diff --git a/source/utils.js b/source/utils.js index 2752334b6..7c6502008 100644 --- a/source/utils.js +++ b/source/utils.js @@ -66,7 +66,7 @@ export function inIframe() { } } -export function softCatch( +export function softCatch( fn: ArgType => ReturnType ): ArgType => ReturnType | null { return function(...args) { @@ -102,3 +102,13 @@ export const constructSitePaths = ( sitePaths ) }) + +export const getFromSessionStorage = softCatch(where => { + typeof sessionStorage !== 'undefined' ? sessionStorage[where] : null +}) + +export const setToSessionStorage = softCatch((where, what) => { + if (typeof sessionStorage !== 'undefined') { + sessionStorage[where] = what + } +})