chore: address review comments
Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
committed by
mrugesh
parent
053dbfbba4
commit
00f18dc21c
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable react/jsx-sort-props */
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { bindActionCreators } from 'redux';
|
import { bindActionCreators } from 'redux';
|
||||||
@ -79,7 +80,7 @@ class ShowCertification extends Component {
|
|||||||
super(...args);
|
super(...args);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
showCloseBtn: false,
|
closeBtn: false,
|
||||||
donationClosed: false
|
donationClosed: false
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -100,11 +101,10 @@ class ShowCertification extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showDonationCloseBtn() {
|
showDonationCloseBtn() {
|
||||||
this.setState({ showCloseBtn: true });
|
this.setState({ closeBtn: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
console.log(this.props);
|
|
||||||
const {
|
const {
|
||||||
cert,
|
cert,
|
||||||
fetchState,
|
fetchState,
|
||||||
@ -116,7 +116,7 @@ class ShowCertification extends Component {
|
|||||||
userFetchState
|
userFetchState
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
const { donationClosed, showCloseBtn } = this.state;
|
const { donationClosed, closeBtn } = this.state;
|
||||||
|
|
||||||
if (!validCertName) {
|
if (!validCertName) {
|
||||||
createFlashMessage(standardErrorMessage);
|
createFlashMessage(standardErrorMessage);
|
||||||
@ -159,7 +159,7 @@ class ShowCertification extends Component {
|
|||||||
bsStyle='primary'
|
bsStyle='primary'
|
||||||
onClick={this.hideDonationSection}
|
onClick={this.hideDonationSection}
|
||||||
>
|
>
|
||||||
close
|
Close.
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -184,12 +184,12 @@ class ShowCertification extends Component {
|
|||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<MinimalDonateForm
|
<MinimalDonateForm
|
||||||
changeCloseBtnLabel={this.showDonationCloseBtn}
|
showCloseBtn={this.showDonationCloseBtn}
|
||||||
defaultTheme='light'
|
defaultTheme='light'
|
||||||
/>
|
/>
|
||||||
<Row className='certification-donation'>
|
<Row className='certification-donation'>
|
||||||
<Col sm={10} smOffset={1} xs={12}>
|
<Col sm={10} smOffset={1} xs={12}>
|
||||||
{showCloseBtn ? donationCloseBtn : ''}
|
{closeBtn ? donationCloseBtn : ''}
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable react/sort-prop-types */
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
@ -18,7 +19,7 @@ import { postChargeStripe } from '../../../utils/ajax';
|
|||||||
import { userSelector } from '../../../redux';
|
import { userSelector } from '../../../redux';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
changeCloseBtnLabel: PropTypes.func,
|
showCloseBtn: PropTypes.func,
|
||||||
defaultTheme: PropTypes.string,
|
defaultTheme: PropTypes.string,
|
||||||
donationAmount: PropTypes.number.isRequired,
|
donationAmount: PropTypes.number.isRequired,
|
||||||
donationDuration: PropTypes.string.isRequired,
|
donationDuration: PropTypes.string.isRequired,
|
||||||
@ -127,8 +128,11 @@ class DonateFormChildViewForHOC extends Component {
|
|||||||
// scroll to top
|
// scroll to top
|
||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
|
|
||||||
// change the donation modal button to close
|
// change the donation modal button label to close
|
||||||
this.props.changeCloseBtnLabel();
|
// or display the close button for the cert donation section
|
||||||
|
if (this.props.showCloseBtn) {
|
||||||
|
this.props.showCloseBtn();
|
||||||
|
}
|
||||||
|
|
||||||
return postChargeStripe({
|
return postChargeStripe({
|
||||||
token,
|
token,
|
||||||
|
@ -50,8 +50,8 @@ const propTypes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function DonateModal({ show, block, isBlockDonation, closeDonationModal }) {
|
function DonateModal({ show, block, isBlockDonation, closeDonationModal }) {
|
||||||
const [showCloseLabel, setCloseLabel] = React.useState(false);
|
const [closeLabel, setCloseLabel] = React.useState(false);
|
||||||
const changeCloseBtnLabel = () => {
|
const showCloseBtn = () => {
|
||||||
setCloseLabel(true);
|
setCloseLabel(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ function DonateModal({ show, block, isBlockDonation, closeDonationModal }) {
|
|||||||
<Modal.Body>
|
<Modal.Body>
|
||||||
{isBlockDonation ? blockDonationText : progressDonationText}
|
{isBlockDonation ? blockDonationText : progressDonationText}
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<MinimalDonateForm changeCloseBtnLabel={changeCloseBtnLabel} />
|
<MinimalDonateForm showCloseBtn={showCloseBtn} />
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<Row>
|
<Row>
|
||||||
<Col sm={10} smOffset={1} xs={12}>
|
<Col sm={10} smOffset={1} xs={12}>
|
||||||
@ -108,7 +108,7 @@ function DonateModal({ show, block, isBlockDonation, closeDonationModal }) {
|
|||||||
className='btn-link'
|
className='btn-link'
|
||||||
onClick={closeDonationModal}
|
onClick={closeDonationModal}
|
||||||
>
|
>
|
||||||
{showCloseLabel ? 'close' : 'Please ask me later.'}
|
{closeLabel ? 'Close.' : 'Please ask me later.'}
|
||||||
</Button>
|
</Button>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
/* eslint-disable react/sort-prop-types */
|
||||||
|
/* eslint-disable react/jsx-sort-props */
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import { Button, Row, Col } from '@freecodecamp/react-bootstrap';
|
import { Row, Col } from '@freecodecamp/react-bootstrap';
|
||||||
import { StripeProvider, Elements } from 'react-stripe-elements';
|
import { StripeProvider, Elements } from 'react-stripe-elements';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -10,14 +12,8 @@ import {
|
|||||||
durationsConfig,
|
durationsConfig,
|
||||||
defaultStateConfig
|
defaultStateConfig
|
||||||
} from '../../../../../config/donation-settings';
|
} from '../../../../../config/donation-settings';
|
||||||
import { apiLocation } from '../../../../config/env.json';
|
|
||||||
import DonateFormChildViewForHOC from './DonateFormChildViewForHOC';
|
import DonateFormChildViewForHOC from './DonateFormChildViewForHOC';
|
||||||
import {
|
import { userSelector } from '../../../redux';
|
||||||
userSelector,
|
|
||||||
isSignedInSelector,
|
|
||||||
signInLoadingSelector,
|
|
||||||
hardGoTo as navigate
|
|
||||||
} from '../../../redux';
|
|
||||||
|
|
||||||
import '../Donation.css';
|
import '../Donation.css';
|
||||||
import DonateCompletion from './DonateCompletion.js';
|
import DonateCompletion from './DonateCompletion.js';
|
||||||
@ -28,12 +24,9 @@ const numToCommas = num =>
|
|||||||
num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
|
num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
changeCloseBtnLabel: PropTypes.func,
|
showCloseBtn: PropTypes.func,
|
||||||
defaultTheme: PropTypes.string,
|
defaultTheme: PropTypes.string,
|
||||||
isDonating: PropTypes.bool,
|
isDonating: PropTypes.bool,
|
||||||
isSignedIn: PropTypes.bool,
|
|
||||||
navigate: PropTypes.func.isRequired,
|
|
||||||
showLoading: PropTypes.bool.isRequired,
|
|
||||||
stripe: PropTypes.shape({
|
stripe: PropTypes.shape({
|
||||||
createToken: PropTypes.func.isRequired
|
createToken: PropTypes.func.isRequired
|
||||||
})
|
})
|
||||||
@ -41,24 +34,11 @@ const propTypes = {
|
|||||||
|
|
||||||
const mapStateToProps = createSelector(
|
const mapStateToProps = createSelector(
|
||||||
userSelector,
|
userSelector,
|
||||||
signInLoadingSelector,
|
({ isDonating }) => ({
|
||||||
isSignedInSelector,
|
isDonating
|
||||||
({ isDonating }, showLoading, isSignedIn) => ({
|
|
||||||
isDonating,
|
|
||||||
isSignedIn,
|
|
||||||
showLoading
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const mapDispatchToProps = {
|
|
||||||
navigate
|
|
||||||
};
|
|
||||||
|
|
||||||
const createOnClick = navigate => e => {
|
|
||||||
e.preventDefault();
|
|
||||||
return navigate(`${apiLocation}/signin?returnTo=donate`);
|
|
||||||
};
|
|
||||||
|
|
||||||
class ModalDonateForm extends Component {
|
class ModalDonateForm extends Component {
|
||||||
constructor(...args) {
|
constructor(...args) {
|
||||||
super(...args);
|
super(...args);
|
||||||
@ -138,14 +118,14 @@ class ModalDonateForm extends Component {
|
|||||||
stripe
|
stripe
|
||||||
} = this.state;
|
} = this.state;
|
||||||
|
|
||||||
const { changeCloseBtnLabel, defaultTheme } = this.props;
|
const { showCloseBtn, defaultTheme } = this.props;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{paymentType === 'Card' ? (
|
{paymentType === 'Card' ? (
|
||||||
<StripeProvider stripe={stripe}>
|
<StripeProvider stripe={stripe}>
|
||||||
<Elements>
|
<Elements>
|
||||||
<DonateFormChildViewForHOC
|
<DonateFormChildViewForHOC
|
||||||
changeCloseBtnLabel={changeCloseBtnLabel}
|
showCloseBtn={showCloseBtn}
|
||||||
defaultTheme={defaultTheme}
|
defaultTheme={defaultTheme}
|
||||||
donationAmount={donationAmount}
|
donationAmount={donationAmount}
|
||||||
donationDuration={donationDuration}
|
donationDuration={donationDuration}
|
||||||
@ -164,7 +144,7 @@ class ModalDonateForm extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { isSignedIn, navigate, showLoading, isDonating } = this.props;
|
const { isDonating } = this.props;
|
||||||
|
|
||||||
if (isDonating) {
|
if (isDonating) {
|
||||||
return (
|
return (
|
||||||
@ -179,17 +159,7 @@ class ModalDonateForm extends Component {
|
|||||||
return (
|
return (
|
||||||
<Row>
|
<Row>
|
||||||
<Col sm={10} smOffset={1} xs={12}>
|
<Col sm={10} smOffset={1} xs={12}>
|
||||||
{!showLoading && !isSignedIn ? (
|
{this.renderDonationOptions()}
|
||||||
<Button
|
|
||||||
bsStyle='default'
|
|
||||||
className='btn btn-block'
|
|
||||||
onClick={createOnClick(navigate)}
|
|
||||||
>
|
|
||||||
Become a supporter
|
|
||||||
</Button>
|
|
||||||
) : (
|
|
||||||
this.renderDonationOptions()
|
|
||||||
)}
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
);
|
);
|
||||||
@ -201,5 +171,5 @@ ModalDonateForm.propTypes = propTypes;
|
|||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
mapStateToProps,
|
mapStateToProps,
|
||||||
mapDispatchToProps
|
null
|
||||||
)(ModalDonateForm);
|
)(ModalDonateForm);
|
||||||
|
Reference in New Issue
Block a user