/* eslint-disable no-param-reassign,no-undef */
import { history } from 'umi';

export default {
  namespace: 'loginMobile',
  state: {
    loginLoading: false,
  },
  reducers: {
    showLoginLoading(state) {
      return { ...state, loginLoading: true };
    },
    hideLoginLoading(state) {
      return { ...state, loginLoading: false };
    },
  },
  effects: {
    *login({ payload }, { put }) {
      const {
        token, userinfo, commonConst, systemData, decimals, dateFormat, dispatch,
      } = payload;
      const reStart = false;
      yield put({ type: 'app/saveToken', payload: token });
      yield put({ type: 'app/saveCommonConst', payload: commonConst });
      yield put({ type: 'app/saveUserinfo', payload: userinfo });
      yield put({ type: 'app/createWebSocket', payload: { reStart, dispatch } });
      yield put({ type: 'app/saveSystemData', payload: systemData });
      yield put({ type: 'app/saveDecimals', payload: decimals });
      yield put({ type: 'app/saveDateFormat', payload: dateFormat });
      history.push('/indexMobile');
    },
  },
  subscriptions: {
  },
};
