import * as authenticationActions from './AuthenticationActions' const initialState = { user: null, accessToken: null, showLoginDialog: false, isAdmin: false }; function AuthenticationReducer(state = initialState, action) { switch (action.type) { case authenticationActions.SHOW_LOGIN_DIALOG: return { ...state, showLoginDialog: true, error: null } case authenticationActions.HIDE_LOGIN_DIALOG: return { ...state, showLoginDialog: false, error: null } case authenticationActions.AUTHENTICATION_PENDING: return { ...state, pending: true, error: null } case authenticationActions.AUTHENTICATION_SUCCESS: return { ...state, showLoginDialog: false, pending: false, user: action.user, accessToken: action.accessToken, isAdmin: action.isAdmin } case authenticationActions.AUTHENTICATION_ERROR: return { ...state, pending: false, error: 'Authentication failed' } case authenticationActions.LOGOUT: return { ...state, user: null, accessToken: null, isAdmin: false } default: return state; } } export default AuthenticationReducer;