2015-10-07 18:19:29 +01:00
|
|
|
/*
|
2021-08-14 11:06:34 +02:00
|
|
|
Copyright 2018 - 2021 New Vector Ltd
|
2021-08-26 08:02:36 +01:00
|
|
|
Copyright 2015-2021 The Matrix.org Foundation C.I.C.
|
2015-10-07 18:19:29 +01:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-06-19 07:57:28 +01:00
|
|
|
import React from 'react';
|
2021-06-29 13:11:58 +01:00
|
|
|
import { MatrixClientPeg } from '../../../MatrixClientPeg';
|
2017-06-08 12:33:29 +01:00
|
|
|
import { _t } from '../../../languageHandler';
|
2021-06-29 13:11:58 +01:00
|
|
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
2021-08-17 18:05:10 +01:00
|
|
|
import EditableTextContainer from "../elements/EditableTextContainer";
|
2015-10-07 18:19:29 +01:00
|
|
|
|
2021-03-08 20:20:07 -07:00
|
|
|
@replaceableComponent("views.settings.ChangeDisplayName")
|
2020-08-29 12:14:16 +01:00
|
|
|
export default class ChangeDisplayName extends React.Component {
|
2021-08-14 11:06:34 +02:00
|
|
|
private getDisplayName = async (): Promise<string> => {
|
2017-10-11 17:56:17 +01:00
|
|
|
const cli = MatrixClientPeg.get();
|
2018-06-19 07:56:04 +01:00
|
|
|
try {
|
|
|
|
|
const res = await cli.getProfileInfo(cli.getUserId());
|
|
|
|
|
return res.displayname;
|
|
|
|
|
} catch (e) {
|
2016-07-29 17:35:48 +01:00
|
|
|
throw new Error("Failed to fetch display name");
|
2018-06-19 07:56:04 +01:00
|
|
|
}
|
2020-08-29 12:14:16 +01:00
|
|
|
};
|
2015-10-07 18:19:29 +01:00
|
|
|
|
2021-08-14 11:06:34 +02:00
|
|
|
private changeDisplayName = (newDisplayname: string): Promise<{}> => {
|
2017-10-11 17:56:17 +01:00
|
|
|
const cli = MatrixClientPeg.get();
|
2021-08-14 11:06:34 +02:00
|
|
|
return cli.setDisplayName(newDisplayname).catch(function() {
|
|
|
|
|
throw new Error("Failed to set display name");
|
2015-10-07 18:19:29 +01:00
|
|
|
});
|
2020-08-29 12:14:16 +01:00
|
|
|
};
|
2015-11-26 17:10:36 +00:00
|
|
|
|
2021-08-14 11:06:34 +02:00
|
|
|
public render(): JSX.Element {
|
2016-07-29 17:35:48 +01:00
|
|
|
return (
|
|
|
|
|
<EditableTextContainer
|
2021-08-14 11:06:34 +02:00
|
|
|
getInitialValue={this.getDisplayName}
|
2017-06-08 12:33:29 +01:00
|
|
|
placeholder={_t("No display name")}
|
2017-03-02 17:29:06 +00:00
|
|
|
blurToSubmit={true}
|
2021-08-14 11:06:34 +02:00
|
|
|
onSubmit={this.changeDisplayName} />
|
2016-07-29 17:35:48 +01:00
|
|
|
);
|
2020-08-29 12:14:16 +01:00
|
|
|
}
|
|
|
|
|
}
|