Fix publishing address wrongly demanding the alias be available (#7690)

This commit is contained in:
Michael Telatynski 2022-02-01 15:06:26 +00:00 committed by GitHub
parent bf8c04ff55
commit 98c5f50f36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 8 deletions

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import React, { ChangeEvent, ContextType, createRef } from "react";
import React, { ChangeEvent, ContextType, createRef, SyntheticEvent } from "react";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { logger } from "matrix-js-sdk/src/logger";
@ -32,13 +32,15 @@ import MatrixClientContext from "../../../contexts/MatrixClientContext";
import SettingsFieldset from "../settings/SettingsFieldset";
interface IEditableAliasesListProps {
roomId?: string;
domain?: string;
}
class EditableAliasesList extends EditableItemList<IEditableAliasesListProps> {
private aliasField = createRef<RoomAliasField>();
private onAliasAdded = async () => {
private onAliasAdded = async (ev: SyntheticEvent) => {
ev.preventDefault();
await this.aliasField.current.validate({ allowEmpty: false });
if (this.aliasField.current.isValid) {
@ -51,7 +53,7 @@ class EditableAliasesList extends EditableItemList<IEditableAliasesListProps> {
};
protected renderNewItemField() {
const onChange = (alias) => this.onNewItemChanged({ target: { value: alias } });
const onChange = (alias: string) => this.onNewItemChanged({ target: { value: alias } });
return (
<form
onSubmit={this.onAliasAdded}
@ -63,7 +65,9 @@ class EditableAliasesList extends EditableItemList<IEditableAliasesListProps> {
ref={this.aliasField}
onChange={onChange}
value={this.props.newItem || ""}
domain={this.props.domain} />
domain={this.props.domain}
roomId={this.props.roomId}
/>
<AccessibleButton onClick={this.onAliasAdded} kind="primary">
{ _t("Add") }
</AccessibleButton>
@ -360,7 +364,7 @@ export default class AliasSettings extends React.Component<IProps, IState> {
</Field>
);
let localAliasesList;
let localAliasesList: JSX.Element;
if (this.state.localAliasesLoading) {
localAliasesList = <Spinner />;
} else {
@ -428,6 +432,7 @@ export default class AliasSettings extends React.Component<IProps, IState> {
itemsLabel={_t('Other published addresses:')}
noItemsLabel={_t('No other published addresses yet, add one below')}
placeholder={_t('New published address (e.g. #alias:server)')}
roomId={this.props.roomId}
/>
</SettingsFieldset>
<SettingsFieldset