text: import {
    USER_LOADING,
    USER_LOADED,
    AUTH_ERROR,
    REGISTER_FAIL,
    REGISTER_SUCCESS,
    LOGIN_SUCCESS,
    LOGIN_FAIL,
    LOGOUT_SUCCESS,
    UPDATE_SUCCESS,
    UPDATE_FAIL
  } from '../actions/types';
  
  const initialState = {
    token: localStorage.getItem('token'),
    isAuthenticated: false,
    isLoading: false,
    user: null,
  };
  
  const reducer = (state = initialState, action) => {
    switch (action.type) {
      case USER_LOADING:
        return {
          ...state,
          isLoading: true,
        };
      case USER_LOADED:
        return {
          ...state,
          isLoading: false,
          isAuthenticated: true,
          user: action.payload,
        };
      case LOGIN_SUCCESS:
        return {
          ...state,
          ...action.payload,
          isLoading: false,
          isAuthenticated: true,
        };
      case REGISTER_SUCCESS:
        return {
          ...state,
          ...action.payload,
          isLoading: false,
          isAuthenticated: true,
        };
      case AUTH_ERROR:
      case REGISTER_FAIL:
      case LOGIN_FAIL:
      case LOGOUT_SUCCESS:
        localStorage.removeItem('token');
        return {
          ...state,
          token: null,
          isLoading: false,
          isAuthenticated: false,
          user: null,
        };
      case UPDATE_SUCCESS:
        return {
          ...state,
          ...action.payload,
          isLoading: false,
          isAuthenticated: true
        }
      default:
        return state;
    }
  };
  
  export default reducer;