import React from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { injectIntl, FormattedMessage } from 'react-intl'; import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; import ProgressBar from '../../../components/progress_bar'; import { fetchFunding } from 'gabsocial/actions/patron'; class FundingPanel extends ImmutablePureComponent { componentDidMount () { this.props.dispatch(fetchFunding()); } render() { const { funding } = this.props; if (!funding) { return null; } const goal = funding.getIn(['goals', '0', 'amount']); const goal_text = funding.getIn(['goals', '0', 'text']); const goal_reached = funding.get('amount') >= goal; let ratio_text; if (goal_reached) { ratio_text = <>${Math.floor(goal/100)} per month— reached!; } else { ratio_text = <>${Math.floor(funding.get('amount')/100)} out of ${Math.floor(goal/100)} per month; } return (
Funding Goal
{ratio_text}
{goal_text}
Donate
) } }; const mapStateToProps = state => { return { funding: state.getIn(['patron', 'funding']) }; }; export default injectIntl( connect(mapStateToProps, null, null, { forwardRef: true, } )(FundingPanel))