Skip to content

Commit

Permalink
Merge pull request #30 from andela/bg/168374435/password-reset-feedback
Browse files Browse the repository at this point in the history
#168374435 Implement password reset feedback
  • Loading branch information
topseySuave committed Sep 10, 2019
2 parents b237e93 + 6aa6d74 commit 05fa735
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A social platform for the creative heart",
"main": "index.js",
"scripts": {
"test": "jest --coverage --coverageReporters=text-lcov | coveralls",
"test": "jest --coverage",
"e2e": "nightwatch",
"start": "export DEBUG=prod && node server/app.js",
"dev": "webpack-dev-server --open --config build-utils/webpack.config.js --env.env=dev",
Expand Down
11 changes: 11 additions & 0 deletions src/actions/__tests__/__snapshots__/authActions.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ Array [
]
`;

exports[`Auth action tests Async password request action test should throw error as expected 1`] = `
Array [
Object {
"type": "LOADING",
},
Object {
"type": "NOT_LOADING",
},
]
`;

exports[`Auth action tests Async password reset action test reset new password 1`] = `
Array [
Object {
Expand Down
10 changes: 5 additions & 5 deletions src/actions/__tests__/authActions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ describe('Auth action tests', () => {
token: 'abcd',
};

const { id, token } = data;
const { id, token, password } = data;

beforeEach(() => {
store = mockStore({});
Expand All @@ -220,10 +220,10 @@ describe('Auth action tests', () => {
nock.cleanAll();
});

it('reset new password', () => (store.dispatch(setNewPassword({ id, token }, { push: jest.fn() }))
it('reset new password', () => (store.dispatch(setNewPassword({ id, token, password }, { push: jest.fn() }))
.then(() => {
nock(url)
.put(`/users/resetPassword/${id}/${token}`)
.put(`/users/resetPassword/${id}/${token}`, { user: { password } })
.reply(200, response);
response.status = 200;
expect(response.status).toEqual(200);
Expand Down Expand Up @@ -258,10 +258,10 @@ describe('Auth action tests', () => {
},
};

return store.dispatch(setNewPassword({ id, token }, { push: jest.fn() }))
return store.dispatch(setNewPassword({ id, token, password }, { push: jest.fn() }))
.then(() => {
nock(url)
.post(`/users/resetPassword/${id}/${token}`)
.post(`/users/resetPassword/${id}/${token}`, { user: { password } })
.reply(400, errorResponse.err);
})
.then(() => {
Expand Down
38 changes: 29 additions & 9 deletions src/actions/authActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,21 @@ export const createUser = (userData, history) => async (dispatch) => {
};

export const requestPasswordLink = (email) => async (dispatch) => {
const response = await axiosInstance.post('users/passwordReset', { user: { email } });
dispatch({
type: LOADING,
});

try {
const response = await axiosInstance.post('users/passwordReset', { user: { email } });
if (response.data.status === 200) {
toast.dismiss();
toast.success(response.data.message);
swal({
title: 'Done!',
text: 'Check your mail for password reset link',
icon: 'success',
button: {
className: 'sweet-alert-btn',
},
});
}
dispatch({
type: NOT_LOADING,
Expand All @@ -101,8 +107,12 @@ export const requestPasswordLink = (email) => async (dispatch) => {
});
} catch (err) {
const { error } = err.response.data;
toast.dismiss();
toast.error(error, { autoClose: 5000 });
swal({
text: error,
icon: 'error',
button: false,
timer: 3000,
});
return dispatch({
type: NOT_LOADING,
});
Expand All @@ -121,14 +131,24 @@ export const setNewPassword = (data, history) => async (dispatch) => {

if (response.status === 200) {
history.push('/');
toast.dismiss();
toast.success(response.data.message);
swal({
title: 'Done!',
text: 'Password reset successfully',
icon: 'success',
button: {
className: 'sweet-alert-btn',
},
});
}
dispatch({ type: NOT_LOADING });
} catch (err) {
const { error } = err.response.data;
toast.dismiss();
toast.error(error, { autoClose: 5000 });
swal({
text: error,
icon: 'error',
button: false,
timer: 3000,
});
}
};
export const loginViaSocial = (brand) => async dispatch => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Forms/PasswordRequest/PasswordRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class PasswordRequest extends Component {
/>
<Button
datatest="send-password-link"
label={loading ? null : 'Send Request Link'}
label={loading ? null : 'Send reset link'}
type="submit"
handleClick={this.handleSubmit}
style={{
Expand Down
2 changes: 1 addition & 1 deletion src/components/Forms/SignIn/SignIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class SignIn extends Component {
/>
<Button
datatest="loginButton"
label={loading ? null : 'Sign In'}
label={loading ? null : 'Sign in'}
handleClick={this.handleSubmit}
disabled={loading ? true : !isFormValid}
type="submit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ exports[`test social media sign in should click the google signin button 1`] = `
disabled={false}
handleClick={[Function]}
id="signin"
label="Sign In"
label="Sign in"
style={
Object {
"backgroundColor": "#000",
Expand Down
2 changes: 1 addition & 1 deletion src/views/ResetPassword/ResetPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class ResetPassword extends Component {
error={error.confirmPassword}
/>
<Button
label={loading ? null : 'Change Passsword'}
label={loading ? null : 'Change passsword'}
type="submit"
handleClick={this.handleSubmit}
style={{
Expand Down
3 changes: 2 additions & 1 deletion src/views/ResetPassword/ResetPassword.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ describe('Password reset component', () => {
});

it('should validate password', () => {
instance.validatePassword();
instance.validate = jest.fn();
expect(instance.validate).toHaveBeenCalledTimes(0);
});

it('test submit', () => {
Expand Down
8 changes: 8 additions & 0 deletions src/views/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ body {
}
}
}

.sweet-alert-btn {
background-color: #fbc02a !important;
transition: ease-in-out .5s;
&:hover {
background-color: #fbc02aa6 !important;
}
}

0 comments on commit 05fa735

Please sign in to comment.