2019-12-09 17:30:24 +01:00
|
|
|
/* eslint-disable max-len */
|
|
|
|
import React from 'react';
|
2019-12-02 15:48:53 +03:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { createSelector } from 'reselect';
|
2019-12-09 22:05:09 +01:00
|
|
|
import { Modal, Button, Col, Row } from '@freecodecamp/react-bootstrap';
|
2019-12-20 16:14:16 +05:30
|
|
|
import { Spacer } from '../helpers';
|
|
|
|
import { blockNameify } from '../../../utils/blockNameify';
|
|
|
|
import Heart from '../../assets/icons/Heart';
|
|
|
|
import Cup from '../../assets/icons/Cup';
|
2019-12-09 22:05:09 +01:00
|
|
|
import MinimalDonateForm from './MinimalDonateForm';
|
2019-12-02 15:48:53 +03:00
|
|
|
|
2019-12-20 16:14:16 +05:30
|
|
|
import ga from '../../analytics';
|
2019-12-02 15:48:53 +03:00
|
|
|
import {
|
|
|
|
closeDonationModal,
|
2019-12-09 17:30:24 +01:00
|
|
|
isDonationModalOpenSelector,
|
2019-12-09 22:05:09 +01:00
|
|
|
isBlockDonationModalSelector
|
2019-12-20 16:14:16 +05:30
|
|
|
} from '../../redux';
|
2019-12-02 15:48:53 +03:00
|
|
|
|
2019-12-20 16:14:16 +05:30
|
|
|
import { challengeMetaSelector } from '../../templates/Challenges/redux';
|
2019-12-02 15:48:53 +03:00
|
|
|
|
2019-12-20 16:14:16 +05:30
|
|
|
import './Donation.css';
|
2019-12-02 15:48:53 +03:00
|
|
|
|
|
|
|
const mapStateToProps = createSelector(
|
|
|
|
isDonationModalOpenSelector,
|
|
|
|
challengeMetaSelector,
|
2019-12-09 17:30:24 +01:00
|
|
|
isBlockDonationModalSelector,
|
2019-12-09 22:05:09 +01:00
|
|
|
(show, { block }, isBlockDonation) => ({
|
2019-12-02 15:48:53 +03:00
|
|
|
show,
|
2019-12-09 17:30:24 +01:00
|
|
|
block,
|
2019-12-09 22:05:09 +01:00
|
|
|
isBlockDonation
|
2019-12-02 15:48:53 +03:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch =>
|
|
|
|
bindActionCreators(
|
|
|
|
{
|
|
|
|
closeDonationModal
|
|
|
|
},
|
|
|
|
dispatch
|
|
|
|
);
|
|
|
|
|
|
|
|
const propTypes = {
|
2019-12-09 17:30:24 +01:00
|
|
|
activeDonors: PropTypes.number,
|
2019-12-02 15:48:53 +03:00
|
|
|
block: PropTypes.string,
|
|
|
|
closeDonationModal: PropTypes.func.isRequired,
|
2019-12-09 17:30:24 +01:00
|
|
|
isBlockDonation: PropTypes.bool,
|
2019-12-02 15:48:53 +03:00
|
|
|
show: PropTypes.bool
|
|
|
|
};
|
|
|
|
|
2019-12-09 22:05:09 +01:00
|
|
|
function DonateModal({ show, block, isBlockDonation, closeDonationModal }) {
|
2019-12-11 13:05:40 +01:00
|
|
|
const [closeLabel, setCloseLabel] = React.useState(false);
|
|
|
|
const showCloseBtn = () => {
|
2019-12-09 22:05:09 +01:00
|
|
|
setCloseLabel(true);
|
|
|
|
};
|
|
|
|
|
2019-12-09 17:30:24 +01:00
|
|
|
if (show) {
|
|
|
|
ga.modalview('/donation-modal');
|
2019-12-02 15:48:53 +03:00
|
|
|
}
|
2019-12-09 17:30:24 +01:00
|
|
|
const blockDonationText = (
|
|
|
|
<div className='block-modal-text'>
|
|
|
|
<div className='donation-icon-container'>
|
|
|
|
<Cup className='donation-icon' />
|
|
|
|
</div>
|
2019-12-09 22:05:09 +01:00
|
|
|
<Row>
|
|
|
|
<Col sm={10} smOffset={1} xs={12}>
|
|
|
|
<p>Nicely done. You just completed {blockNameify(block)}.</p>
|
|
|
|
<p>Help us create even more learning resources like this.</p>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2019-12-09 17:30:24 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
const progressDonationText = (
|
|
|
|
<div className='text-center progress-modal-text'>
|
|
|
|
<div className='donation-icon-container'>
|
|
|
|
<Heart className='donation-icon' />
|
|
|
|
</div>
|
2019-12-09 22:05:09 +01:00
|
|
|
<Row>
|
|
|
|
<Col sm={10} smOffset={1} xs={12}>
|
|
|
|
<p>
|
|
|
|
Help us create even more learning resources for you and your family.
|
|
|
|
</p>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2019-12-09 17:30:24 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal bsSize='lg' className='donation-modal' show={show}>
|
|
|
|
<Modal.Header className='fcc-modal'>
|
|
|
|
<Modal.Title className='modal-title text-center'>
|
2019-12-09 22:05:09 +01:00
|
|
|
<strong>Become a Supporter</strong>
|
2019-12-09 17:30:24 +01:00
|
|
|
</Modal.Title>
|
|
|
|
</Modal.Header>
|
|
|
|
<Modal.Body>
|
|
|
|
{isBlockDonation ? blockDonationText : progressDonationText}
|
2019-12-09 22:05:09 +01:00
|
|
|
<Spacer />
|
2019-12-11 13:05:40 +01:00
|
|
|
<MinimalDonateForm showCloseBtn={showCloseBtn} />
|
2019-12-09 22:05:09 +01:00
|
|
|
<Spacer />
|
|
|
|
<Row>
|
|
|
|
<Col sm={10} smOffset={1} xs={12}>
|
|
|
|
<Button
|
|
|
|
block={true}
|
|
|
|
bsSize='sm'
|
|
|
|
bsStyle='primary'
|
|
|
|
className='btn-link'
|
|
|
|
onClick={closeDonationModal}
|
2019-12-18 09:36:43 +01:00
|
|
|
tabIndex='0'
|
2019-12-09 22:05:09 +01:00
|
|
|
>
|
2019-12-12 20:08:25 +05:30
|
|
|
{closeLabel ? 'Close.' : 'Ask me later.'}
|
2019-12-09 22:05:09 +01:00
|
|
|
</Button>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2019-12-09 17:30:24 +01:00
|
|
|
</Modal.Body>
|
|
|
|
</Modal>
|
|
|
|
);
|
2019-12-02 15:48:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DonateModal.displayName = 'DonateModal';
|
|
|
|
DonateModal.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(DonateModal);
|