{"size": 928, "ext": "js", "max_stars_repo_path": "src/models/register.js", "max_stars_repo_name": "Log-Loss/hinet-front", "max_stars_repo_stars_event_min_datetime": "2018-03-06T06:00:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-27T20:49:53.000Z", "max_issues_repo_path": "src/models/register.js", "max_issues_repo_name": "Log-Loss/hinet-front", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/models/register.js", "max_forks_repo_name": "Log-Loss/hinet-front", "max_forks_repo_forks_event_min_datetime": "2018-03-06T08:18:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-27T08:52:33.000Z"}
{"max_stars_count": 39, "max_issues_count": null, "max_forks_count": 3, "avg_line_length": 19.7446808511, "max_line_length": 61, "alphanum_fraction": 0.5107758621}
import { register } from '../services/api';

export default {
  namespace: 'register',

  state: {
    code: undefined,
  },

  effects: {
    *submit({ payload }, { call, put }) {
      yield put({
        type: 'changeSubmitting',
        payload: true,
      });
      const response = yield call(register, payload);
      if (response.code === 200) {
        localStorage.setItem('id', response.result.id);
        localStorage.setItem('email', response.result.email);
      }
      yield put({
        type: 'registerHandle',
        payload: response,
      });
      yield put({
        type: 'changeSubmitting',
        payload: false,
      });
    },
  },

  reducers: {
    registerHandle(state, { payload }) {
      return {
        ...state,
        code: payload.code,
      };
    },
    changeSubmitting(state, { payload }) {
      return {
        ...state,
        submitting: payload,
      };
    },
  },
};
