Skip to content

Commit

Permalink
fix(account): show dialog after password change success
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikThePendric committed Dec 2, 2019
1 parent e74e7b1 commit ec779c5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
3 changes: 3 additions & 0 deletions i18n/module/i18n_module_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,6 @@ false=No
yes=Yes
no=No
password_changed_successfully=Password changed successfully
login_again=You need to login again to continue using the application.
login=Login
39 changes: 39 additions & 0 deletions src/account/PasswordChangeSuccessDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FlatButton, Dialog } from 'material-ui';

import appActions from '../app.actions';

// In development environments this won't provide the correct behavior
// because the app is hosted on a different port, but once an app is deployed
// reloading the window with an invalidated session will redirect to the login page
const reload = () => {
appActions.setCategory('account')
window.location.reload(true);
}

function PasswordChangeSuccessDialog(props, context) {
const titleText = context.d2.i18n.getTranslation('password_changed_successfully');
const bodyText = context.d2.i18n.getTranslation('login_again');
const buttonText = context.d2.i18n.getTranslation('login');

const buttons = [
<FlatButton label={buttonText} primary onClick={reload} />,
];
return (
<Dialog
title={titleText}
actions={buttons}
modal
open
>
{bodyText}
</Dialog>
);
}

PasswordChangeSuccessDialog.contextTypes = {
d2: PropTypes.object.isRequired
};

export default PasswordChangeSuccessDialog;
7 changes: 3 additions & 4 deletions src/account/account.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ accountActions.setPassword.subscribe(({ data: [oldPassword, newPassword, onSucce
api.update('/me/changePassword', payload)
.then(() => {
log.debug('Password updated successfully.');
appActions.showSnackbarMessage({
message: d2.i18n.getTranslation('password_update_success'),
status: 'success',
});

appActions.setCategory('passwordChanged');

onSuccess();
complete();
})
Expand Down
2 changes: 2 additions & 0 deletions src/app.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import TwoFactor from './account/twoFactor/TwoFactor';
import UserSettings from './settings/UserSettings.component';
import ViewProfile from './viewProfile/ViewProfile.component';
import AboutPage from './aboutPage/AboutPage.component';
import PasswordChangeSuccessDialog from './account/PasswordChangeSuccessDialog';

function WrAppadApp(props) {
return (
Expand Down Expand Up @@ -48,6 +49,7 @@ class AppRouter extends Component {
<Route path="profile" component={Profile} />
<Route path="account" component={Account} />
<Route path="twoFactor" component={TwoFactor} />
<Route path="passwordChanged" component={PasswordChangeSuccessDialog} />
<Route path="viewProfile" component={ViewProfile} />
<Route path="aboutPage" component={AboutPage} />
<Redirect from="/" to="/viewProfile" />
Expand Down

0 comments on commit ec779c5

Please sign in to comment.