import React, { useState,useEffect} from 'react';
import SelectOptions from '../SelectOptions';

import { connect } from 'umi'

const index = (props:any) => {

  const {dispatch, CommunityList,value,onChange } = props;
  const tosCommunityget = (values:any) => {dispatch({type: 'Init/tosCommunityget',playload:values})};  
  useEffect(() => {
    if (CommunityList == null) {
      tosCommunityget(null)
    }    
  }, []); 
  useEffect(() => {
    if (CommunityList != null) {
      onChange({ index:1,value: CommunityList})
    }    
  }, [CommunityList]);

  const printContent = (values:any) => {
    onChange({ index:CommunityList.length==values.length?1:0,value: values})
  }
  return (
    <>
          {
            CommunityList != null ?
            <SelectOptions  list={CommunityList.sort()} show={true} onSubmit={printContent} />:  
            null
          }
             
    </>
  );
};

function mapStateToProps(state:any) {
  const { CommunityList } = state.Init;  
  return {
    CommunityList,
  };
}
export default connect(mapStateToProps)(index);
