import {
  Actions,
  ActionType,
} from './modify.action';

import {
  State,
  initialState,
} from './modify.state';

export function reducer(state = initialState, action: Actions): State {
  switch (action.type) {
    case ActionType.Modify: {
      return {
        ...state,
        error: null,
        pending: true,
      };
    }

    case ActionType.ModifySuccess: {
      return {
        ...state,
        error: null,
        pending: false,
        member: action.payload,
      };
    }

    case ActionType.ModifyFailure: {
      return {
        ...state,
        error: action.payload,
        pending: false,
        member: null,
      };
    }

    default: {
      return state;
    }
  }
}
