import { TREAT_DEMAND_GROUP_PENDING, TREAT_DEMAND_GROUP_SUCCESS, TREAT_DEMAND_GROUP_ERROR, TREAT_DEMAND_GROUP_RESET } from "../types/NanoCreditType";

const initialState = {
     loading: false,
     result: null,
     error: null
};

export default (state = initialState, action) => {
     switch (action.type) {
          case TREAT_DEMAND_GROUP_PENDING: return {
               ...state,
               loading: true
          }
          case TREAT_DEMAND_GROUP_SUCCESS: return {
               ...state,
               loading: false,
               result: action.result.data,
               error: null
          }
          case TREAT_DEMAND_GROUP_ERROR: return {
               ...state,
               loading: false,
               result: null,
               error: action.result
          }
          case TREAT_DEMAND_GROUP_RESET: return initialState;

          default: {
               return state;
          }
     }
};
