delete-account.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* jshint ignore:start */
  2. import React from 'react';
  3. import Button from 'misago/components/button';
  4. import ajax from 'misago/services/ajax';
  5. import title from 'misago/services/page-title';
  6. import snackbar from 'misago/services/snackbar';
  7. import store from 'misago/services/store';
  8. import misago from 'misago';
  9. export default class extends React.Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. isLoading: false,
  14. password: '',
  15. };
  16. }
  17. componentDidMount() {
  18. title.set({
  19. title: gettext("Delete account"),
  20. parent: gettext("Change your options")
  21. });
  22. }
  23. onPasswordChange = (event) => {
  24. this.setState({ password: event.target.value });
  25. }
  26. handleSubmit = (event) => {
  27. event.preventDefault();
  28. const { isLoading, password } = this.state;
  29. const { user } = this.props;
  30. if (password.length == 0) {
  31. snackbar.error(gettext("Enter your password to confirm account deletion."));
  32. return false;
  33. }
  34. if (isLoading) return false;
  35. this.setState({ isLoading: true });
  36. ajax.post(user.api.delete, { password }).then(
  37. (success) => {
  38. window.location.href = misago.get('MISAGO_PATH');
  39. },
  40. (rejection) => {
  41. this.setState({ isLoading: false });
  42. if (rejection.password) {
  43. snackbar.error(rejection.password[0]);
  44. } else {
  45. snackbar.apiError(rejection)
  46. }
  47. }
  48. );
  49. }
  50. render() {
  51. return (
  52. <form onSubmit={this.handleSubmit}>
  53. <div className="panel panel-danger panel-form">
  54. <div className="panel-heading">
  55. <h3 className="panel-title">{gettext("Delete account")}</h3>
  56. </div>
  57. <div className="panel-body">
  58. <p className="lead">
  59. {gettext("You are going to delete your account. This action is nonreversible, and will result in following data being deleted:")}
  60. </p>
  61. <p>- {gettext("Stored IP addresses associated with content that you have posted will be deleted.")}</p>
  62. <p>- {gettext("Your username will become available for other user to rename to or for new user to register their account with.")}</p>
  63. <p>- {gettext("Your e-mail will become available for use in new account registration.")}</p>
  64. <hr/>
  65. <p>{gettext("All your posted content will NOT be deleted, but username associated with it will be changed to one shared by all deleted accounts.")}</p>
  66. </div>
  67. <div className="panel-footer">
  68. <div className="input-group">
  69. <input
  70. className="form-control"
  71. disabled={this.state.isLoading}
  72. name="password-confirmation"
  73. type="password"
  74. placeholder={gettext("Enter your password to confirm account deletion.")}
  75. value={this.state.password}
  76. onChange={this.onPasswordChange}
  77. />
  78. <span className="input-group-btn">
  79. <Button className="btn-danger" loading={this.state.isLoading}>
  80. {gettext("Delete my account")}
  81. </Button>
  82. </span>
  83. </div>
  84. </div>
  85. </div>
  86. </form>
  87. );
  88. }
  89. }