-
Notifications
You must be signed in to change notification settings - Fork 1
/
TeamMemberAdd.jsx
70 lines (59 loc) · 1.43 KB
/
TeamMemberAdd.jsx
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict';
const React = require('react');
const TeamMemberAdd = React.createClass({
propTypes: {
onAdd: React.PropTypes.func.isRequired
},
getInitialState () {
return {
fields: {
name: '',
email: ''
},
isFormValid: false
};
},
handleChange (event) {
const fields = Object.assign({}, this.state.fields, {
[event.target.name]: event.target.value
});
this.setState({
fields,
isFormValid: fields.name && fields.email
});
},
handleSubmit (event) {
event.preventDefault();
if (!this.state.isFormValid) {
return;
}
this.props.onAdd({
name: this.state.fields.name,
email: this.state.fields.email
});
this.setState({
fields: {
name: '',
email: ''
}
});
},
render () {
return (
<form onSubmit={this.handleSubmit}>
<div>
<label htmlFor='name'>Name:</label>
<input type='text' name='name' id='name' value={this.state.fields.name} onChange={this.handleChange} />
</div>
<div>
<label htmlFor='email'>E-Mail:</label>
<input type='text' name='email' id='email' value={this.state.fields.email} onChange={this.handleChange} />
</div>
<div>
<button disabled={!this.state.isFormValid} type='submit'>Join team</button>
</div>
</form>
);
}
});
module.exports = TeamMemberAdd;