Ivan - Create system fixtures and fix language session issues [skip ci]

This commit is contained in:
ivan 2016-08-13 18:36:57 -03:00
parent 04396db948
commit 5a3c0f511f
9 changed files with 77 additions and 5 deletions

View File

@ -1,4 +1,26 @@
import API from 'lib-app/api-call';
import sessionStore from 'lib-app/session-store';
export default {
init() {
if (sessionStore.areConfigsStored()) {
return {
type: 'INIT_CONFIGS_FULFILLED',
payload: {
data: sessionStore.getConfigs()
}
};
} else {
return {
type: 'INIT_CONFIGS',
payload: API.call({
path: '/system/get-configs',
data: {}
})
};
}
},
changeLanguage(newLanguage) {
return {
type: 'CHANGE_LANGUAGE',

View File

@ -3,6 +3,7 @@ import {render} from 'react-dom'
import { Provider } from 'react-redux';
import SessionActions from 'actions/session-actions';
import ConfigActions from 'actions/config-actions';
import routes from './Routes';
import store from './store';
@ -19,6 +20,7 @@ let renderApplication = function () {
render(<Provider store={store}>{routes}</Provider>, document.getElementById('app'));
};
window.store = store;
store.dispatch(ConfigActions.init());
store.dispatch(SessionActions.initSession());
let unsubscribe = store.subscribe(() => {

View File

@ -24,7 +24,7 @@ class MainLayoutHeader extends React.Component {
return (
<div className="main-layout-header">
{this.renderAccessLinks()}
<DropDown className="main-layout-header--languages" items={this.getLanguageList()} onChange={this.changeLanguage.bind(this)}/>
<DropDown {...this.getLanguageSelectorProps()}/>
</div>
);
}
@ -51,6 +51,15 @@ class MainLayoutHeader extends React.Component {
return result;
}
getLanguageSelectorProps() {
return {
className: 'main-layout-header--languages',
items: this.getLanguageList(),
selectedIndex: Object.values(codeLanguages).indexOf(this.props.config.language),
onChange: this.changeLanguage.bind(this)
};
}
getLanguageList() {
return Object.keys(codeLanguages).map((language) => {
return {

View File

@ -62,7 +62,7 @@ class DropDown extends React.Component {
items: this.props.items,
onItemClick: this.handleItemClick.bind(this),
onMouseDown: this.handleListMouseDown.bind(this),
selectedIndex: this.state.selectedIndex
selectedIndex: this.getSelectedIndex()
};
return (

View File

@ -0,0 +1,15 @@
module.exports = [
{
path: '/system/get-configs',
time: 1000,
response: function () {
return {
status: 'success',
data: {
'language': 'us',
'reCaptchaKey': '6LfM5CYTAAAAAGLz6ctpf-hchX2_l0Ge-Bn-n8wS'
}
};
}
}
];

View File

@ -17,6 +17,7 @@ let fixtures = (function () {
// FIXTURES
fixtures.add(require('data/fixtures/user-fixtures'));
fixtures.add(require('data/fixtures/system-fixtures'));
_.each(fixtures.getAll(), function (fixture) {
mockjax({

View File

@ -37,6 +37,22 @@ class SessionStore {
this.setItem('rememberData-expiration', expiration);
}
storeConfigs(configs) {
this.setItem('language', configs.language);
this.setItem('reCaptchaKey', configs.reCaptchaKey);
}
getConfigs() {
return {
language: this.getItem('language'),
reCaptchaKey: this.getItem('reCaptchaKey')
};
}
areConfigsStored() {
return !!this.getItem('reCaptchaKey');
}
isRememberDataExpired() {
let rememberData = this.getRememberData();

View File

@ -13,7 +13,8 @@ class ConfigReducer extends Reducer {
getTypeHandlers() {
return {
'CHANGE_LANGUAGE': this.onLanguageChange
'CHANGE_LANGUAGE': this.onLanguageChange,
'INIT_CONFIGS_FULFILLED': this.onInitConfigs
};
}
@ -24,6 +25,12 @@ class ConfigReducer extends Reducer {
language: payload
});
}
onInitConfigs(state, payload) {
sessionStore.storeConfigs(payload.data);
return _.extend({}, state, payload.data);
}
}
export default ConfigReducer.getInstance();

View File

@ -91,9 +91,9 @@ class SessionReducer extends Reducer {
userId: resultData.userId,
expiration: resultData.rememberExpiration
});
} else {
sessionStore.createSession(resultData.userId, resultData.token);
}
sessionStore.createSession(resultData.userId, resultData.token);
}
}