Created
November 17, 2016 01:28
-
-
Save iamkevingreen/29073e5d04e3685d98f95b5d3a4cd31a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {PropTypes, Component} from 'react' | |
import Formsy from 'formsy-react' | |
import Input from './Input' | |
class Home extends Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
canSubmit: false | |
} | |
this.handleSubmit = this.handleSubmit.bind(this) | |
this.enableButton = this.enableButton.bind(this) | |
this.disableButton = this.disableButton.bind(this) | |
} | |
enableButton() { | |
this.setState({ | |
canSubmit: true | |
}) | |
} | |
disableButton() { | |
this.setState({ | |
canSubmit: false | |
}) | |
} | |
handleSubmit(data) { | |
fetch('/subscribe', { | |
method: 'POST', | |
body: JSON.stringify(data) | |
}) | |
.then((res) => res.json()) | |
.then((json) => { | |
console.log(json) | |
// Do whatever you would like, display a thank you message, or inform the user if they are already a member | |
}) | |
} | |
render() { | |
return ( | |
<div> | |
<h1>Mailchimp subscribe</h1> | |
<div> | |
<Formsy.Form onValidSubmit={this.handleSubmit} onValid={this.enableButton} onInvalid={this.disableButton}> | |
<Input name="email" validations="isEmail" validationError="Non-valid Email" required label="Email Address" /> | |
<button type="submit" disabled={!this.state.canSubmit} className="btn btn--black">Subscribe</button> | |
</Formsy.Form> | |
</div> | |
</div> | |
); | |
} | |
} | |
export default Home; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment