-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcreate-user.js
More file actions
40 lines (32 loc) · 1.13 KB
/
create-user.js
File metadata and controls
40 lines (32 loc) · 1.13 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
import React, { Component } from 'react'
import { reduxForm, Field } from 'redux-form'
import ErrorField from '../common/error-field'
import { validate as validateEmail } from 'email-validator'
class NewUserForm extends Component {
render() {
return (
<div>
<h3>Create User Form</h3>
<form onSubmit={this.props.handleSubmit}>
<Field label="First Name" name="firstName" component={ErrorField} />
<Field label="Last Name" name="lastName" component={ErrorField} />
<Field label="Email" name="email" component={ErrorField} />
<button type="submit">Submit</button>
<button onClick={this.props.reset}>Reset</button>
</form>
</div>
)
}
}
const validate = ({ firstName, lastName, email }) => {
const errors = {}
if (!firstName) errors.firstName = 'first name is a required field'
if (!lastName) errors.lastName = 'last name is a required field'
if (!email) errors.email = 'email is a required field'
else if (!validateEmail(email)) errors.email = 'email is invalid'
return errors
}
export default reduxForm({
form: 'user',
validate
})(NewUserForm)