ENEI2019-Public/App/app/store/reducers/api.js

64 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-02-12 23:07:19 +00:00
import { DATA_AVAILABLE, API_LOGIN, CHECK_USER, LOGOUT_USER, USER_INFO, HOLD, GET_EVENTS } from "../actions/actionTypes" //Import the actions types constant we defined in our actions
2019-02-22 23:38:34 +00:00
import { REHYDRATE } from 'redux-persist';
2019-01-31 00:46:49 +00:00
2019-02-22 23:38:34 +00:00
let apiState= { isConnected:false, token:{valid:false}, tokenData:'error', logged:false, onHold:true,user:{}, events:[], failedAttempt:false}
2019-01-31 00:46:49 +00:00
const apiReducer = (state = apiState, action) => {
switch(action.type){
2019-02-22 23:38:34 +00:00
case REHYDRATE:
console.log( action.payload)
return {
// ...state,
// logged:false,
//onHold:true,
user: action.payload.apiReducer.user
};
case 'CHANGE_CONNECTION_STATUS':
return Object.assign({}, state, {
isConnected: action.isConnected,
});
2019-01-31 00:46:49 +00:00
2019-02-03 20:54:27 +00:00
case HOLD:
2019-02-08 18:56:38 +00:00
state=Object.assign({},state, { onHold:true });
2019-02-03 20:54:27 +00:00
return state;
2019-01-31 00:46:49 +00:00
case API_LOGIN:
2019-02-22 23:38:34 +00:00
state=Object.assign({},state, { logged:action.logged, token:action.token, failedAttempt: action.failedAttempt, user:user});
2019-02-03 20:54:27 +00:00
2019-01-31 00:46:49 +00:00
return state;
case CHECK_USER:
2019-02-22 23:38:34 +00:00
state=Object.assign({},state, { token:action.token,logged:action.logged, onHold:action.onHold});
2019-01-31 00:46:49 +00:00
return state;
case LOGOUT_USER:
2019-02-03 20:54:27 +00:00
state=Object.assign({},state, { token:action.token, logged:false});
2019-01-31 00:46:49 +00:00
return state;
case USER_INFO:
2019-02-17 00:46:36 +00:00
state=Object.assign({},state, { user: action.user , loggedIn:action.loggedIn, onHold:action.onHold});
2019-01-31 00:46:49 +00:00
return state;
2019-02-06 23:24:00 +00:00
case GET_EVENTS:
state=Object.assign({},state, { events: action.events});
return state;
2019-02-22 23:38:34 +00:00
2019-01-31 00:46:49 +00:00
default:
return state;
}
}
2019-02-12 23:07:19 +00:00
export default apiReducer;