Created
October 21, 2016 13:44
-
-
Save bnhansn/4173e6240864897fe8617c87b5941507 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
| // @flow | |
| import React, { Component } from 'react'; | |
| import { Field, reduxForm } from 'redux-form'; | |
| import { Link } from 'react-router'; | |
| import { css, StyleSheet } from 'aphrodite'; | |
| import Input from '../Input'; | |
| const styles = StyleSheet.create({ | |
| card: { | |
| maxWidth: '500px', | |
| padding: '3rem 4rem', | |
| margin: '2rem auto', | |
| }, | |
| }); | |
| type Props = { | |
| onSubmit: () => void, | |
| handleSubmit: () => void, | |
| submitting: boolean, | |
| } | |
| class LoginForm extends Component { | |
| props: Props | |
| handleSubmit = data => this.props.onSubmit(data); | |
| render() { | |
| const { handleSubmit, submitting } = this.props; | |
| return ( | |
| <form | |
| className={`card ${css(styles.card)}`} | |
| onSubmit={handleSubmit(this.handleSubmit)} | |
| > | |
| <h3 style={{ marginBottom: '2rem', textAlign: 'center' }}>Login to Sling</h3> | |
| <Field name="email" type="text" component={Input} placeholder="Email" /> | |
| <Field name="password" type="password" component={Input} placeholder="Password" /> | |
| <button | |
| type="submit" | |
| disabled={submitting} | |
| className="btn btn-block btn-primary" | |
| > | |
| {submitting ? 'Logging in...' : 'Login'} | |
| </button> | |
| <hr style={{ margin: '2rem 0' }} /> | |
| <Link to="/signup" className="btn btn-block btn-secondary"> | |
| Create a new account | |
| </Link> | |
| </form> | |
| ); | |
| } | |
| } | |
| const validate = (values) => { | |
| const errors = {}; | |
| if (!values.email) { | |
| errors.email = 'Required'; | |
| } | |
| if (!values.password) { | |
| errors.password = 'Required'; | |
| } | |
| return errors; | |
| }; | |
| export default reduxForm({ | |
| form: 'login', | |
| validate, | |
| })(LoginForm); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment