-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDoerInfo.jsx
53 lines (48 loc) · 1.32 KB
/
DoerInfo.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
import React from 'react';
export default class DoerInfo extends React.Component {
constructor(props) {
super(props);
this.state = {
name: '',
pswd: '',
};
this.handleLogout = this.handleLogout.bind(this);
this.handleLogin = this.handleLogin.bind(this);
}
handleInput(key, e) {
this.setState({ [key]: e.target.value });
}
handleLogout(e) {
e.preventDefault();
this.setState({ name: '', pswd: '' }, this.props.logout);
}
handleLogin() {
const { name, pswd } = this.state;
this.props.login(name, pswd);
}
render() {
const { doer, errMsg } = this.props;
if (doer) {
return (
<div className="doer-info-welcome">
<span>{`Welecome: ${doer.name}`}</span>
<a href="#" onClick={this.handleLogout}>Logout</a>
</div>
);
}
return (
<div className="doer-info-regist">
<label>name: </label><input
type="text"
value={this.state.name}
onChange={(e) => { this.handleInput('name', e); }}
/><label>password: </label><input
type="text"
value={this.state.pswd}
onChange={(e) => { this.handleInput('pswd', e); }}
/><button onClick={this.handleLogin}>Regist/Login</button>
{errMsg && <span>{errMsg}</span>}
</div>
);
}
}