text: import { connect } from 'react-redux';
  import {EnhanceLoading} from '../../../components/Enhance';
  import {Action} from '../../../action-reducer/action';
  import {getPathValue} from '../../../action-reducer/helper';
  import {buildOrderPageState} from './OrderPageContainer';
  import Complete from './Complete';
  
  const prefix = ['complete'];
  const action = new Action(prefix);
  
  const getSelfState = (rootState) => {
    return getPathValue(rootState, prefix);
  };
  
  const initActionCreator = () => async (dispatch) => {
    dispatch(action.assign({status: 'loading'}));
    const state = await buildOrderPageState();
    if (!state) {
      dispatch(action.assign({status: 'retry'}));
      return;
    }
    dispatch(action.create(state));
  };
  
  const tabChangeActionCreator = (key) => {
    return action.assign({activeKey: key});
  };
  
  const tabCloseActionCreator = (key) => (dispatch, getState) => {
    const {activeKey, tabs} = getSelfState(getState());
    const newTabs = tabs.filter(tab => tab.key !== key);
    if (activeKey === key) {
      let index = tabs.findIndex(tab => tab.key === key);
      (newTabs.length === index) && (index--);
      dispatch(action.assign({tabs: newTabs, [activeKey]: undefined, activeKey: newTabs[index].key}));
    } else {
      dispatch(action.assign({tabs: newTabs, [key]: undefined}));
    }
  };
  
  const mapStateToProps = (state) => {
    return getSelfState(state);
  };
  
  const actionCreators = {
    onInit: initActionCreator,
    onTabChange: tabChangeActionCreator,
    onTabClose: tabCloseActionCreator
  };
  
  const Container = connect(mapStateToProps, actionCreators)(EnhanceLoading(Complete));
  export default Container;
  