feat: add donation form to certificate
This commit is contained in:
committed by
mrugesh
parent
01d1315835
commit
053dbfbba4
@ -3,7 +3,9 @@ import PropTypes from 'prop-types';
|
|||||||
import { bindActionCreators } from 'redux';
|
import { bindActionCreators } from 'redux';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import { Grid, Row, Col, Image } from '@freecodecamp/react-bootstrap';
|
import { Grid, Row, Col, Image, Button } from '@freecodecamp/react-bootstrap';
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
|
import MinimalDonateForm from '../components/Donation/components/MinimalDonateForm';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
showCertSelector,
|
showCertSelector,
|
||||||
@ -19,7 +21,7 @@ import standardErrorMessage from '../utils/standardErrorMessage';
|
|||||||
import reallyWeirdErrorMessage from '../utils/reallyWeirdErrorMessage';
|
import reallyWeirdErrorMessage from '../utils/reallyWeirdErrorMessage';
|
||||||
|
|
||||||
import RedirectHome from '../components/RedirectHome';
|
import RedirectHome from '../components/RedirectHome';
|
||||||
import { Loader, Link } from '../components/helpers';
|
import { Loader, Spacer } from '../components/helpers';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
cert: PropTypes.shape({
|
cert: PropTypes.shape({
|
||||||
@ -73,6 +75,18 @@ const mapDispatchToProps = dispatch =>
|
|||||||
bindActionCreators({ createFlashMessage, showCert }, dispatch);
|
bindActionCreators({ createFlashMessage, showCert }, dispatch);
|
||||||
|
|
||||||
class ShowCertification extends Component {
|
class ShowCertification extends Component {
|
||||||
|
constructor(...args) {
|
||||||
|
super(...args);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
showCloseBtn: false,
|
||||||
|
donationClosed: false
|
||||||
|
};
|
||||||
|
|
||||||
|
this.hideDonationSection = this.hideDonationSection.bind(this);
|
||||||
|
this.showDonationCloseBtn = this.showDonationCloseBtn.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { username, certName, validCertName, showCert } = this.props;
|
const { username, certName, validCertName, showCert } = this.props;
|
||||||
if (validCertName) {
|
if (validCertName) {
|
||||||
@ -80,7 +94,17 @@ class ShowCertification extends Component {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hideDonationSection() {
|
||||||
|
this.setState({ donationClosed: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
showDonationCloseBtn() {
|
||||||
|
this.setState({ showCloseBtn: true });
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
console.log(this.props);
|
||||||
const {
|
const {
|
||||||
cert,
|
cert,
|
||||||
fetchState,
|
fetchState,
|
||||||
@ -92,6 +116,8 @@ class ShowCertification extends Component {
|
|||||||
userFetchState
|
userFetchState
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
const { donationClosed, showCloseBtn } = this.state;
|
||||||
|
|
||||||
if (!validCertName) {
|
if (!validCertName) {
|
||||||
createFlashMessage(standardErrorMessage);
|
createFlashMessage(standardErrorMessage);
|
||||||
return <RedirectHome />;
|
return <RedirectHome />;
|
||||||
@ -122,22 +148,49 @@ class ShowCertification extends Component {
|
|||||||
completionTime
|
completionTime
|
||||||
} = cert;
|
} = cert;
|
||||||
|
|
||||||
let conditionalDonationMessage = '';
|
let conditionalDonationSection = '';
|
||||||
|
|
||||||
if (userComplete && signedInUserName === username && !isDonating) {
|
const donationCloseBtn = (
|
||||||
conditionalDonationMessage = (
|
<div>
|
||||||
<Grid>
|
<Spacer />
|
||||||
<Row className='certification-donation text-center'>
|
<Button
|
||||||
|
block={true}
|
||||||
|
bsSize='sm'
|
||||||
|
bsStyle='primary'
|
||||||
|
onClick={this.hideDonationSection}
|
||||||
|
>
|
||||||
|
close
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
userComplete &&
|
||||||
|
signedInUserName === username &&
|
||||||
|
!isDonating &&
|
||||||
|
!donationClosed
|
||||||
|
) {
|
||||||
|
conditionalDonationSection = (
|
||||||
|
<Grid className='donation-section'>
|
||||||
|
<Row className='certification-donation'>
|
||||||
|
<Col sm={10} smOffset={1} xs={12}>
|
||||||
<p>
|
<p>
|
||||||
Only you can see this message. Congratulations on earning this
|
Only you can see this message. Congratulations on earning this
|
||||||
certification. It’s no easy task. Running freeCodeCamp isn’t easy
|
certification. It’s no easy task. Running freeCodeCamp isn’t
|
||||||
either. Nor is it cheap. Help us help you and many other people
|
easy either. Nor is it cheap. Help us help you and many other
|
||||||
around the world. Make a tax-deductible supporting donation to our
|
people around the world. Make a tax-deductible supporting
|
||||||
nonprofit today.
|
donation to our nonprofit today.
|
||||||
</p>
|
</p>
|
||||||
<Link className={'btn'} to={'/donate'}>
|
</Col>
|
||||||
Check out our donation dashboard
|
</Row>
|
||||||
</Link>
|
<MinimalDonateForm
|
||||||
|
changeCloseBtnLabel={this.showDonationCloseBtn}
|
||||||
|
defaultTheme='light'
|
||||||
|
/>
|
||||||
|
<Row className='certification-donation'>
|
||||||
|
<Col sm={10} smOffset={1} xs={12}>
|
||||||
|
{showCloseBtn ? donationCloseBtn : ''}
|
||||||
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
@ -145,7 +198,7 @@ class ShowCertification extends Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='certificate-outer-wrapper'>
|
<div className='certificate-outer-wrapper'>
|
||||||
{conditionalDonationMessage}
|
{conditionalDonationSection}
|
||||||
<Grid className='certificate-wrapper certification-namespace'>
|
<Grid className='certificate-wrapper certification-namespace'>
|
||||||
<Row>
|
<Row>
|
||||||
<header>
|
<header>
|
||||||
|
@ -19,6 +19,7 @@ import { userSelector } from '../../../redux';
|
|||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
changeCloseBtnLabel: PropTypes.func,
|
changeCloseBtnLabel: PropTypes.func,
|
||||||
|
defaultTheme: PropTypes.string,
|
||||||
donationAmount: PropTypes.number.isRequired,
|
donationAmount: PropTypes.number.isRequired,
|
||||||
donationDuration: PropTypes.string.isRequired,
|
donationDuration: PropTypes.string.isRequired,
|
||||||
email: PropTypes.string,
|
email: PropTypes.string,
|
||||||
@ -176,7 +177,7 @@ class DonateFormChildViewForHOC extends Component {
|
|||||||
|
|
||||||
renderDonateForm() {
|
renderDonateForm() {
|
||||||
const { isFormValid } = this.state;
|
const { isFormValid } = this.state;
|
||||||
const { getDonationButtonLabel, theme } = this.props;
|
const { getDonationButtonLabel, theme, defaultTheme } = this.props;
|
||||||
return (
|
return (
|
||||||
<Form className='donation-form' onSubmit={this.handleSubmit}>
|
<Form className='donation-form' onSubmit={this.handleSubmit}>
|
||||||
<FormGroup className='donation-email-container'>
|
<FormGroup className='donation-email-container'>
|
||||||
@ -193,7 +194,7 @@ class DonateFormChildViewForHOC extends Component {
|
|||||||
</FormGroup>
|
</FormGroup>
|
||||||
<StripeCardForm
|
<StripeCardForm
|
||||||
getValidationState={this.getValidationState}
|
getValidationState={this.getValidationState}
|
||||||
theme={theme}
|
theme={defaultTheme ? defaultTheme : theme}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
block={true}
|
block={true}
|
||||||
|
@ -29,6 +29,7 @@ const numToCommas = num =>
|
|||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
changeCloseBtnLabel: PropTypes.func,
|
changeCloseBtnLabel: PropTypes.func,
|
||||||
|
defaultTheme: PropTypes.string,
|
||||||
isDonating: PropTypes.bool,
|
isDonating: PropTypes.bool,
|
||||||
isSignedIn: PropTypes.bool,
|
isSignedIn: PropTypes.bool,
|
||||||
navigate: PropTypes.func.isRequired,
|
navigate: PropTypes.func.isRequired,
|
||||||
@ -137,7 +138,7 @@ class ModalDonateForm extends Component {
|
|||||||
stripe
|
stripe
|
||||||
} = this.state;
|
} = this.state;
|
||||||
|
|
||||||
const { changeCloseBtnLabel } = this.props;
|
const { changeCloseBtnLabel, defaultTheme } = this.props;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{paymentType === 'Card' ? (
|
{paymentType === 'Card' ? (
|
||||||
@ -145,6 +146,7 @@ class ModalDonateForm extends Component {
|
|||||||
<Elements>
|
<Elements>
|
||||||
<DonateFormChildViewForHOC
|
<DonateFormChildViewForHOC
|
||||||
changeCloseBtnLabel={changeCloseBtnLabel}
|
changeCloseBtnLabel={changeCloseBtnLabel}
|
||||||
|
defaultTheme={defaultTheme}
|
||||||
donationAmount={donationAmount}
|
donationAmount={donationAmount}
|
||||||
donationDuration={donationDuration}
|
donationDuration={donationDuration}
|
||||||
getDonationButtonLabel={this.getDonationButtonLabel}
|
getDonationButtonLabel={this.getDonationButtonLabel}
|
||||||
|
@ -38,8 +38,8 @@
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.certificate-outer-wrapper .certification-donation {
|
.certificate-outer-wrapper .donation-section {
|
||||||
padding: 15px 0px;
|
padding: 20px 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.certificate-outer-wrapper .certification-donation .btn {
|
.certificate-outer-wrapper .certification-donation .btn {
|
||||||
@ -54,6 +54,13 @@
|
|||||||
color: var(--gray-05);
|
color: var(--gray-05);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.certificate-outer-wrapper .btn[disabled],
|
||||||
|
.certificate-outer-wrapper .btn[disabled]:hover {
|
||||||
|
background-color: var(--gray-15);
|
||||||
|
border-color: var(--quaternary-color);
|
||||||
|
color: var(--quaternary-color);
|
||||||
|
}
|
||||||
|
|
||||||
.certification-namespace header {
|
.certification-namespace header {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 140px;
|
height: 140px;
|
||||||
|
Reference in New Issue
Block a user