import React from 'react'; import { connect } from 'react-redux'; import { injectIntl } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import ProgressBar from '../../../components/progress_bar'; import { fetchPatronInstance } from 'soapbox/actions/patron'; import { Map as ImmutableMap } from 'immutable'; const moneyFormat = amount => ( new Intl .NumberFormat('en-US', { style: 'currency', currency: 'usd', notation: 'compact', }) .format(amount/100) ); class FundingPanel extends ImmutablePureComponent { componentDidMount() { this.props.dispatch(fetchPatronInstance()); } render() { const { patron } = this.props; if (patron.isEmpty()) return null; const amount = patron.getIn(['funding', 'amount']); const goal = patron.getIn(['goals', '0', 'amount']); const goal_text = patron.getIn(['goals', '0', 'text']); const goal_reached = amount >= goal; let ratio_text; if (goal_reached) { ratio_text = <>{moneyFormat(goal)} per month— reached!; } else { ratio_text = <>{moneyFormat(amount)} out of {moneyFormat(goal)} per month; } return (
Funding Goal
{ratio_text}
{goal_text}
Donate
); } }; const mapStateToProps = state => { return { patron: state.getIn(['patron', 'instance'], ImmutableMap()), }; }; export default injectIntl( connect(mapStateToProps, null, null, { forwardRef: true, } )(FundingPanel));