Skip to content

Commit 83bbba2

Browse files
author
riteshsangwan
committed
fix some issues
1 parent 0c3e1cb commit 83bbba2

File tree

11 files changed

+44
-28
lines changed

11 files changed

+44
-28
lines changed

config/default.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
/* eslint-disable import/no-commonjs */
22
/**
3-
* Main config file
3+
* Main config file for the server which is hosting the reat app
44
*/
55
module.exports = {
66
// below env variables are NOT visible in frontend
77
PORT: process.env.PORT || 3000,
88

99
// below env variables are visible in frontend
1010
GOOGLE_API_KEY: process.env.GOOGLE_API_KEY || 'AIzaSyCrL-O319wNJK8kk8J_JAYsWgu6yo5YsDI',
11-
API_BASE_PATH: process.env.API_BASE_PATH || 'http://localhost:3500',
12-
REACT_APP_AUTH0_CLIENT_ID: process.env.REACT_APP_AUTH0_CLIENT_ID || 'h7p6V93Shau3SSvqGrl6V4xrATlkrVGm',
13-
REACT_APP_AUTH0_CLIENT_DOMAIN: process.env.REACT_APP_AUTH0_CLIENT_DOMAIN || 'spanhawk.auth0.com',
14-
AUTH0_CALLBACK: 'http://localhost:3000',
1511
};

src/components/TextField/TextField.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
width: 100%;
33
border: 1px solid #ebebeb;
44

5+
input[type="password"],
56
input[type="text"] {
67
width: 100%;
78
padding: 0 10px;

src/config/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* eslint-disable import/no-commonjs */
2+
/**
3+
* Main config file for the react app
4+
*/
5+
module.exports = {
6+
// below env variables are visible in frontend
7+
API_BASE_PATH: process.env.API_BASE_PATH || 'http://localhost:3500',
8+
REACT_APP_AUTH0_CLIENT_ID: process.env.REACT_APP_AUTH0_CLIENT_ID || 'h7p6V93Shau3SSvqGrl6V4xrATlkrVGm',
9+
REACT_APP_AUTH0_CLIENT_DOMAIN: process.env.REACT_APP_AUTH0_CLIENT_DOMAIN || 'spanhawk.auth0.com',
10+
AUTH0_CALLBACK: 'http://localhost:3000',
11+
socket: {
12+
url: process.env.REACT_APP_SOCKET_URL || 'http://localhost:3500',
13+
},
14+
};

src/routes/DronesMap/modules/DronesMap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {handleActions} from 'redux-actions';
22
import io from 'socket.io-client';
33
import APIService from 'services/APIService';
4-
import config from '../../../../config/default';
4+
import config from '../../../config';
55

66
// Drones will be updated and map will be redrawn every 3s
77
// Otherwise if drones are updated with high frequency (e.g. 0.5s), the map will be freezing
@@ -32,7 +32,7 @@ export const init = () => async(dispatch) => {
3232
const {body: {items: drones}} = await APIService.searchDrones({limit: DRONE_LIMIT});
3333
lastUpdated = new Date().getTime();
3434
dispatch({type: DRONES_LOADED, payload: {drones}});
35-
socket = io(config.API_BASE_PATH);
35+
socket = io(config.socket.url);
3636
socket.on('dronepositionupdate', (drone) => {
3737
pendingUpdates[drone.id] = drone;
3838
if (updateTimeoutId) {

src/routes/Home/components/LoginModal/LoginModal.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import APIService from '../../../../services/APIService';
1111
import {toastr} from 'react-redux-toastr';
1212
import {defaultAuth0Service} from '../../../../services/AuthService';
1313

14+
const EMAIL_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
15+
1416
/*
1517
* customStyles
1618
*/
@@ -251,7 +253,7 @@ const validate = (values) => {
251253
const errors = {};
252254
if (!values.emailUp && !values.email) {
253255
errors.emailUp = 'Email is required';
254-
} else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(values.emailUp) && !values.email) {
256+
} else if (!EMAIL_REGEX.test(values.emailUp) && !values.email) {
255257
errors.emailUp = 'Invalid email address';
256258
}
257259

@@ -263,7 +265,7 @@ const validate = (values) => {
263265

264266
if (!values.email) {
265267
errors.email = 'Email is required';
266-
} else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(values.email)) {
268+
} else if (!EMAIL_REGEX.test(values.email)) {
267269
errors.email = 'Invalid email address';
268270
}
269271
if (!values.password) {

src/routes/ResetPassword/components/ResetPasswordView.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import FormField from '../../../components/FormField';
66
import Button from '../../../components/Button';
77
import {reduxForm} from 'redux-form';
88
import {sendRequest} from '../modules/ResetPassword';
9+
import {browserHistory} from 'react-router';
10+
import {toastr} from 'react-redux-toastr';
911

1012
class ResetPasswordView extends Component {
1113

@@ -14,7 +16,13 @@ class ResetPasswordView extends Component {
1416
* This is triggered by handleSubmit
1517
*/
1618
onSubmit(data) {
17-
return sendRequest(data);
19+
sendRequest(data).then(() => {
20+
toastr.success('', 'Password reset successfuly, kindly login again');
21+
browserHistory.push('/');
22+
}).catch((reason) => {
23+
const message = reason.response.body.error || 'something went wrong, please try again';
24+
toastr.error(message);
25+
});
1826
}
1927

2028
render() {
@@ -32,7 +40,7 @@ class ResetPasswordView extends Component {
3240
<div styleName="row">
3341
<label htmlFor="password">Password:</label>
3442
<FormField {...fields.password} className="password-field">
35-
<TextField {...fields.password} label={'New Password'} />
43+
<TextField {...fields.password} type={'password'} label={'New Password'} />
3644
</FormField>
3745
</div>
3846

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import {asyncConnect} from 'redux-connect';
22
import {actions} from '../modules/ResetPassword';
3-
import {browserHistory} from 'react-router';
43

54
import ResetPasswordView from '../components/ResetPasswordView';
65

76
const resolve = [{
87
promise: () => Promise.resolve(),
98
}];
109

11-
const handleSuccess = () => {
12-
browserHistory.push('/');
13-
};
14-
15-
const mapState = (state) => ({...state.resetPassword, onSubmitSuccess: handleSuccess});
10+
const mapState = (state) => state.resetPassword;
1611

1712
export default asyncConnect(resolve, mapState, actions)(ResetPasswordView);

src/routes/ResetPassword/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default (store) => ({
1111

1212
injectReducer(store, {key: 'resetPassword', reducer});
1313
if (!nextState.location.query.token) {
14-
cb(new Error('Invalid route invokation'));
14+
cb(new Error('Invalid route invocation'));
1515
} else {
1616
cb(null, Dashboard);
1717
}

src/services/APIService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import _ from 'lodash';
44
import superagent from 'superagent';
55
import superagentPromise from 'superagent-promise';
6-
import config from '../../config/default';
6+
import config from '../config';
77

88
// DEMO: emulate API requests with dummy data for demo purposes
99

src/services/AuthService.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Copyright (c) 2016 Topcoder Inc, All rights reserved.
33
*/
4-
/* eslint no-console: 0 */
4+
55
/**
66
* auth0 Authentication service for the app.
77
*
@@ -10,11 +10,13 @@
1010
*/
1111

1212
import Auth0 from 'auth0-js';
13-
import config from '../../config/default';
13+
import config from '../config';
1414
import UserApi from '../api/User';
15+
import _ from 'lodash';
1516

1617

1718
const userApi = new UserApi(config.API_BASE_PATH);
19+
const idTokenKey = 'id_token';
1820

1921
class AuthService {
2022

@@ -68,9 +70,7 @@ class AuthService {
6870
_self.removeToken();
6971
throw error;
7072
} else {
71-
userApi.registerSocialUser(profile.name, profile.email, _self.getToken()).then((loginResult) => {
72-
console.log('user registered successfully', loginResult);
73-
}).catch((reason) => {
73+
userApi.registerSocialUser(profile.name, profile.email, _self.getToken()).then(_.noop).catch((reason) => {
7474
// remove the id token
7575
_self.removeToken();
7676
throw reason;
@@ -95,23 +95,23 @@ class AuthService {
9595
*/
9696
setToken(idToken) {
9797
// Saves user token to localStorage
98-
localStorage.setItem('id_token', idToken);
98+
localStorage.setItem(idTokenKey, idToken);
9999
}
100100

101101
/**
102102
* Get the stored id token from local storage
103103
*/
104104
getToken() {
105105
// Retrieves the user token from localStorage
106-
return localStorage.getItem('id_token');
106+
return localStorage.getItem(idTokenKey);
107107
}
108108

109109
/**
110110
* Remove the id token from local storage
111111
*/
112112
removeToken() {
113113
// Clear user token and profile data from localStorage
114-
localStorage.removeItem('id_token');
114+
localStorage.removeItem(idTokenKey);
115115
}
116116

117117
/**

src/store/modules/global.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {handleActions, createAction} from 'redux-actions';
22
import {browserHistory} from 'react-router';
33
import UserApi from 'api/User.js';
4-
import config from '../../../config/default';
4+
import config from '../../config';
55

66
const userApi = new UserApi(config.API_BASE_PATH);
77

0 commit comments

Comments
 (0)