/* like mutation */
import ACTION from '../actions/actiontsTypes';

const initialState = {
    token: null,
    role: null,
    userName: null,
    isFetching: false,
    error: null
};

export default function (state = initialState, action) {
    switch (action.type) {
        case ACTION.USER_DATA_REQUEST: {
            return {
                ...state,
                isFetching: true,
                error: null
            }
        }
        case ACTION.USER_DATA_RESPONSE: {
            return {
                ...state,
                token: action.token,
                role: action.role,
                userName: action.userName,
                isFetching: false,
                error: null
            }
        }
        case ACTION.USER_DATA_ERROR: {
            return {
                ...state,
                error: action.error.response.data,
                isFetching: false
            }
        }
        default: {
            return state
        }
    }
}

