Better feedback in invite dialog
Show feedback if you enter a valid but unknown email address or mxid Fixes https://github.com/vector-im/riot-web/issues/2933
This commit is contained in:
parent
fcb1d7a664
commit
de621902fc
4 changed files with 26 additions and 7 deletions
|
@ -19,9 +19,12 @@ import MultiInviter from './utils/MultiInviter';
|
||||||
|
|
||||||
const emailRegex = /^\S+@\S+\.\S+$/;
|
const emailRegex = /^\S+@\S+\.\S+$/;
|
||||||
|
|
||||||
|
// We allow localhost for mxids to avoid confusion
|
||||||
|
const mxidRegex = /^@\S+:(?:\S+\.\S+|localhost)$/
|
||||||
|
|
||||||
export function getAddressType(inputText) {
|
export function getAddressType(inputText) {
|
||||||
const isEmailAddress = /^\S+@\S+\.\S+$/.test(inputText);
|
const isEmailAddress = emailRegex.test(inputText);
|
||||||
const isMatrixId = inputText[0] === '@' && inputText.indexOf(":") > 0;
|
const isMatrixId = mxidRegex.test(inputText);
|
||||||
|
|
||||||
// sanity check the input for user IDs
|
// sanity check the input for user IDs
|
||||||
if (isEmailAddress) {
|
if (isEmailAddress) {
|
||||||
|
|
|
@ -154,14 +154,26 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
onQueryChanged: function(ev) {
|
onQueryChanged: function(ev) {
|
||||||
var query = ev.target.value;
|
const query = ev.target.value;
|
||||||
var queryList = [];
|
let queryList = [];
|
||||||
|
|
||||||
// Only do search if there is something to search
|
// Only do search if there is something to search
|
||||||
if (query.length > 0) {
|
if (query.length > 0 && query != '@') {
|
||||||
|
// filter the known users list
|
||||||
queryList = this._userList.filter((user) => {
|
queryList = this._userList.filter((user) => {
|
||||||
return this._matches(query, user);
|
return this._matches(query, user);
|
||||||
|
}).map((user) => {
|
||||||
|
return user.userId;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If the query isn't a user we know about, but is a
|
||||||
|
// valid address, add an entry for that
|
||||||
|
if (queryList.length == 0) {
|
||||||
|
const addrType = Invite.getAddressType(query);
|
||||||
|
if (addrType !== null) {
|
||||||
|
queryList.push(query);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|
|
@ -25,6 +25,8 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
onSelected: React.PropTypes.func.isRequired,
|
onSelected: React.PropTypes.func.isRequired,
|
||||||
|
|
||||||
|
// List of strings: the addresses to display
|
||||||
addressList: React.PropTypes.array.isRequired,
|
addressList: React.PropTypes.array.isRequired,
|
||||||
truncateAt: React.PropTypes.number.isRequired,
|
truncateAt: React.PropTypes.number.isRequired,
|
||||||
selected: React.PropTypes.number,
|
selected: React.PropTypes.number,
|
||||||
|
@ -125,7 +127,7 @@ module.exports = React.createClass({
|
||||||
// method, how far to scroll when using the arrow keys
|
// method, how far to scroll when using the arrow keys
|
||||||
addressList.push(
|
addressList.push(
|
||||||
<div className={classes} onClick={this.onClick(i)} onMouseEnter={this.onMouseEnter(i)} onMouseLeave={this.onMouseLeave} key={i} ref={(ref) => { this.addressListElement = ref; }} >
|
<div className={classes} onClick={this.onClick(i)} onMouseEnter={this.onMouseEnter(i)} onMouseLeave={this.onMouseLeave} key={i} ref={(ref) => { this.addressListElement = ref; }} >
|
||||||
<AddressTile address={this.props.addressList[i].userId} justified={true} networkName="vector" networkUrl="img/search-icon-vector.svg" />
|
<AddressTile address={this.props.addressList[i]} justified={true} networkName="vector" networkUrl="img/search-icon-vector.svg" />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,8 @@ module.exports = React.createClass({
|
||||||
imgUrl = "img/avatar-error.svg";
|
imgUrl = "img/avatar-error.svg";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removing networks for now as they're not really supported
|
||||||
|
/*
|
||||||
var network;
|
var network;
|
||||||
if (this.props.networkUrl !== "") {
|
if (this.props.networkUrl !== "") {
|
||||||
network = (
|
network = (
|
||||||
|
@ -79,6 +81,7 @@ module.exports = React.createClass({
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
var info;
|
var info;
|
||||||
var error = false;
|
var error = false;
|
||||||
|
@ -145,7 +148,6 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes}>
|
<div className={classes}>
|
||||||
{ network }
|
|
||||||
<div className="mx_AddressTile_avatar">
|
<div className="mx_AddressTile_avatar">
|
||||||
<BaseAvatar width={25} height={25} name={name} title={name} url={imgUrl} />
|
<BaseAvatar width={25} height={25} name={name} title={name} url={imgUrl} />
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue