bigbuffet-rw/app/gabsocial/features/ui/components/funding_panel.js

67 lines
1.9 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-03-31 15:45:12 -07:00
import { fetchFunding } from 'gabsocial/actions/patron';
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-03-31 15:45:12 -07:00
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;
2020-03-27 13:59:38 -07:00
let ratio_text;
if (goal_reached) {
ratio_text = <><strong>${Math.floor(goal/100)}</strong> per month<span className='funding-panel__reached'>&mdash; reached!</span></>;
} else {
2020-03-31 15:45:12 -07:00
ratio_text = <><strong>${Math.floor(funding.get('amount')/100)} out of ${Math.floor(goal/100)}</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-03-31 15:45:12 -07:00
<ProgressBar progress={funding.get('amount')/goal} />
2020-03-27 13:59:38 -07:00
<div className='funding-panel__description'>
{goal_text}
</div>
<a className='button' href='/donate'>Donate</a>
</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-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));