-
Notifications
You must be signed in to change notification settings - Fork 50
/
Login.js
169 lines (154 loc) · 3.81 KB
/
Login.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import styles from '@/styles/Login.scss';
import '@/styles/Fn.scss';
import React from 'react';
import PropTypes from 'prop-types';
import CSSModules from 'react-css-modules';
import Modal from 'react-modal';
import classNames from 'classnames';
import Button from 'react-mdl/lib/Button';
import Textfield from 'react-mdl/lib/Textfield';
import Icon from 'react-mdl/lib/Icon';
import { FormattedMessage, injectIntl } from 'react-intl';
import moment from '@/utils/moment';
import Storage from '@/utils/Storage';
import withRef from '@/utils/withRef';
class Login extends React.Component {
static propTypes = {
onLogoutClick: PropTypes.func,
onLogoutClick: PropTypes.func,
isSubmitting: PropTypes.bool,
authData: PropTypes.object
};
constructor(props) {
super(props);
this.state = {
isHidden: true,
isClosing: false,
username: '',
password: ''
};
Modal.setAppElement('#app');
}
componentDidMount() {
const authData = Storage.get('auth');
this.setState({
authData
});
}
@autobind
open() {
this.setState({
isHidden: false
});
}
@autobind
close() {
this.setState({
isHidden: true
});
}
@autobind
setUsername(username) {
this.setState({
username
});
}
@autobind
getUsername() {
return this.state.username;
}
@autobind
setPassword(password) {
this.setState({
password
});
}
@autobind
getPassword() {
return this.state.password;
}
renderContent() {
if (
this.props.authData !== null &&
this.props.authData.expires_at > moment().unix()
) {
return (
<div>
<div styleName="avatar">
<span styleName="name">
<FormattedMessage id="Nickname" /> 「{
this.props.authData.user.name
}」
</span>
</div>
<div styleName="footer">
<Button onClick={this.props.onLogoutClick} raised accent ripple>
<FormattedMessage id="Logout" />
</Button>
</div>
</div>
);
}
return (
<div>
<Textfield
onChange={event => this.setUsername(event.target.value)}
value={this.getUsername()}
label={this.props.intl.formatMessage({
id: 'Email Address / pixiv ID'
})}
spellCheck={false}
floatingLabel
style={{ width: '100%' }}
/>
<Textfield
type="password"
onChange={event => this.setPassword(event.target.value)}
value={this.getPassword()}
label={this.props.intl.formatMessage({
id: 'Password'
})}
floatingLabel
style={{ width: '100%' }}
/>
<div styleName="footer">
<Button
className={classNames({
'fn-disallow': this.props.isSubmitting
})}
onClick={this.props.onLoginClick}
disabled={this.props.isSubmitting}
raised
accent
ripple>
<FormattedMessage
id={this.props.isSubmitting ? 'Wait a Moment' : 'Login'}
/>
</Button>
</div>
</div>
);
}
render() {
return (
<Modal
styleName="login-modal-body"
overlayClassName={styles['login-modal-overlay']}
isOpen={!this.state.isHidden}
onRequestClose={this.close}
contentLabel="login-modal">
<div styleName="clear" onClick={this.close}>
<Icon name="clear" />
</div>
<div styleName="form">
<div styleName="fields">{this.renderContent()}</div>
</div>
</Modal>
);
}
}
export default withRef(
// eslint-disable-next-line babel/new-cap
CSSModules(Login, styles, { allowMultiple: true }),
injectIntl
);