Skip to content

Commit 2743fb1

Browse files
removed ToS, some ESlint minor refactors
1 parent b8223fe commit 2743fb1

File tree

2 files changed

+96
-91
lines changed

2 files changed

+96
-91
lines changed
Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,89 @@
1-
import React,{Component} from 'react';
1+
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import Axios from 'axios';
44
import '../../css/registration/LogIn.scss';
55

6+
const { REACT_APP_SVR_API } = process.env;
67

7-
class LogIn extends Component{
8+
class LogIn extends Component {
89
constructor(props) {
910
super(props);
1011

1112
this.state = {
1213
email: '',
1314
password: '',
14-
}
15+
};
1516
}
1617

17-
LogInHandler = () =>{
18+
LogInHandler = () => {
1819
const { email, password } = this.state;
1920
const data = {
2021
email,
2122
password,
22-
}
23-
24-
Axios.post('http://localhost:5000/api/user/login',data)
25-
.then(response=>{
23+
};
24+
25+
Axios.post(`${REACT_APP_SVR_API}/user/login`, data)
26+
.then(response => {
2627
localStorage.setItem('app-token', response.data.token);
2728
// this.props.history.push("/dashboard");
2829
this.props.handleLogin();
2930
})
30-
.catch(error=>{
31-
try {
31+
.catch(error => {
32+
try {
3233
// Handles errors that are not HTTP specific
33-
console.log(error)
34+
console.error(error);
3435
this.setState({ showRegistrationFailure: true });
3536
if (!error.status) {
36-
console.log('A network error has occured.')
37+
console.error('A network error has occured.');
3738
} else if (error.response.status === 400) {
38-
console.log('Bad Request');
39+
console.error('Bad Request');
3940
} else if (error.response.status === 500) {
40-
console.log('Something bad happended on the server.');
41+
console.error('Something bad happended on the server.');
4142
} else {
42-
console.log('An unknown error has occurred');
43+
console.error('An unknown error has occurred');
4344
}
4445
} catch (ex) {
4546
Promise.reject(ex);
4647
}
47-
})
48-
}
48+
});
49+
};
4950

50-
render(){
51+
render() {
5152
const { email, password } = this.state;
5253
const { changeToSignup } = this.props;
5354
return (
5455
<div id="login-container">
55-
<h1 id="title" >Login</h1>
56+
<h1 id="title">Login</h1>
5657
<form id="login-form">
5758
<h3>Email</h3>
58-
<input type="email" value={email} onChange={event => this.setState({email:event.target.value})}/>
59+
<input
60+
type="email"
61+
value={email}
62+
onChange={event => this.setState({ email: event.target.value })}
63+
/>
5964
<h3>Password</h3>
60-
<input type="password" value={password} onChange={event => this.setState({password:event.target.value})}/>
61-
<button id="submit-button" type="button" onClick={this.LogInHandler}>Submit</button>
65+
<input
66+
type="password"
67+
value={password}
68+
onChange={event => this.setState({ password: event.target.value })}
69+
/>
70+
<button id="submit-button" type="button" onClick={this.LogInHandler}>
71+
Submit
72+
</button>
6273
</form>
63-
<p>Don't have an account, <button id='signup-button' type="button" onClick={changeToSignup()}>Sign up!</button></p>
74+
<p>
75+
Don't have an account,{' '}
76+
<button id="signup-button" type="button" onClick={changeToSignup()}>
77+
Sign up!
78+
</button>
79+
</p>
6480
</div>
6581
);
6682
}
6783
}
6884

69-
7085
LogIn.propTypes = {
7186
handleLogin: PropTypes.func.isRequired,
7287
};
7388

74-
export default LogIn;
89+
export default LogIn;

src/components/registration/SignUp.js

Lines changed: 56 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
3-
import Axios from 'axios';
3+
import axios from 'axios';
44
import '../../css/registration/SignUp.scss';
55

6+
const { REACT_APP_SVR_API } = process.env;
7+
8+
/**
9+
* @description Validates all inputs to theses constraints
10+
*/
11+
const validate = (email, password, confirmedPassword, fullName, location) => ({
12+
email: email.length === 0,
13+
password: password.length < 8 || password !== confirmedPassword,
14+
fullName: fullName.length === 0,
15+
location: location.length === 0,
16+
});
17+
18+
const WarningBanner = warn_data =>
19+
// eslint-disable-next-line implicit-arrow-linebreak
20+
warn_data.warn ? <div className="warning">{warn_data.message}</div> : null;
21+
622
class SignUp extends Component {
7-
constructor(props){
23+
constructor(props) {
824
super(props);
925

1026
this.state = {
@@ -14,46 +30,48 @@ class SignUp extends Component {
1430
confirmPassword: '',
1531
location: '',
1632
fullName: '',
17-
// Might have to refactored this...
33+
// Might have to refactor this...
1834
touched: {
1935
email: false,
2036
password: false,
2137
},
2238
};
2339
}
24-
40+
2541
/**
2642
* Creates a user with the server
2743
*/
2844
createUserHandler = () => {
2945
const { email, password, location, fullName } = this.state;
46+
const { handleSignup } = this.props;
3047
const data = {
3148
email,
3249
password,
3350
location,
3451
fullName,
3552
};
36-
Axios.post('http://localhost:5000/api/user/', data)
53+
axios
54+
.post(`${REACT_APP_SVR_API}/user/`, data)
3755
.then(response => {
3856
console.log(response);
3957
// Stores token in local storeage for the time being
4058
localStorage.setItem('app-token', response.data.token);
4159
// Sweet Alert for successful registration
42-
this.props.handleSignup();
60+
handleSignup();
4361
})
4462
.catch(error => {
4563
try {
4664
// Handles errors that are not HTTP specific
47-
console.log(error);
65+
console.error(error);
4866
this.setState({ showRegistrationFailure: true });
4967
if (!error.status) {
50-
console.log('A network error has occured.');
68+
console.error('A network error has occured.');
5169
} else if (error.response.status === 400) {
52-
console.log('Bad Request');
70+
console.error('Bad Request');
5371
} else if (error.response.status === 500) {
54-
console.log('Something bad happended on the server.');
72+
console.error('Something bad happended on the server.');
5573
} else {
56-
console.log('An unknown error has occurred');
74+
console.error('An unknown error has occurred');
5775
}
5876
} catch (ex) {
5977
Promise.reject(ex);
@@ -84,11 +102,11 @@ class SignUp extends Component {
84102
};
85103

86104
handleBlur = field => event => {
87-
this.setState({
88-
touched: { ...this.state.touched, [field]: true },
89-
});
105+
this.setState(prevState => ({
106+
touched: { ...prevState.touched, [field]: true },
107+
}));
90108
};
91-
109+
92110
/**
93111
* @description Controls the submit button
94112
*/
@@ -102,34 +120,27 @@ class SignUp extends Component {
102120
};
103121

104122
canBeSubmitted() {
105-
const { email, password, confirmPassword, location, fullName } = this.state;
123+
const { email, password, confirmPassword, location, fullName } = this.state;
106124
const errors = validate(
107125
email,
108126
password,
109-
confirmPassword,// Moda
127+
confirmPassword, // Moda
110128
fullName,
111-
location
129+
location,
112130
);
113131
const isDisabled = Object.keys(errors).some(x => errors[x]);
114132
return !isDisabled;
115133
}
116-
117134

118135
render() {
119-
const { email, password, confirmPassword, location, fullName } = this.state;
136+
const { email, password, confirmPassword, location, fullName, touched } = this.state;
120137
const { backToLogin } = this.props;
121-
const errors = validate(
122-
email,
123-
password,
124-
confirmPassword,
125-
fullName,
126-
location
127-
);
138+
const errors = validate(email, password, confirmPassword, fullName, location);
128139
const isDisabled = Object.keys(errors).some(x => errors[x]);
129140

130141
const shouldMarkError = field => {
131142
const hasError = errors[field];
132-
const shouldShow = this.state.touched[field];
143+
const shouldShow = touched[field];
133144

134145
return hasError ? shouldShow : false;
135146
};
@@ -141,64 +152,63 @@ class SignUp extends Component {
141152
<input
142153
className={shouldMarkError('email') ? 'error' : ''}
143154
type="text"
144-
value={this.state.email}
155+
value={email}
145156
onChange={this.handleEmailChange}
146157
onBlur={this.handleBlur('email')}
147-
placeholder='[email protected]'
158+
placeholder="[email protected]"
148159
/>
149160
<h3 className="input-labels">Password</h3>
150161
<input
151162
className={shouldMarkError('password') ? 'error' : ''}
152163
type="password"
153-
value={this.state.password}
164+
value={password}
154165
onChange={this.handlePasswordChange}
155166
onBlur={this.handleBlur('password')}
156-
placeholder='Minimum length 8 characters'
167+
placeholder="Minimum length 8 characters"
157168
/>
158169
<h3 className="input-labels">Confirm Password</h3>
159170
<input
160171
className={shouldMarkError('confirmedPassword') ? 'error' : ''}
161172
type="password"
162-
value={this.state.confirmPassword}
173+
value={confirmPassword}
163174
onChange={this.handleConfirmPassword}
164175
onBlur={this.handleBlur('confirmPassword')}
165176
/>
166177
<h3 className="input-labels">Full Name</h3>
167178
<input
168179
className={shouldMarkError('fullName') ? 'error' : ''}
169180
type="text"
170-
value={this.state.fullName}
181+
value={fullName}
171182
onChange={this.handleFullName}
172183
onBlur={this.handleBlur('fullName')}
173-
placeholder='Jane Doe'
184+
placeholder="Jane Doe"
174185
/>
175186
<h3 className="input-labels">Location</h3>
176187
<input
177188
className={shouldMarkError('location') ? 'error' : ''}
178189
type="text"
179-
value={this.state.location}
190+
value={location}
180191
onChange={this.handleLocation}
181192
onBlur={this.handleBlur('location')}
182-
placeholder='Example: Neverwinter'
193+
placeholder="Example: Neverwinter"
183194
/>
184-
<p>
185-
By clicking "Sign Up" you are agreeing
186-
to our
187-
{' '}
195+
{/* <p>
196+
{`By clicking "Sign Up" you are agreeing to our `}
188197
<a href="https://www.termsandcondiitionssample.com/live.php?token=bYAxBa2kby8ugr9x4eWMbKKgXnxOQyNg" rel="noopener noreferrer" target="_blank">Terms and Agreement</a>
189-
</p>
198+
</p> */}
190199
<button
191200
id="register-button"
192201
type="button"
193202
onClick={this.createUserHandler}
194203
disabled={isDisabled}
195204
>
196-
Sign Up
205+
{`Sign Up`}
197206
</button>
198207
<p>
199-
Go back to
200-
{' '}
201-
<button id='login-button' type="button" onClick={backToLogin()}>Log in!</button>
208+
{`Go back to `}
209+
<button id="login-button" type="button" onClick={backToLogin()}>
210+
{`Log in!`}
211+
</button>
202212
</p>
203213
</form>
204214
<WarningBanner
@@ -210,26 +220,6 @@ Go back to
210220
}
211221
}
212222

213-
/**
214-
* @description Validates all inputs to theses constraints
215-
*/
216-
const validate = (email, password, confirmedPassword, fullName, location) => ({
217-
email: email.length === 0,
218-
password: password.length < 8 || password !== confirmedPassword,
219-
fullName: fullName.length === 0,
220-
location: location.length === 0,
221-
});
222-
223-
function WarningBanner(props) {
224-
if (!props.warn) {
225-
return null;
226-
}
227-
return <div className="warning">
228-
{' '}
229-
{props.message}
230-
</div>;
231-
}
232-
233223
SignUp.propTypes = {
234224
handleSignup: PropTypes.func.isRequired,
235225
};

0 commit comments

Comments
 (0)