web.common: added value 'language' to localStorage

This commit is contained in:
Daniil Senkiv 2020-01-20 16:20:19 +03:00
parent 28b0eced9d
commit a6f6cf4fea
2 changed files with 8 additions and 0 deletions

View File

@ -1,4 +1,5 @@
export const AUTH_KEY = 'asc_auth_key';
export const LANGUAGE = 'language';
/**
* Enum for employee activation status.

View File

@ -3,6 +3,7 @@ import {
SET_PORTAL_CULTURES, SET_PORTAL_LANGUAGE_AND_TIME, SET_TIMEZONES, SET_CURRENT_PRODUCT_ID, SET_CURRENT_PRODUCT_HOME_PAGE, SET_GREETING_SETTINGS,
} from './actions';
import isEmpty from "lodash/isEmpty";
import { LANGUAGE } from '../../constants';
const initialState = {
isAuthenticated: false,
@ -35,6 +36,9 @@ const initialState = {
const authReducer = (state = initialState, action) => {
switch (action.type) {
case SET_CURRENT_USER:
action.user.cultureName
&& localStorage.getItem(LANGUAGE) !== action.user.cultureName
&& localStorage.setItem(LANGUAGE, action.user.cultureName);
return Object.assign({}, state, {
isAuthenticated: !isEmpty(action.user),
user: action.user
@ -44,6 +48,9 @@ const authReducer = (state = initialState, action) => {
modules: action.modules
});
case SET_SETTINGS:
if (!localStorage.getItem(LANGUAGE)) {
localStorage.setItem(LANGUAGE, action.settings.culture);
}
return Object.assign({}, state, {
settings: { ...state.settings, ...action.settings }
});