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

import {
  State,
  initialState,
} from './member-signup.state';

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

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

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

    default: {
      return state;
    }
  }
}
