PasswordSettings.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import { toastSuccess, toastError } from '../../util/apiNotification';
  5. import { createSubscribedElement } from '../UnstatedUtils';
  6. import AppContainer from '../../services/AppContainer';
  7. import PersonalContainer from '../../services/PersonalContainer';
  8. class PasswordSettings extends React.Component {
  9. constructor(appContainer) {
  10. super();
  11. this.appContainer = appContainer;
  12. this.state = {
  13. oldPassword: '',
  14. newPassword: '',
  15. newPasswordConfirm: '',
  16. };
  17. this.onClickSubmit = this.onClickSubmit.bind(this);
  18. this.onChangeOldPassword = this.onChangeOldPassword.bind(this);
  19. }
  20. async onClickSubmit() {
  21. const { t } = this.props;
  22. try {
  23. // TODO GW-1136 create apiV3 for updating password
  24. toastSuccess(t('toaster.update_successed', { target: t('personal_settings.update_password') }));
  25. }
  26. catch (err) {
  27. toastError(err);
  28. }
  29. }
  30. onChangeOldPassword(oldPassword) {
  31. this.setState({ oldPassword });
  32. }
  33. onChangeNewPassword(newPassword) {
  34. this.setState({ newPassword });
  35. }
  36. onChangeNewPasswordConfirm(newPasswordConfirm) {
  37. this.setState({ newPasswordConfirm });
  38. }
  39. render() {
  40. const { t, personalContainer } = this.props;
  41. return (
  42. <React.Fragment>
  43. <div className="mb-5 container-fluid">
  44. <h2 className="border-bottom">{t('personal_settings.update_password')}</h2>
  45. </div>
  46. <div className="row mb-3">
  47. <label htmlFor="oldPassword" className="col-xs-3 text-right">{ t('personal_settings.current_password') }</label>
  48. <div className="col-xs-6">
  49. <input
  50. className="form-control"
  51. type="password"
  52. name="oldPassword"
  53. value={this.state.oldPassword}
  54. onChange={(e) => { this.onChangeOldPassword(e.target.value) }}
  55. />
  56. </div>
  57. </div>
  58. <div className="row mb-3">
  59. <label htmlFor="newPassword" className="col-xs-3 text-right">{t('personal_settings.new_password') }</label>
  60. <div className="col-xs-6">
  61. <input
  62. className="form-control"
  63. type="password"
  64. name="newPassword"
  65. value={this.state.newPassword}
  66. onChange={(e) => { this.onChangeNewPassword(e.target.value) }}
  67. />
  68. </div>
  69. </div>
  70. <div className="row mb-3">
  71. <label htmlFor="newPasswordConfirm" className="col-xs-3 text-right">{t('personal_settings.new_password_confirm') }</label>
  72. <div className="col-xs-6">
  73. <input
  74. className="form-control col-xs-4"
  75. type="password"
  76. name="newPasswordConfirm"
  77. value={this.state.newPasswordConfirm}
  78. onChange={(e) => { this.onChangeNewPasswordConfirm(e.target.value) }}
  79. />
  80. <p className="help-block">{t('page_register.form_help.password') }</p>
  81. </div>
  82. </div>
  83. <div className="row my-3">
  84. <div className="col-xs-offset-4 col-xs-5">
  85. <button type="button" className="btn btn-primary" onClick={this.onClickSubmit} disabled={personalContainer.state.retrieveError != null}>
  86. {t('Update')}
  87. </button>
  88. </div>
  89. </div>
  90. </React.Fragment>
  91. );
  92. }
  93. }
  94. const PasswordSettingsWrapper = (props) => {
  95. return createSubscribedElement(PasswordSettings, props, [AppContainer, PersonalContainer]);
  96. };
  97. PasswordSettings.propTypes = {
  98. t: PropTypes.func.isRequired, // i18next
  99. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  100. personalContainer: PropTypes.instanceOf(PersonalContainer).isRequired,
  101. };
  102. export default withTranslation()(PasswordSettingsWrapper);