Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {
- HOSPITAL_CODE_CHANGED,
- CLEAR_HOSPITAL_CODE,
- AUTH_UPDATE,
- LOGIN_USER,
- LOGIN_USER_FAIL,
- LOGIN_USER_SUCCESS,
- UPDATE_HOSPITAL_SERVER,
- RESET_USER
- } from '../actions/types';
- const INITIAL_STATE = {
- mainServer: {
- url: '172.29.189.130/getServer',
- port: 80,
- protocol: 'http'
- },
- hospitalCode: null,
- hospitalServer: {
- mqtt: {
- url: null,
- port: null,
- protocol: null
- },
- rest: {
- url: null,
- port: null,
- protocol: null
- }
- },
- hospitalName: 'Default',
- username: 'Nursing6C',
- password: 'nursing6c',
- token: '',
- rememberMe: false,
- loading: false,
- error: '',
- user: null
- };
- export default (state = INITIAL_STATE, action) => {
- switch (action.type) {
- case CLEAR_HOSPITAL_CODE:
- return {
- ...state,
- hospitalCode: null
- }
- case RESET_USER:
- return {
- ...state,
- token: '',
- user: null,
- loading: false,
- error: ''
- }
- case HOSPITAL_CODE_CHANGED:
- return {
- ...state,
- hospitalCode: action.payload
- }
- case UPDATE_HOSPITAL_SERVER:
- return {
- ...state,
- hospitalServer: action.payload.server,
- hospitalCode: action.payload.hospitalCode,
- hospitalName: action.payload.hospitalName
- }
- case AUTH_UPDATE:
- return {
- ...state,
- [action.payload.prop]: action.payload.value
- }
- case LOGIN_USER:
- return {
- ...state,
- loading: true,
- error: '',
- user: action.payload
- }
- case LOGIN_USER_SUCCESS:
- return {
- ...state,
- token: action.payload,
- loading: false,
- error: ''
- }
- case LOGIN_USER_FAIL:
- return {
- ...state,
- loading: false,
- error: 'Authentication Failed.' + action.payload,
- password: ''
- }
- default:
- return state
- }
- }
Add Comment
Please, Sign In to add comment