get locale from user if exists

This commit is contained in:
Delucse
2020-12-14 14:48:12 +01:00
parent e52e3943c1
commit c6a1e854d2
6 changed files with 48 additions and 21 deletions
+9 -2
View File
@@ -1,8 +1,8 @@
import { MYBADGES_CONNECT, MYBADGES_DISCONNECT, USER_LOADED, USER_LOADING, AUTH_ERROR, LOGIN_SUCCESS, LOGIN_FAIL, LOGOUT_SUCCESS, LOGOUT_FAIL, REFRESH_TOKEN_SUCCESS } from '../actions/types';
import axios from 'axios';
import { returnErrors, returnSuccess } from './messageActions'
import { returnErrors, returnSuccess } from './messageActions';
import { setLanguage } from './generalActions';
// Check token & load user
export const loadUser = () => (dispatch) => {
@@ -16,6 +16,7 @@ export const loadUser = () => (dispatch) => {
type: USER_LOADED,
payload: res.data.user
});
dispatch(setLanguage(res.data.user.language));
},
error: err => {
if(err.response){
@@ -61,6 +62,7 @@ export const login = ({ email, password }) => (dispatch) => {
type: LOGIN_SUCCESS,
payload: res.data
});
dispatch(setLanguage(res.data.user.language));
dispatch(returnSuccess(res.data.message, res.status, 'LOGIN_SUCCESS'));
})
.catch(err => {
@@ -130,6 +132,11 @@ export const logout = () => (dispatch) => {
dispatch({
type: LOGOUT_SUCCESS
});
var locale = 'de_DE';
if (window.localStorage.getItem('locale')) {
locale = window.localStorage.getItem('locale');
}
dispatch(setLanguage(locale));
dispatch(returnSuccess(res.data.message, res.status, 'LOGOUT_SUCCESS'));
clearTimeout(logoutTimerId);
},
+4 -1
View File
@@ -7,7 +7,10 @@ export const visitPage = () => (dispatch) => {
});
};
export const setLanguage = (language) => (dispatch) => {
export const setLanguage = (language) => (dispatch, getState) => {
if(!getState().auth.isAuthenticated){
window.localStorage.setItem('locale', language);
}
dispatch({
type: LANGUAGE,
payload: language