-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathUserForm.js
More file actions
46 lines (38 loc) · 1.05 KB
/
UserForm.js
File metadata and controls
46 lines (38 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React, { Component } from 'react'
import {reduxForm, Field} from 'redux-form'
import validator from 'email-validator'
import ErrorField from '../common/ErrorField'
class UserForm extends Component {
static propTypes = {
};
render() {
const {mode} = this.props;
return (
<div>
<h3>{mode === 'add' ? 'Add user' : 'Edit User' }</h3>
<form onSubmit={this.props.handleSubmit}>
<div>
First name: <Field name='firstName' component='input'/>
</div>
<div>
Last name: <Field name='lastName' component='input'/>
</div>
<div>
email: <Field component={ErrorField} name='email'/>
</div>
<input type='submit' />
</form>
</div>
)
}
}
const validate = ({ email }) => {
const errors = {}
if (!email) errors.email = 'email is a required field'
if (email && !validator.validate(email)) errors.email = 'incorrect email format'
return errors
}
export default reduxForm({
form: 'user',
validate
})(UserForm)