fix(donate): refactor form handler

This commit is contained in:
Mrugesh Mohapatra
2019-02-14 19:25:25 +05:30
committed by Stuart Taylor
parent 82219916bf
commit bed432b93b

View File

@ -56,7 +56,6 @@ class DonateForm extends Component {
this.handleSubmit = this.handleSubmit.bind(this); this.handleSubmit = this.handleSubmit.bind(this);
this.postDonation = this.postDonation.bind(this); this.postDonation = this.postDonation.bind(this);
this.resetDonation = this.resetDonation.bind(this); this.resetDonation = this.resetDonation.bind(this);
this.submit = this.submit.bind(this);
} }
getUserEmail() { getUserEmail() {
@ -80,7 +79,8 @@ class DonateForm extends Component {
})); }));
} }
handleSubmit() { handleSubmit(e) {
e.preventDefault();
const email = this.getUserEmail(); const email = this.getUserEmail();
if (!email || !isEmail(email)) { if (!email || !isEmail(email)) {
return this.setState(state => ({ return this.setState(state => ({
@ -150,11 +150,6 @@ class DonateForm extends Component {
); );
} }
submit(e) {
e.preventDefault();
this.handleSubmit();
}
resetDonation() { resetDonation() {
return this.setState({...initialState}); return this.setState({...initialState});
} }
@ -167,7 +162,7 @@ class DonateForm extends Component {
const { isFormValid } = this.state; const { isFormValid } = this.state;
return ( return (
<div> <div>
<Form className='donation-form' onSubmit={this.submit}> <Form className='donation-form' onSubmit={this.handleSubmit}>
<FormGroup className='donation-email-container'> <FormGroup className='donation-email-container'>
<ControlLabel> <ControlLabel>
Email (we'll send you a tax-deductible donation receipt): Email (we'll send you a tax-deductible donation receipt):