/* eslint-disable react/sort-prop-types */ /* eslint-disable react/jsx-sort-props */ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { Row, Col, ControlLabel, FormControl, FormGroup, Button } from '@freecodecamp/react-bootstrap'; import { StripeProvider, Elements } from 'react-stripe-elements'; import { Spacer } from '../helpers'; // eslint-disable-next-line max-len import DonateFormChildViewForHOC from '../Donation/DonateFormChildViewForHOC'; import './YearEndGift.css'; import '../Donation/Donation.css'; import { stripePublicKey } from '../../../../config/env.json'; import { stripeScriptLoader } from '../../utils/scriptLoaders'; const numToCommas = num => num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,'); const propTypes = { showCloseBtn: PropTypes.func, defaultTheme: PropTypes.string, isDonating: PropTypes.bool, stripe: PropTypes.shape({ createToken: PropTypes.func.isRequired }) }; class YearEndDonationForm extends Component { constructor(...args) { super(...args); this.state = { donationAmount: 25000, showOtherAmounts: false, stripe: null }; this.handleStripeLoad = this.handleStripeLoad.bind(this); this.getDonationButtonLabel = this.getDonationButtonLabel.bind(this); this.handleSelectAmount = this.handleSelectAmount.bind(this); this.handleChange = this.handleChange.bind(this); this.handleClick = this.handleClick.bind(this); } componentDidMount() { if (window.Stripe) { this.handleStripeLoad(); } else if (document.querySelector('#stripe-js')) { document .querySelector('#stripe-js') .addEventListener('load', this.handleStripeLoad); } else { stripeScriptLoader(this.handleStripeLoad); } } componentWillUnmount() { const stripeMountPoint = document.querySelector('#stripe-js'); if (stripeMountPoint) { stripeMountPoint.removeEventListener('load', this.handleStripeLoad); } } handleStripeLoad() { // Create Stripe instance once Stripe.js loads if (stripePublicKey) { this.setState(state => ({ ...state, stripe: window.Stripe(stripePublicKey) })); } } getDonationButtonLabel() { const { donationAmount } = this.state; let donationBtnLabel = `Confirm your donation`; donationBtnLabel = `Confirm your one-time donation of $${numToCommas( donationAmount / 100 )}`; return donationBtnLabel; } renderDonationOptions() { const { donationAmount, stripe } = this.state; const { showCloseBtn, defaultTheme } = this.props; return (
); } handleSelectAmount(e) { this.setState({ donationAmount: Number(e.target.value) }); } handleChange(e) { if (isNaN(e.target.value)) return; const amount = Math.floor(e.target.value) * 100; this.setState({ donationAmount: amount }); } renderAmountRadio() { return (
); } renderCustomAmountInput() { return (
Or give a custom amount:
); } renderPayPalDonations() { return (
); } renderForm(item) { return (
{' '} {' '}
); } handleClick() { this.setState({ showOtherAmounts: true, donationAmount: 25000 }); } renderOtherPaymentButton() { return ( <> ); } render() { return ( Thank you again for supporting freeCodeCamp.org with a one-time year-end gift. Please enter your credit card information below. {this.renderAmountRadio()} {this.state.showOtherAmounts ? this.renderCustomAmountInput() : this.renderOtherPaymentButton()} {this.renderDonationOptions()} Or give using PayPal: {this.renderPayPalDonations()} If you need a receipt from your taxes, reply to Quincy's email he sent you. ); } } YearEndDonationForm.displayName = 'YearEndDonationForm'; YearEndDonationForm.propTypes = propTypes; export default YearEndDonationForm;