github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/build-blockchain-insurance-app-master/web/src/police/components/TheftClaimsPage.js (about)

     1  'use strict';
     2  
     3  import React, { Props } from 'react';
     4  import PropTypes from 'prop-types';
     5  import { FormattedMessage, injectIntl, intlShape } from 'react-intl';
     6  import { connect } from 'react-redux';
     7  import { bindActionCreators } from 'redux';
     8  
     9  import Loading from '../../shared/Loading';
    10  import * as policeActions from '../actions/policeActions';
    11  import TheftClaimComponent from './TheftClaimComponent';
    12  
    13  class TheftClaimsPage extends React.Component {
    14  
    15    static get propTypes() {
    16      return {
    17        intl: intlShape.isRequired,
    18        theftClaims: PropTypes.array,
    19        loading: PropTypes.bool.isRequired,
    20        policeActions: PropTypes.object.isRequired
    21      };
    22    }
    23  
    24    constructor(props) {
    25      super(props);
    26  
    27      this.toTheftClaimComponent = this.toTheftClaimComponent.bind(this);
    28    }
    29  
    30    toTheftClaimComponent(theftClaim, index) {
    31      return (
    32        <TheftClaimComponent key={index} theftClaim={theftClaim}
    33          onProcessedClaim={this.props.policeActions.processTheftClaim} />
    34      );
    35    }
    36  
    37    render() {
    38      const { theftClaims, loading, intl } = this.props;
    39  
    40      const cards = Array.isArray(theftClaims) ?
    41        theftClaims.map(this.toTheftClaimComponent) : null;
    42      const claims = ((Array.isArray(cards) && cards.length > 0) ||
    43        cards === null) ? cards :
    44        (
    45          <div className='ibm-col-5-5 ibm-col-medium-6-6'>
    46            <FormattedMessage id='No outstanding theft claims.' />
    47          </div>
    48        );
    49      return (
    50        <Loading hidden={loading}
    51          text={intl.formatMessage({ id: 'Loading Theft Claims...' })}>
    52          <div className='ibm-columns ibm-cards' style={{ minHeight: '30vh' }}
    53            data-widget='masonry' data-items='.ibm-col-6-2'>
    54            {claims}
    55          </div>
    56        </Loading>
    57      );
    58    }
    59  }
    60  
    61  function mapStateToProps(state, ownProps) {
    62    return {
    63      theftClaims: state.police.theftClaims,
    64      loading: Array.isArray(state.police.theftClaims)
    65    };
    66  }
    67  
    68  function mapDispatchToProps(dispatch) {
    69    return {
    70      policeActions: bindActionCreators(policeActions, dispatch)
    71    };
    72  }
    73  
    74  export default connect(mapStateToProps, mapDispatchToProps)(
    75    injectIntl(TheftClaimsPage));