Skip to content
Snippets Groups Projects
RootReducer.js 1.37 KiB
Newer Older
Orlando Piñero's avatar
Orlando Piñero committed
import * as authenticationActions from '../actions/AuthenticationActions'

Orlando Piñero's avatar
Orlando Piñero committed
const initialState = {
Orlando Piñero's avatar
Orlando Piñero committed
    user: null,
Orlando Piñero's avatar
Orlando Piñero committed
    loginPending: false,
    showLoginDialog: false
};

function rootReducer(state = initialState, action) {

    console.log("Bin im reducer: " + action.type)
Orlando Piñero's avatar
Orlando Piñero committed

    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
            }
        case authenticationActions.AUTHENTICATION_ERROR:
            return {
                ...state,
                pending: false,
                error: 'Authentication failed'
            }
        default:
            return state;
    }
Orlando Piñero's avatar
Orlando Piñero committed
};

export default rootReducer;