From 053dbfbba443fc0699e87784e1274525b3a8f91d Mon Sep 17 00:00:00 2001 From: Ahmad Abdolsaheb Date: Tue, 10 Dec 2019 15:32:19 +0100 Subject: [PATCH] feat: add donation form to certificate --- .../client-only-routes/ShowCertification.js | 89 +++++++++++++++---- .../components/DonateFormChildViewForHOC.js | 5 +- .../Donation/components/MinimalDonateForm.js | 4 +- client/src/pages/certification.css | 11 ++- 4 files changed, 86 insertions(+), 23 deletions(-) diff --git a/client/src/client-only-routes/ShowCertification.js b/client/src/client-only-routes/ShowCertification.js index 7a71b6c459..e6eb0f66c0 100644 --- a/client/src/client-only-routes/ShowCertification.js +++ b/client/src/client-only-routes/ShowCertification.js @@ -3,7 +3,9 @@ import PropTypes from 'prop-types'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; 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 { showCertSelector, @@ -19,7 +21,7 @@ import standardErrorMessage from '../utils/standardErrorMessage'; import reallyWeirdErrorMessage from '../utils/reallyWeirdErrorMessage'; import RedirectHome from '../components/RedirectHome'; -import { Loader, Link } from '../components/helpers'; +import { Loader, Spacer } from '../components/helpers'; const propTypes = { cert: PropTypes.shape({ @@ -73,6 +75,18 @@ const mapDispatchToProps = dispatch => bindActionCreators({ createFlashMessage, showCert }, dispatch); 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() { const { username, certName, validCertName, showCert } = this.props; if (validCertName) { @@ -80,7 +94,17 @@ class ShowCertification extends Component { } return null; } + + hideDonationSection() { + this.setState({ donationClosed: true }); + } + + showDonationCloseBtn() { + this.setState({ showCloseBtn: true }); + } + render() { + console.log(this.props); const { cert, fetchState, @@ -92,6 +116,8 @@ class ShowCertification extends Component { userFetchState } = this.props; + const { donationClosed, showCloseBtn } = this.state; + if (!validCertName) { createFlashMessage(standardErrorMessage); return ; @@ -122,22 +148,49 @@ class ShowCertification extends Component { completionTime } = cert; - let conditionalDonationMessage = ''; + let conditionalDonationSection = ''; - if (userComplete && signedInUserName === username && !isDonating) { - conditionalDonationMessage = ( - - -

- Only you can see this message. Congratulations on earning this - certification. It’s no easy task. Running freeCodeCamp isn’t easy - either. Nor is it cheap. Help us help you and many other people - around the world. Make a tax-deductible supporting donation to our - nonprofit today. -

- - Check out our donation dashboard - + const donationCloseBtn = ( +
+ + +
+ ); + + if ( + userComplete && + signedInUserName === username && + !isDonating && + !donationClosed + ) { + conditionalDonationSection = ( + + + +

+ Only you can see this message. Congratulations on earning this + certification. It’s no easy task. Running freeCodeCamp isn’t + easy either. Nor is it cheap. Help us help you and many other + people around the world. Make a tax-deductible supporting + donation to our nonprofit today. +

+ +
+ + + + {showCloseBtn ? donationCloseBtn : ''} +
); @@ -145,7 +198,7 @@ class ShowCertification extends Component { return (
- {conditionalDonationMessage} + {conditionalDonationSection}
diff --git a/client/src/components/Donation/components/DonateFormChildViewForHOC.js b/client/src/components/Donation/components/DonateFormChildViewForHOC.js index e9ffdc99bf..7c4ae1101a 100644 --- a/client/src/components/Donation/components/DonateFormChildViewForHOC.js +++ b/client/src/components/Donation/components/DonateFormChildViewForHOC.js @@ -19,6 +19,7 @@ import { userSelector } from '../../../redux'; const propTypes = { changeCloseBtnLabel: PropTypes.func, + defaultTheme: PropTypes.string, donationAmount: PropTypes.number.isRequired, donationDuration: PropTypes.string.isRequired, email: PropTypes.string, @@ -176,7 +177,7 @@ class DonateFormChildViewForHOC extends Component { renderDonateForm() { const { isFormValid } = this.state; - const { getDonationButtonLabel, theme } = this.props; + const { getDonationButtonLabel, theme, defaultTheme } = this.props; return (
@@ -193,7 +194,7 @@ class DonateFormChildViewForHOC extends Component {