fix(donate): refactor to add completion in form
This commit is contained in:
committed by
Stuart Taylor
parent
d816bc4acf
commit
e84f021d8b
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
.donation-elements {
|
.donation-elements {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: column;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,21 +70,6 @@
|
|||||||
padding-top: 8px;
|
padding-top: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.donate-card-element {
|
|
||||||
min-width: 280px;
|
|
||||||
flex: 1 1 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.donate-expiry-element {
|
|
||||||
min-width: 120px;
|
|
||||||
flex: 0 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.donate-cvc-element {
|
|
||||||
min-width: 80px;
|
|
||||||
flex: 0 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.StripeElement--focus {
|
.StripeElement--focus {
|
||||||
border-color: #66afe9;
|
border-color: #66afe9;
|
||||||
outline: 0;
|
outline: 0;
|
||||||
|
@ -4,14 +4,13 @@ import { Alert, Button } from '@freecodecamp/react-bootstrap';
|
|||||||
import Spinner from 'react-spinkit';
|
import Spinner from 'react-spinkit';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
close: PropTypes.func.isRequired,
|
|
||||||
error: PropTypes.string,
|
error: PropTypes.string,
|
||||||
processing: PropTypes.bool,
|
processing: PropTypes.bool,
|
||||||
reset: PropTypes.func.isRequired,
|
reset: PropTypes.func.isRequired,
|
||||||
success: PropTypes.bool
|
success: PropTypes.bool
|
||||||
};
|
};
|
||||||
|
|
||||||
function DonateCompletion({ close, processing, reset, success, error = null }) {
|
function DonateCompletion({ processing, reset, success, error = null }) {
|
||||||
/* eslint-disable no-nested-ternary */
|
/* eslint-disable no-nested-ternary */
|
||||||
const style = processing ? 'info' : success ? 'success' : 'danger';
|
const style = processing ? 'info' : success ? 'success' : 'danger';
|
||||||
const heading = processing
|
const heading = processing
|
||||||
@ -43,7 +42,6 @@ function DonateCompletion({ close, processing, reset, success, error = null }) {
|
|||||||
<span />
|
<span />
|
||||||
</Fragment>
|
</Fragment>
|
||||||
)}
|
)}
|
||||||
{!processing && <Button onClick={close}>Close</Button>}
|
|
||||||
</p>
|
</p>
|
||||||
</Alert>
|
</Alert>
|
||||||
);
|
);
|
||||||
|
@ -12,12 +12,12 @@ import { injectStripe } from 'react-stripe-elements';
|
|||||||
|
|
||||||
import Spacer from '../../../components/helpers/Spacer';
|
import Spacer from '../../../components/helpers/Spacer';
|
||||||
import StripeCardForm from './StripeCardForm';
|
import StripeCardForm from './StripeCardForm';
|
||||||
|
import DonateCompletion from './DonateCompletion';
|
||||||
import { postJSON$ } from '../../../templates/Challenges/utils/ajax-stream.js';
|
import { postJSON$ } from '../../../templates/Challenges/utils/ajax-stream.js';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
email: PropTypes.string,
|
email: PropTypes.string,
|
||||||
maybeButton: PropTypes.func.isRequired,
|
maybeButton: PropTypes.func.isRequired,
|
||||||
renderCompletion: PropTypes.func.isRequired,
|
|
||||||
stripe: PropTypes.shape({
|
stripe: PropTypes.shape({
|
||||||
createToken: PropTypes.func.isRequired
|
createToken: PropTypes.func.isRequired
|
||||||
})
|
})
|
||||||
@ -147,6 +147,12 @@ class DonateForm extends Component {
|
|||||||
return this.setState(() => initialSate);
|
return this.setState(() => initialSate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderCompletion(props) {
|
||||||
|
return (
|
||||||
|
<DonateCompletion {...props}/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
renderDonateForm() {
|
renderDonateForm() {
|
||||||
const { isFormValid } = this.state;
|
const { isFormValid } = this.state;
|
||||||
return (
|
return (
|
||||||
@ -186,9 +192,8 @@ class DonateForm extends Component {
|
|||||||
const {
|
const {
|
||||||
donationState: { processing, success, error }
|
donationState: { processing, success, error }
|
||||||
} = this.state;
|
} = this.state;
|
||||||
const { renderCompletion } = this.props;
|
|
||||||
if (processing || success || error) {
|
if (processing || success || error) {
|
||||||
return renderCompletion({
|
return this.renderCompletion({
|
||||||
processing,
|
processing,
|
||||||
success,
|
success,
|
||||||
error,
|
error,
|
||||||
|
@ -10,7 +10,6 @@ import { stripePublicKey } from '../../../../config/env.json';
|
|||||||
|
|
||||||
import ga from '../../../analytics';
|
import ga from '../../../analytics';
|
||||||
import DonateForm from './DonateForm';
|
import DonateForm from './DonateForm';
|
||||||
import DonateCompletion from './DonateCompletion';
|
|
||||||
import {
|
import {
|
||||||
userSelector,
|
userSelector,
|
||||||
closeDonationModal,
|
closeDonationModal,
|
||||||
@ -48,7 +47,6 @@ class DonateModal extends Component {
|
|||||||
this.state = {
|
this.state = {
|
||||||
stripe: null
|
stripe: null
|
||||||
};
|
};
|
||||||
this.renderCompletion = this.renderCompletion.bind(this);
|
|
||||||
this.renderMaybe = this.renderMaybe.bind(this);
|
this.renderMaybe = this.renderMaybe.bind(this);
|
||||||
}
|
}
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -70,12 +68,6 @@ class DonateModal extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderCompletion(props) {
|
|
||||||
return (
|
|
||||||
<DonateCompletion close={this.props.closeDonationModal} {...props} />
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderMaybe() {
|
renderMaybe() {
|
||||||
const { closeDonationModal } = this.props;
|
const { closeDonationModal } = this.props;
|
||||||
const handleClick = e => {
|
const handleClick = e => {
|
||||||
@ -109,7 +101,6 @@ class DonateModal extends Component {
|
|||||||
<DonateForm
|
<DonateForm
|
||||||
email={email}
|
email={email}
|
||||||
maybeButton={this.renderMaybe}
|
maybeButton={this.renderMaybe}
|
||||||
renderCompletion={this.renderCompletion}
|
|
||||||
/>
|
/>
|
||||||
</Modal.Body>
|
</Modal.Body>
|
||||||
<Modal.Footer>
|
<Modal.Footer>
|
||||||
|
@ -77,25 +77,31 @@ class StripeCardForm extends Component {
|
|||||||
return (
|
return (
|
||||||
<div className='donation-elements'>
|
<div className='donation-elements'>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
<ControlLabel>Card Number:</ControlLabel>
|
<ControlLabel>
|
||||||
|
Your Card Number:
|
||||||
|
</ControlLabel>
|
||||||
<CardNumberElement
|
<CardNumberElement
|
||||||
className='form-control donate-input-element donate-card-element'
|
className='form-control donate-input-element'
|
||||||
onChange={this.handleInputChange}
|
onChange={this.handleInputChange}
|
||||||
style={style}
|
style={style}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
<ControlLabel>Expiry:</ControlLabel>
|
<ControlLabel>
|
||||||
|
Your Card Expiration Month:
|
||||||
|
</ControlLabel>
|
||||||
<CardExpiryElement
|
<CardExpiryElement
|
||||||
className='form-control donate-input-element donate-expiry-element'
|
className='form-control donate-input-element'
|
||||||
onChange={this.handleInputChange}
|
onChange={this.handleInputChange}
|
||||||
style={style}
|
style={style}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
<ControlLabel>CVC:</ControlLabel>
|
<ControlLabel>
|
||||||
|
Your Card CVC (3-digit security number):
|
||||||
|
</ControlLabel>
|
||||||
<CardCVCElement
|
<CardCVCElement
|
||||||
className='form-control donate-input-element donate-cvc-element'
|
className='form-control donate-input-element'
|
||||||
onChange={this.handleInputChange}
|
onChange={this.handleInputChange}
|
||||||
style={style}
|
style={style}
|
||||||
/>
|
/>
|
||||||
|
@ -12,7 +12,6 @@ import { userSelector } from '../redux';
|
|||||||
|
|
||||||
import Spacer from '../components/helpers/Spacer';
|
import Spacer from '../components/helpers/Spacer';
|
||||||
import DonateForm from '../components/Donation/components/DonateForm';
|
import DonateForm from '../components/Donation/components/DonateForm';
|
||||||
import DonateCompletion from '../components/Donation/components/DonateCompletion';
|
|
||||||
import DonateText from '../components/Donation/components/DonateText';
|
import DonateText from '../components/Donation/components/DonateText';
|
||||||
import PoweredByStripe from '../components/Donation/components/poweredByStripe';
|
import PoweredByStripe from '../components/Donation/components/poweredByStripe';
|
||||||
|
|
||||||
@ -66,10 +65,6 @@ class IndexPage extends Component {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
renderCompletion(props) {
|
|
||||||
return <DonateCompletion close={() => {}} {...props} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { email = '' } = this.props;
|
const { email = '' } = this.props;
|
||||||
return (
|
return (
|
||||||
@ -90,7 +85,6 @@ class IndexPage extends Component {
|
|||||||
<DonateForm
|
<DonateForm
|
||||||
email={email}
|
email={email}
|
||||||
maybeButton={() => null}
|
maybeButton={() => null}
|
||||||
renderCompletion={this.renderCompletion}
|
|
||||||
/>
|
/>
|
||||||
</Elements>
|
</Elements>
|
||||||
</StripeProvider>
|
</StripeProvider>
|
||||||
|
@ -251,14 +251,14 @@ export const reducer = handleActions(
|
|||||||
...state,
|
...state,
|
||||||
isOnline
|
isOnline
|
||||||
}),
|
}),
|
||||||
[types.openDonationModal]: state => ({
|
|
||||||
...state,
|
|
||||||
showDonationModal: true
|
|
||||||
}),
|
|
||||||
[types.closeDonationModal]: state => ({
|
[types.closeDonationModal]: state => ({
|
||||||
...state,
|
...state,
|
||||||
showDonationModal: false
|
showDonationModal: false
|
||||||
}),
|
}),
|
||||||
|
[types.openDonationModal]: state => ({
|
||||||
|
...state,
|
||||||
|
showDonationModal: true
|
||||||
|
}),
|
||||||
[types.showCert]: state => ({
|
[types.showCert]: state => ({
|
||||||
...state,
|
...state,
|
||||||
showCert: {},
|
showCert: {},
|
||||||
|
Reference in New Issue
Block a user