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
|
|
|
|
|
|
|
import {
|
|
|
|
closeDonationModal,
|
2019-12-09 17:30:24 +01:00
|
|
|
isDonationModalOpenSelector,
|
2020-02-04 08:43:56 +03:00
|
|
|
isBlockDonationModalSelector,
|
|
|
|
executeGA
|
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(
|
|
|
|
{
|
2020-02-04 08:43:56 +03:00
|
|
|
closeDonationModal,
|
|
|
|
executeGA
|
2019-12-02 15:48:53 +03:00
|
|
|
},
|
|
|
|
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,
|
2020-02-04 08:43:56 +03:00
|
|
|
executeGA: PropTypes.func,
|
2019-12-09 17:30:24 +01:00
|
|
|
isBlockDonation: PropTypes.bool,
|
2019-12-02 15:48:53 +03:00
|
|
|
show: PropTypes.bool
|
|
|
|
};
|
|
|
|
|
2020-02-04 08:43:56 +03:00
|
|
|
function DonateModal({
|
|
|
|
show,
|
|
|
|
block,
|
|
|
|
isBlockDonation,
|
|
|
|
closeDonationModal,
|
|
|
|
executeGA
|
|
|
|
}) {
|
2019-12-11 13:05:40 +01:00
|
|
|
const [closeLabel, setCloseLabel] = React.useState(false);
|
2020-02-04 08:43:56 +03:00
|
|
|
const handleProcessing = (duration, amount) => {
|
|
|
|
executeGA({
|
|
|
|
type: 'event',
|
|
|
|
data: {
|
|
|
|
category: 'donation',
|
|
|
|
action: 'Modal strip form submission',
|
|
|
|
label: duration,
|
|
|
|
value: amount
|
|
|
|
}
|
|
|
|
});
|
2019-12-09 22:05:09 +01:00
|
|
|
setCloseLabel(true);
|
|
|
|
};
|
|
|
|
|
2019-12-09 17:30:24 +01:00
|
|
|
if (show) {
|
2020-02-04 08:43:56 +03:00
|
|
|
executeGA({ type: 'modal', data: '/donation-modal' });
|
|
|
|
executeGA({
|
|
|
|
type: 'event',
|
|
|
|
data: {
|
|
|
|
category: 'Donation',
|
|
|
|
action: `Displayed ${
|
|
|
|
isBlockDonation ? 'block' : 'progress'
|
|
|
|
} donation modal`,
|
|
|
|
nonInteraction: true
|
|
|
|
}
|
|
|
|
});
|
2019-12-02 15:48:53 +03:00
|
|
|
}
|
2019-12-23 15:31:10 +03:00
|
|
|
|
|
|
|
const donationText = (
|
|
|
|
<b>
|
|
|
|
Become a supporter and help us create even more learning resources for
|
|
|
|
you.
|
|
|
|
</b>
|
|
|
|
);
|
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>
|
2019-12-23 15:31:10 +03:00
|
|
|
{!closeLabel && (
|
|
|
|
<Col sm={10} smOffset={1} xs={12}>
|
2020-01-21 11:49:25 +03:00
|
|
|
<b>Nicely done. You just completed {blockNameify(block)}. </b>
|
2019-12-23 15:31:10 +03:00
|
|
|
{donationText}
|
|
|
|
</Col>
|
|
|
|
)}
|
2019-12-09 22:05:09 +01:00
|
|
|
</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>
|
2019-12-23 15:31:10 +03:00
|
|
|
{!closeLabel && (
|
|
|
|
<Col sm={10} smOffset={1} xs={12}>
|
|
|
|
{donationText}
|
|
|
|
</Col>
|
|
|
|
)}
|
2019-12-09 22:05:09 +01:00
|
|
|
</Row>
|
2019-12-09 17:30:24 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal bsSize='lg' className='donation-modal' show={show}>
|
|
|
|
<Modal.Body>
|
|
|
|
{isBlockDonation ? blockDonationText : progressDonationText}
|
2019-12-09 22:05:09 +01:00
|
|
|
<Spacer />
|
2020-02-04 08:43:56 +03:00
|
|
|
<MinimalDonateForm handleProcessing={handleProcessing} />
|
2019-12-09 22:05:09 +01:00
|
|
|
<Spacer />
|
|
|
|
<Row>
|
2019-12-23 15:31:10 +03:00
|
|
|
<Col sm={4} smOffset={4} xs={8} xsOffset={2}>
|
2019-12-09 22:05:09 +01:00
|
|
|
<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-23 15:31:10 +03:00
|
|
|
{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);
|