Skip to content

Commit 9d72748

Browse files
author
riteshsangwan
committed
implement reset password
1 parent 90a9c9e commit 9d72748

File tree

8 files changed

+196
-2
lines changed

8 files changed

+196
-2
lines changed

config/default.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ module.exports = {
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 || 'https://kb-dsp-server-dev.herokuapp.com',
11+
API_BASE_PATH: process.env.API_BASE_PATH || 'http://localhost:3500',
1212
};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React, {Component} from 'react';
2+
import CSSModules from 'react-css-modules';
3+
import styles from './ResetPasswordView.scss';
4+
import TextField from '../../../components/TextField';
5+
import FormField from '../../../components/FormField';
6+
import Button from '../../../components/Button';
7+
import {reduxForm} from 'redux-form';
8+
import {sendRequest} from '../modules/ResetPassword';
9+
10+
class ResetPasswordView extends Component {
11+
12+
/**
13+
* This function is called when the form is submitted
14+
* This is triggered by handleSubmit
15+
*/
16+
onSubmit(data) {
17+
return sendRequest(data);
18+
}
19+
20+
render() {
21+
const {fields, handleSubmit, location: {query: {token}}} = this.props;
22+
const _self = this;
23+
return (
24+
<div styleName="reset-password-form">
25+
<form onSubmit={handleSubmit((data) => _self.onSubmit({...data, code: token}))}>
26+
<div styleName="row">
27+
<label htmlFor="email">Email:</label>
28+
<FormField {...fields.email}>
29+
<TextField {...fields.email} label={'email'} />
30+
</FormField>
31+
</div>
32+
<div styleName="row">
33+
<label htmlFor="password">Password:</label>
34+
<FormField {...fields.password}>
35+
<TextField {...fields.password} label={'New Password'} />
36+
</FormField>
37+
</div>
38+
39+
{/* add-package end */}
40+
<div styleName="actions">
41+
<Button type="submit" color="blue">Submit</Button>
42+
</div>
43+
</form>
44+
{/* form end */}
45+
</div>
46+
);
47+
}
48+
}
49+
50+
ResetPasswordView.propTypes = {
51+
fields: React.PropTypes.object.isRequired,
52+
location: React.PropTypes.object.isRequired,
53+
handleSubmit: React.PropTypes.func.isRequired,
54+
};
55+
56+
const form = reduxForm({
57+
form: 'resetPasswordForm',
58+
fields: ['password', 'email'],
59+
validate(values) {
60+
const errors = {};
61+
if (!values.password) {
62+
errors.password = 'required';
63+
}
64+
if (!values.email) {
65+
errors.email = 'required';
66+
}
67+
68+
return errors;
69+
},
70+
});
71+
72+
export default form(CSSModules(ResetPasswordView, styles));
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.reset-password-form {
2+
padding: 50px 0 14px;
3+
margin: 0 300px;
4+
height: calc(100vh - 60px - 42px - 50px); // header height - breadcrumb height - footer height
5+
h4 {
6+
font-weight: bold;
7+
font-size: 20px;
8+
color: #525051;
9+
margin-top: 40px;
10+
border-top: 1px solid #e7e8ea;
11+
padding-top: 25px;
12+
}
13+
}
14+
.row {
15+
display: flex;
16+
margin-bottom: 22px;
17+
label {
18+
display: block;
19+
flex: 0 0 20%;
20+
align-self: center;
21+
font-size: 14px;
22+
color: #343434;
23+
font-weight: bold;
24+
}
25+
26+
.input-with-label {
27+
flex: 0 0 20%;
28+
display: flex;
29+
align-items: center;
30+
.input {
31+
flex: 0 0 66%;
32+
}
33+
}
34+
}
35+
.actions {
36+
text-align: right;
37+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {asyncConnect} from 'redux-connect';
2+
import {actions} from '../modules/ResetPassword';
3+
import {browserHistory} from 'react-router';
4+
5+
import ResetPasswordView from '../components/ResetPasswordView';
6+
7+
const resolve = [{
8+
promise: () => Promise.resolve(),
9+
}];
10+
11+
const handleSuccess = () => {
12+
browserHistory.push('/');
13+
};
14+
15+
const mapState = (state) => ({...state.resetPassword, onSubmitSuccess: handleSuccess});
16+
17+
export default asyncConnect(resolve, mapState, actions)(ResetPasswordView);

src/routes/ResetPassword/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {injectReducer} from '../../store/reducers';
2+
3+
export default (store) => ({
4+
path: 'reset-password',
5+
name: 'Reset password', /* Breadcrumb name */
6+
staticName: true,
7+
getComponent(nextState, cb) {
8+
require.ensure([], (require) => {
9+
const Dashboard = require('./containers/ResetPasswordContainer').default;
10+
const reducer = require('./modules/ResetPassword').default;
11+
12+
injectReducer(store, {key: 'resetPassword', reducer});
13+
if (!nextState.location.query.token) {
14+
cb(new Error('Invalid route invokation'));
15+
} else {
16+
cb(null, Dashboard);
17+
}
18+
}, 'ResetPassword');
19+
},
20+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {handleActions} from 'redux-actions';
2+
import APIService from 'services/APIService';
3+
// ------------------------------------
4+
// Actions
5+
// ------------------------------------
6+
7+
export const actions = {
8+
};
9+
10+
export const sendRequest = (values) => new Promise((resolve, reject) => {
11+
APIService.resetPassword(values).then((result) => {
12+
resolve(result);
13+
}).catch((reason) => {
14+
reject(reason);
15+
});
16+
});
17+
18+
// ------------------------------------
19+
// Reducer
20+
// ------------------------------------
21+
export default handleActions({
22+
}, {
23+
});

src/routes/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import BrowseProviderRoute from './BrowseProvider';
1919
import DroneDetailsRoute from './DroneDetails';
2020
import AvailablePackagesRoute from './AvailablePackages';
2121
import ProviderDetailsRoute from './ProviderDetails';
22+
import ResetPasswordRoute from './ResetPassword';
2223

2324
export const createRoutes = (store) => ({
2425
path: '/',
@@ -53,7 +54,7 @@ export const createRoutes = (store) => ({
5354
DroneDetailsRoute(store),
5455
AvailablePackagesRoute(store),
5556
ProviderDetailsRoute(store),
56-
57+
ResetPasswordRoute(store),
5758
],
5859
});
5960

src/services/APIService.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,4 +578,28 @@ export default class APIService {
578578
.query(params)
579579
.end();
580580
}
581+
582+
/**
583+
* Reset the user password
584+
* @param {Object} entity the client request payload
585+
*/
586+
static resetPassword(entity) {
587+
return request
588+
.post(`${config.API_BASE_PATH}/api/v1/reset-password`)
589+
.set('Content-Type', 'application/json')
590+
.send(entity)
591+
.end();
592+
}
593+
594+
/**
595+
* Send the forgot password link to user's email account
596+
* @param {Object} entity the client request payload
597+
*/
598+
static forgotPassword(entity) {
599+
return request
600+
.post(`${config.API_BASE_PATH}/api/v1/forgot-password`)
601+
.set('Content-Type', 'application/json')
602+
.send(entity)
603+
.end();
604+
}
581605
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy