forked from strapi/strapi-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
190 lines (169 loc) · 5.51 KB
/
index.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/**
*
* AuthPage
*
*/
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { createStructuredSelector } from 'reselect';
import { bindActionCreators, compose } from 'redux';
import { get, map, replace } from 'lodash';
import { Link } from 'react-router-dom';
import Button from 'components/Button';
import FormDivider from 'components/FormDivider';
import Input from 'components/Input';
import Logo from 'images/logo_strapi.png';
import SocialLink from 'components/SocialLink';
// Utils
import injectSaga from 'utils/injectSaga';
import injectReducer from 'utils/injectReducer';
import { onChange, setForm, submit } from './actions';
import form from './form.json';
import makeSelectAuthPage from './selectors';
import reducer from './reducer';
import saga from './saga';
import './styles.scss';
export class AuthPage extends React.Component { // eslint-disable-line react/prefer-stateless-function
componentDidMount() {
this.setForm(this.props);
}
componentWillUpdate(nextProps) {
// Update the form depending on the URL's params
if (nextProps.match.params.authType !== this.props.match.params.authType) {
this.setForm(nextProps);
}
}
/**
* Create the form depending on the URL
* @param {Object} props
*/
setForm = (props) => {
const params = props.location.search ? replace(props.location.search, '?code=', '') : props.match.params.id;
this.props.setForm(props.match.params.authType, params);
}
/**
* Check the URL's params to render the appropriate links
* @return {Element} Returns navigation links
*/
renderLink = () => {
if (this.props.match.params.authType === 'login') {
return (
<div>
<Link to="/auth/forgot-password">
Forgot Password
</Link>
or
<Link to="/auth/register">
register
</Link>
</div>
);
}
return (
<div>
<Link to="/auth/login">
Ready to signin
</Link>
</div>
);
}
render() {
const divStyle = this.props.match.params.authType === 'register' ? { marginTop: '3.2rem' } : { marginTop: '.9rem' };
const inputs = get(form, this.props.match.params.authType) || [];
const providers = ['discord', 'facebook', 'github', 'google', 'microsoft', 'twitch', 'twitter']; // To remove a provider from the list just delete it from this array...
return (
<div className="authPage">
<div className="wrapper">
<div className="headerContainer">
{this.props.match.params.authType === 'register' ? (
<span>Welcome !</span>
) : (
<img src={Logo} alt="logo" />
)}
</div>
<div className="headerDescription">
{this.props.match.params.authType === 'register' ? (
<span>
Please register to access the app.
</span>
) : ''}
</div>
<div className="formContainer" style={divStyle}>
<div className="container-fluid">
<div className="row">
<div className="col-md-12">
{providers.map(provider => <SocialLink provider={provider} key={provider} />)}
</div>
</div>
<FormDivider />
<form onSubmit={(e) => {
e.preventDefault();
this.props.submit();
}}
>
<div className="row" style={{ textAlign: 'start' }}>
{map(inputs, (input, key) => (
<Input
autoFocus={key === 0}
customBootstrapClass={get(input, 'customBootstrapClass')}
didCheckErrors={false}
errors={[]}
key={get(input, 'name')}
label={get(input, 'label')}
name={get(input, 'name')}
onChange={this.props.onChange}
placeholder={get(input, 'placeholder')}
type={get(input, 'type')}
validations={{ required: true }}
value={get(this.props.modifiedData, get(input, 'name'))}
/>
))}
<div className="col-md-12 buttonContainer">
<Button
label="Submit"
style={{ width: '100%' }}
primary
type="submit"
/>
</div>
</div>
</form>
</div>
</div>
<div className="linkContainer">
{this.renderLink()}
</div>
</div>
</div>
);
}
}
AuthPage.propTypes = {
formType: PropTypes.string.isRequired,
history: PropTypes.object.isRequired,
location: PropTypes.object.isRequired,
match: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired,
setForm: PropTypes.func.isRequired,
submit: PropTypes.func.isRequired,
};
const mapStateToProps = makeSelectAuthPage();
function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
onChange,
setForm,
submit,
},
dispatch
);
}
const withConnect = connect(mapStateToProps, mapDispatchToProps);
const withReducer = injectReducer({ key: 'authPage', reducer });
const withSaga = injectSaga({ key: 'authPage', saga });
export default compose(
withReducer,
withSaga,
withConnect,
)(AuthPage);