-
Notifications
You must be signed in to change notification settings - Fork 2
/
UserLogin.js
122 lines (106 loc) · 2.77 KB
/
UserLogin.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
import React from 'react'
import PropTypes from 'prop-types'
import withRouter from 'found/lib/withRouter'
import { routerShape } from 'found/lib/PropTypes'
import { createFragmentContainer, graphql } from 'react-relay'
import Formsy from 'formsy-react'
import Wrapper from './Wrapper'
import Bold from './Bold'
import Hint from './Hint'
import FormWraper from './FormWrapper'
import TextInput from '../../components/Input/FormsyText'
import Button from '../../components/Button'
import {
login as loginUser,
loginWithFacebookRoute,
} from '../../auth'
import { ERRORS } from '../../../config'
class LoginPage extends React.Component {
static propTypes = {
router: routerShape.isRequired,
viewer: PropTypes.shape({
isLoggedIn: PropTypes.bool,
}).isRequired,
}
setFormElement = (element) => {
this.formElement = element
}
login = ({ email, password }) => {
loginUser({ email, password })
.then((error) => {
if (error) {
console.error(ERRORS[error.name])
} else {
this.props.router.go(-1)
}
})
}
render() {
const { viewer, router } = this.props
if (viewer.isLoggedIn) {
this.props.router.push('/')
return <div />
}
const submitMargin = { marginTop: 20 }
return (
<Wrapper>
<h2>Login</h2>
<Hint>
You can use <Bold>reader@test.com</Bold>, <Bold>publisher@test.com</Bold>,
<Bold> publisher2@test.com</Bold> with password <Bold>qwerty</Bold>.
</Hint>
<FormWraper>
<Button
label="Login with facebook"
style={submitMargin}
href={loginWithFacebookRoute}
external
fullWidth
secondary
/>
<Formsy.Form
ref={this.setFormElement}
onSubmit={this.login}
>
<TextInput
name="email"
label="E-Mail"
validations="isEmail"
validationError="Please enter a valid email address"
fullWidth
/>
<TextInput
type="password"
name="password"
label="Passwort"
fullWidth
/>
<Button
type="submit"
label="Login"
style={submitMargin}
fullWidth
secondary
/>
</Formsy.Form>
<Button
label="Register"
style={submitMargin}
to="/register"
fullWidth
primary
/>
</FormWraper>
</Wrapper>
)
}
}
export default createFragmentContainer(
withRouter(LoginPage),
graphql`
fragment UserLogin_viewer on Viewer {
isLoggedIn
canPublish
}
`,
)