element-portable/src/components/views/dialogs/DeactivateAccountDialog.js
Marcel 70e7d81093 More i18n strings (#963)
* Add i18n for E2E import and Export Dialogs

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add various previous missing i18n strings

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Translate CreateRoomButton

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add ChatInviteDialog and fix missing to.

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add ConfitmRedactDialog translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add DeactivateAccountDialog translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add DeviceVerifyDialog translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add SessionRestoreErrorDialog translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add SetDisplayNameDialog translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add UnknownDeviceDialog translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add AddressTile translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add DeviceVerifyButtons translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add Dropdown translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add UserSelector translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add CaptchaForm translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add CasLogin translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add CustomServerDialog translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add InteractiveAuthEntryComponents translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add LoginFooter translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add RegistrationForm translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add ServerConfig translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add MAudioBody translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add MImageBody translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add MVideoBody translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add TextualBody translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add UnknownBody translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add UrlPreviewSettings translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add AuxPanel translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* Add PresenceLabel translations

Signed-off-by: MTRNord <mtrnord1@gmail.com>

* fix syntax error

* weird space :P

* missing ','

* fix missing value

* fix json fail

* remove acidential added file

* fix another json fail
2017-05-30 15:09:57 +01:00

138 lines
4.4 KiB
JavaScript

/*
Copyright 2016 OpenMarket Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import React from 'react';
import sdk from '../../../index';
import MatrixClientPeg from '../../../MatrixClientPeg';
import * as Lifecycle from '../../../Lifecycle';
import Velocity from 'velocity-vector';
import { _t } from '../../../languageHandler';
export default class DeactivateAccountDialog extends React.Component {
constructor(props, context) {
super(props, context);
this._passwordField = null;
this._onOk = this._onOk.bind(this);
this._onCancel = this._onCancel.bind(this);
this._onPasswordFieldChange = this._onPasswordFieldChange.bind(this);
this.state = {
confirmButtonEnabled: false,
busy: false,
errStr: null,
};
}
_onPasswordFieldChange(ev) {
this.setState({
confirmButtonEnabled: Boolean(ev.target.value),
});
}
_onOk() {
// This assumes that the HS requires password UI auth
// for this endpoint. In reality it could be any UI auth.
this.setState({busy: true});
MatrixClientPeg.get().deactivateAccount({
type: 'm.login.password',
user: MatrixClientPeg.get().credentials.userId,
password: this._passwordField.value,
}).done(() => {
Lifecycle.onLoggedOut();
this.props.onFinished(false);
}, (err) => {
let errStr = _t('Unknown error');
// https://matrix.org/jira/browse/SYN-744
if (err.httpStatus == 401 || err.httpStatus == 403) {
errStr = _t('Incorrect password');
Velocity(this._passwordField, "callout.shake", 300);
}
this.setState({
busy: false,
errStr: errStr,
});
});
}
_onCancel() {
this.props.onFinished(false);
}
render() {
const Loader = sdk.getComponent("elements.Spinner");
let passwordBoxClass = '';
let error = null;
if (this.state.errStr) {
error = <div className="error">
{this.state.errStr}
</div>;
passwordBoxClass = 'error';
}
const okLabel = this.state.busy ? <Loader /> : 'Deactivate Account';
const okEnabled = this.state.confirmButtonEnabled && !this.state.busy;
let cancelButton = null;
if (!this.state.busy) {
cancelButton = <button onClick={this._onCancel} autoFocus={true}>
{_t("Cancel")}
</button>;
}
return (
<div className="mx_DeactivateAccountDialog">
<div className="mx_Dialog_title danger">
{_t("Deactivate Account")}
</div>
<div className="mx_Dialog_content">
<p>{_t("This will make your account permanently unusable. You will not be able to re-register the same user ID.")}</p>
<p>{_t("This action is irreversible.")}</p>
<p>{_t("To continue, please enter your password.")}</p>
<p>{_t("Password")}:</p>
<input
type="password"
onChange={this._onPasswordFieldChange}
ref={(e) => {this._passwordField = e;}}
className={passwordBoxClass}
/>
{error}
</div>
<div className="mx_Dialog_buttons">
<button
className="mx_Dialog_primary danger"
onClick={this._onOk}
disabled={!okEnabled}
>
{okLabel}
</button>
{cancelButton}
</div>
</div>
);
}
}
DeactivateAccountDialog.propTypes = {
onFinished: React.PropTypes.func.isRequired,
};