...
|
...
|
@@ -11,7 +11,28 @@ |
|
|
*/
|
|
|
import InitialState from './userInitialState';
|
|
|
|
|
|
import Immutable, {List, Record} from 'immutable';
|
|
|
|
|
|
const {
|
|
|
|
|
|
DELETE_TOKEN_REQUEST,
|
|
|
DELETE_TOKEN_SUCCESS,
|
|
|
|
|
|
LOGIN_REQUEST,
|
|
|
LOGIN_SUCCESS,
|
|
|
LOGIN_FAILURE,
|
|
|
|
|
|
LOGOUT_REQUEST,
|
|
|
LOGOUT_SUCCESS,
|
|
|
LOGOUT_FAILURE,
|
|
|
|
|
|
SET_SESSION_TOKEN,
|
|
|
|
|
|
RESET_PASSWORD_REQUEST,
|
|
|
RESET_PASSWORD_SUCCESS,
|
|
|
RESET_PASSWORD_FAILURE,
|
|
|
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
const initialState = new InitialState;
|
|
|
|
...
|
...
|
@@ -25,9 +46,46 @@ export default function userReducer(state = initialState, action) { |
|
|
|
|
|
switch (action.type) {
|
|
|
|
|
|
case LOGOUT_REQUEST:
|
|
|
case LOGIN_REQUEST:
|
|
|
case RESET_PASSWORD_REQUEST: {
|
|
|
let nextState = state.set('isFetching', true)
|
|
|
.set('error', null);
|
|
|
return nextState;
|
|
|
}
|
|
|
|
|
|
case LOGIN_SUCCESS: {
|
|
|
const {account, pid, sessionKey, shops} = action.payload;
|
|
|
let ShopRecord = Record({ id: '', name: '' })
|
|
|
let shopsList = Immutable.fromJS(shops, function(key, value) {
|
|
|
return new ShopRecord(value);
|
|
|
});
|
|
|
let nextState = state.set('isFetching', false)
|
|
|
.set('error', null)
|
|
|
.setIn(['profile', 'account'], account)
|
|
|
.setIn(['profile', 'pid'], pid)
|
|
|
.setIn(['profile', 'sessionKey'], sessionKey)
|
|
|
.set('shops', shopsList);
|
|
|
return nextState;
|
|
|
}
|
|
|
|
|
|
case LOGOUT_SUCCESS:
|
|
|
case RESET_PASSWORD_SUCCESS:
|
|
|
return state.set('isFetching', false);
|
|
|
|
|
|
case LOGOUT_FAILURE:
|
|
|
case LOGIN_FAILURE:
|
|
|
case RESET_PASSWORD_FAILURE:
|
|
|
return state.set('isFetching', false)
|
|
|
.set('error', action.payload);
|
|
|
|
|
|
case DELETE_TOKEN_REQUEST:
|
|
|
case DELETE_TOKEN_SUCCESS:
|
|
|
return state;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* ## Default
|
|
|
*/
|
|
|
return state;
|
|
|
} |
...
|
...
|
|