|
| 1 | +/* |
| 2 | +Copyright 2020 Awesome Technologies Innovationslabor GmbH |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import React from 'react'; |
| 18 | +import createReactClass from 'create-react-class'; |
| 19 | +import PropTypes from 'prop-types'; |
| 20 | +import * as sdk from '../../../index'; |
| 21 | +import * as Email from '../../../email'; |
| 22 | +import AddThreepid from '../../../AddThreepid'; |
| 23 | +import { _t } from '../../../languageHandler'; |
| 24 | +import Modal from '../../../Modal'; |
| 25 | +import {MatrixClientPeg} from '../../../MatrixClientPeg'; |
| 26 | + |
| 27 | + |
| 28 | +/** |
| 29 | + * Prompt the user to set a displayname. |
| 30 | + * |
| 31 | + * On success, `onFinished(true)` is called. |
| 32 | + */ |
| 33 | +export default createReactClass({ |
| 34 | + displayName: 'SetDisplaynameDialog', |
| 35 | + propTypes: { |
| 36 | + onFinished: PropTypes.func.isRequired, |
| 37 | + }, |
| 38 | + |
| 39 | + getInitialState: function() { |
| 40 | + return { |
| 41 | + displayname: '', |
| 42 | + }; |
| 43 | + }, |
| 44 | + |
| 45 | + onDisplaynameChanged: function(value) { |
| 46 | + this.setState({ |
| 47 | + displayname: value, |
| 48 | + }); |
| 49 | + }, |
| 50 | + |
| 51 | + onSubmit: function() { |
| 52 | + const displayname = this.state.displayname; |
| 53 | + |
| 54 | + const cli = MatrixClientPeg.get(); |
| 55 | + cli.setDisplayName(displayname).catch(function(e) { |
| 56 | + throw new Error("Failed to set display name", e); |
| 57 | + }); |
| 58 | + |
| 59 | + this.props.onFinished(true); |
| 60 | + }, |
| 61 | + |
| 62 | + onCancelled: function() { |
| 63 | + this.props.onFinished(false); |
| 64 | + }, |
| 65 | + |
| 66 | + onEmailDialogFinished: function(ok) { |
| 67 | + if (ok) { |
| 68 | + this.verifyEmailAddress(); |
| 69 | + } else { |
| 70 | + this.setState({emailBusy: false}); |
| 71 | + } |
| 72 | + }, |
| 73 | + |
| 74 | + render: function() { |
| 75 | + const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog'); |
| 76 | + const EditableText = sdk.getComponent('elements.EditableText'); |
| 77 | + |
| 78 | + return ( |
| 79 | + <BaseDialog className="mx_SetEmailDialog" |
| 80 | + onFinished={this.onCancelled} |
| 81 | + title={this.props.title} |
| 82 | + contentId='mx_Dialog_content' |
| 83 | + > |
| 84 | + <div className="mx_Dialog_content"> |
| 85 | + <p id='mx_Dialog_content'> |
| 86 | + { _t('This will allow others to identify you and your account.') } |
| 87 | + </p> |
| 88 | + <EditableText |
| 89 | + initialValue={this.state.displayname} |
| 90 | + className="mx_SetEmailDialog_email_input" |
| 91 | + autoFocus="true" |
| 92 | + placeholder={_t("Displayname")} |
| 93 | + placeholderClassName="mx_SetEmailDialog_email_input_placeholder" |
| 94 | + blurToCancel={false} |
| 95 | + onValueChanged={this.onDisplaynameChanged} /> |
| 96 | + </div> |
| 97 | + <div className="mx_Dialog_buttons"> |
| 98 | + <input className="mx_Dialog_primary" |
| 99 | + type="submit" |
| 100 | + value={_t("Continue")} |
| 101 | + onClick={this.onSubmit} |
| 102 | + /> |
| 103 | + <input |
| 104 | + type="submit" |
| 105 | + value={_t("Skip")} |
| 106 | + onClick={this.onCancelled} |
| 107 | + /> |
| 108 | + </div> |
| 109 | + </BaseDialog> |
| 110 | + ); |
| 111 | + }, |
| 112 | +}); |
0 commit comments