/ embark-ui / src / containers / ContractOverviewContainer.js
ContractOverviewContainer.js
 1  import React, {Component} from 'react';
 2  import {connect} from 'react-redux';
 3  import PropTypes from 'prop-types';
 4  
 5  import {contractProfile as contractProfileAction, contractFunction as contractFunctionAction} from '../actions';
 6  import ContractOverview from '../components/ContractOverview';
 7  import DataWrapper from "../components/DataWrapper";
 8  import {getContractProfile, getContractFunctions} from "../reducers/selectors";
 9  
10  class ContractOverviewContainer extends Component {
11    componentDidMount() {
12      this.props.fetchContractProfile(this.props.contract.className);
13    }
14  
15    render() {
16      return (
17        <DataWrapper shouldRender={this.props.contractProfile !== undefined}
18                     {...this.props}
19                     render={({contractProfile, contractFunctions, postContractFunction}) => (
20                       <ContractOverview contractProfile={contractProfile}
21                                         contractFunctions={contractFunctions}
22                                         contract={this.props.contract}
23                                         postContractFunction={postContractFunction}/>
24                     )}/>
25      );
26    }
27  }
28  
29  function mapStateToProps(state, props) {
30    return {
31      contractProfile: getContractProfile(state, props.contract.className),
32      contractFunctions: getContractFunctions(state, props.contract.className),
33      error: state.errorMessage,
34      loading: state.loading
35    };
36  }
37  
38  ContractOverviewContainer.propTypes = {
39    contract: PropTypes.object,
40    contractProfile: PropTypes.object,
41    contractFunctions: PropTypes.arrayOf(PropTypes.object),
42    postContractFunction: PropTypes.func,
43    fetchContractProfile: PropTypes.func,
44    error: PropTypes.string
45  };
46  
47  export default connect(
48    mapStateToProps,
49    {
50      fetchContractProfile: contractProfileAction.request,
51      postContractFunction: contractFunctionAction.post
52    }
53  )(ContractOverviewContainer);