Created
October 21, 2016 20:51
-
-
Save bnhansn/6958eb3017217294c85ac52893c3d064 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'; | |
| type Props = { | |
| handleSubmit: () => void, | |
| onSubmit: () => void, | |
| submitting: boolean, | |
| } | |
| class NewRoomForm extends Component { | |
| props: Props | |
| handleSubmit = data => this.props.onSubmit(data); | |
| render() { | |
| const { handleSubmit, submitting } = this.props; | |
| return ( | |
| <form onSubmit={handleSubmit(this.handleSubmit)}> | |
| <div className="input-group"> | |
| <Field | |
| name="name" | |
| type="text" | |
| placeholder="Name" | |
| component="input" | |
| className="form-control" | |
| /> | |
| <div className="input-group-btn"> | |
| <button type="submit" className="btn btn-primary" disabled={submitting}> | |
| {submitting ? 'Saving...' : 'Submit'} | |
| </button> | |
| </div> | |
| </div> | |
| </form> | |
| ); | |
| } | |
| } | |
| const validate = (values) => { | |
| const errors = {}; | |
| if (!values.name) { | |
| errors.name = 'Required'; | |
| } | |
| return errors; | |
| }; | |
| export default reduxForm({ | |
| form: 'newRoom', | |
| validate, | |
| })(NewRoomForm); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment