Skip to content

Instantly share code, notes, and snippets.

@bnhansn
Created October 21, 2016 20:51
Show Gist options
  • Save bnhansn/6958eb3017217294c85ac52893c3d064 to your computer and use it in GitHub Desktop.
Save bnhansn/6958eb3017217294c85ac52893c3d064 to your computer and use it in GitHub Desktop.
// @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