Merge pull request #6791 from matrix-org/t3chguy/fix/19003
commit
0ee77e2d17
|
@ -97,9 +97,8 @@ const spaceNameValidator = withValidation({
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const nameToAlias = (name: string, domain: string): string => {
|
const nameToLocalpart = (name: string): string => {
|
||||||
const localpart = name.trim().toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9_-]+/gi, "");
|
return name.trim().toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9_-]+/gi, "");
|
||||||
return `#${localpart}:${domain}`;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// XXX: Temporary for the Spaces release only
|
// XXX: Temporary for the Spaces release only
|
||||||
|
@ -176,8 +175,8 @@ export const SpaceCreateForm: React.FC<ISpaceCreateFormProps> = ({
|
||||||
value={name}
|
value={name}
|
||||||
onChange={ev => {
|
onChange={ev => {
|
||||||
const newName = ev.target.value;
|
const newName = ev.target.value;
|
||||||
if (!alias || alias === nameToAlias(name, domain)) {
|
if (!alias || alias === `#${nameToLocalpart(name)}:${domain}`) {
|
||||||
setAlias(nameToAlias(newName, domain));
|
setAlias(`#${nameToLocalpart(newName)}:${domain}`);
|
||||||
aliasFieldRef.current.validate({ allowEmpty: true });
|
aliasFieldRef.current.validate({ allowEmpty: true });
|
||||||
}
|
}
|
||||||
setName(newName);
|
setName(newName);
|
||||||
|
@ -195,7 +194,7 @@ export const SpaceCreateForm: React.FC<ISpaceCreateFormProps> = ({
|
||||||
onChange={setAlias}
|
onChange={setAlias}
|
||||||
domain={domain}
|
domain={domain}
|
||||||
value={alias}
|
value={alias}
|
||||||
placeholder={name ? nameToAlias(name, domain) : _t("e.g. my-space")}
|
placeholder={name ? nameToLocalpart(name) : _t("e.g. my-space")}
|
||||||
label={_t("Address")}
|
label={_t("Address")}
|
||||||
disabled={busy}
|
disabled={busy}
|
||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
|
@ -218,6 +217,7 @@ export const SpaceCreateForm: React.FC<ISpaceCreateFormProps> = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
const SpaceCreateMenu = ({ onFinished }) => {
|
const SpaceCreateMenu = ({ onFinished }) => {
|
||||||
|
const cli = useContext(MatrixClientContext);
|
||||||
const [visibility, setVisibility] = useState<Visibility>(null);
|
const [visibility, setVisibility] = useState<Visibility>(null);
|
||||||
const [busy, setBusy] = useState<boolean>(false);
|
const [busy, setBusy] = useState<boolean>(false);
|
||||||
|
|
||||||
|
@ -234,14 +234,18 @@ const SpaceCreateMenu = ({ onFinished }) => {
|
||||||
|
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
// require & validate the space name field
|
// require & validate the space name field
|
||||||
if (!await spaceNameField.current.validate({ allowEmpty: false })) {
|
if (!(await spaceNameField.current.validate({ allowEmpty: false }))) {
|
||||||
spaceNameField.current.focus();
|
spaceNameField.current.focus();
|
||||||
spaceNameField.current.validate({ allowEmpty: false, focused: true });
|
spaceNameField.current.validate({ allowEmpty: false, focused: true });
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// validate the space name alias field but do not require it
|
|
||||||
if (visibility === Visibility.Public && !await spaceAliasField.current.validate({ allowEmpty: true })) {
|
// validate the space alias field but do not require it
|
||||||
|
const aliasLocalpart = alias.substring(1, alias.length - cli.getDomain().length - 1);
|
||||||
|
if (visibility === Visibility.Public && aliasLocalpart &&
|
||||||
|
(await spaceAliasField.current.validate({ allowEmpty: true })) === false
|
||||||
|
) {
|
||||||
spaceAliasField.current.focus();
|
spaceAliasField.current.focus();
|
||||||
spaceAliasField.current.validate({ allowEmpty: true, focused: true });
|
spaceAliasField.current.validate({ allowEmpty: true, focused: true });
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
|
@ -249,7 +253,13 @@ const SpaceCreateMenu = ({ onFinished }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await createSpace(name, visibility === Visibility.Public, alias, topic, avatar);
|
await createSpace(
|
||||||
|
name,
|
||||||
|
visibility === Visibility.Public,
|
||||||
|
aliasLocalpart ? alias : undefined,
|
||||||
|
topic,
|
||||||
|
avatar,
|
||||||
|
);
|
||||||
|
|
||||||
onFinished();
|
onFinished();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue