pleroma/app/soapbox/features/ui/components/funding_panel.js

79 lines
2.2 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import React from 'react';
import { connect } from 'react-redux';
2020-04-14 13:45:38 -07:00
import { injectIntl } from 'react-intl';
2020-03-27 13:59:38 -07:00
import ImmutablePureComponent from 'react-immutable-pure-component';
import ProgressBar from '../../../components/progress_bar';
2020-05-28 15:52:07 -07:00
import { fetchFunding } from 'soapbox/actions/patron';
2020-03-27 13:59:38 -07:00
2020-06-30 15:33:21 -07:00
const moneyFormat = amount => (
new Intl
.NumberFormat('en-US', {
style: 'currency',
currency: 'usd',
notation: 'compact',
})
.format(amount/100)
);
2020-03-27 13:59:38 -07:00
class FundingPanel extends ImmutablePureComponent {
2020-03-31 15:45:12 -07:00
componentDidMount() {
2020-03-31 15:45:12 -07:00
this.props.dispatch(fetchFunding());
}
2020-03-27 13:59:38 -07:00
render() {
2020-06-30 15:33:21 -07:00
const { funding, patronUrl } = this.props;
2020-03-31 15:45:12 -07:00
if (!funding) {
return null;
}
2020-06-30 15:33:21 -07:00
const amount = funding.getIn(['funding', 'amount']);
2020-03-31 15:45:12 -07:00
const goal = funding.getIn(['goals', '0', 'amount']);
const goal_text = funding.getIn(['goals', '0', 'text']);
2020-06-30 15:33:21 -07:00
const goal_reached = amount >= goal;
2020-03-27 13:59:38 -07:00
let ratio_text;
if (goal_reached) {
2020-06-30 15:33:21 -07:00
ratio_text = <><strong>{moneyFormat(goal)}</strong> per month<span className='funding-panel__reached'>&mdash; reached!</span></>;
2020-03-27 13:59:38 -07:00
} else {
2020-06-30 15:33:21 -07:00
ratio_text = <><strong>{moneyFormat(amount)} out of {moneyFormat(goal)}</strong> per month</>;
2020-03-27 13:59:38 -07:00
}
return (
<div className='wtf-panel funding-panel'>
<div className='wtf-panel-header'>
2020-04-14 11:44:40 -07:00
<i role='img' alt='users' className='fa fa-line-chart wtf-panel-header__icon' />
2020-03-27 13:59:38 -07:00
<span className='wtf-panel-header__label'>
<span>Funding Goal</span>
</span>
</div>
<div className='wtf-panel__content'>
<div className='funding-panel__ratio'>
{ratio_text}
</div>
2020-06-30 15:33:21 -07:00
<ProgressBar progress={amount/goal} />
2020-03-27 13:59:38 -07:00
<div className='funding-panel__description'>
{goal_text}
</div>
2020-06-30 15:33:21 -07:00
{patronUrl && <a className='button' href={patronUrl}>Donate</a>}
2020-03-27 13:59:38 -07:00
</div>
</div>
2020-04-14 11:44:40 -07:00
);
2020-03-27 13:59:38 -07:00
}
2020-04-14 11:44:40 -07:00
2020-03-27 13:59:38 -07:00
};
const mapStateToProps = state => {
return {
2020-04-14 11:44:40 -07:00
funding: state.getIn(['patron', 'funding']),
2020-06-30 15:33:21 -07:00
patronUrl: state.getIn(['soapbox', 'extensions', 'patron', 'baseUrl']),
2020-03-27 13:59:38 -07:00
};
};
export default injectIntl(
connect(mapStateToProps, null, null, {
forwardRef: true,
}
2020-04-14 11:44:40 -07:00
)(FundingPanel));