2015-07-14 18:53:49 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2019-12-20 03:45:24 +03:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2015-07-14 18:53:49 +03: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.
|
|
|
|
*/
|
|
|
|
|
2019-12-08 15:16:17 +03:00
|
|
|
import React, {createRef} from 'react';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2019-09-06 20:35:52 +03:00
|
|
|
import createReactClass from 'create-react-class';
|
2017-05-30 17:09:57 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2015-07-14 18:53:49 +03:00
|
|
|
|
2019-12-20 03:45:24 +03:00
|
|
|
export default createReactClass({
|
2015-11-26 20:37:40 +03:00
|
|
|
displayName: 'UserSelector',
|
|
|
|
|
2015-07-14 18:53:49 +03:00
|
|
|
propTypes: {
|
2017-12-26 04:03:18 +03:00
|
|
|
onChange: PropTypes.func,
|
2019-07-31 14:19:29 +03:00
|
|
|
selected_users: PropTypes.arrayOf(PropTypes.string),
|
2015-07-14 18:53:49 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
2015-09-21 18:17:29 +03:00
|
|
|
onChange: function() {},
|
|
|
|
selected: [],
|
2015-07-14 18:53:49 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2020-03-31 23:12:52 +03:00
|
|
|
// TODO: [REACT-WARNING] Replace component with real class, use constructor for refs
|
2019-12-08 15:16:17 +03:00
|
|
|
UNSAFE_componentWillMount: function() {
|
|
|
|
this._user_id_input = createRef();
|
|
|
|
},
|
|
|
|
|
2015-07-14 18:53:49 +03:00
|
|
|
addUser: function(user_id) {
|
2015-09-21 18:17:29 +03:00
|
|
|
if (this.props.selected_users.indexOf(user_id == -1)) {
|
|
|
|
this.props.onChange(this.props.selected_users.concat([user_id]));
|
2015-07-14 18:53:49 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
removeUser: function(user_id) {
|
2015-09-21 18:17:29 +03:00
|
|
|
this.props.onChange(this.props.selected_users.filter(function(e) {
|
|
|
|
return e != user_id;
|
|
|
|
}));
|
2015-07-14 18:53:49 +03:00
|
|
|
},
|
2015-11-26 20:37:40 +03:00
|
|
|
|
|
|
|
onAddUserId: function() {
|
2019-12-08 15:16:17 +03:00
|
|
|
this.addUser(this._user_id_input.current.value);
|
|
|
|
this._user_id_input.current.value = "";
|
2015-11-26 20:37:40 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2017-10-11 19:56:17 +03:00
|
|
|
const self = this;
|
2015-11-26 20:37:40 +03:00
|
|
|
return (
|
|
|
|
<div>
|
2019-12-08 15:16:17 +03:00
|
|
|
<ul className="mx_UserSelector_UserIdList">
|
2017-10-11 19:56:17 +03:00
|
|
|
{ this.props.selected_users.map(function(user_id, i) {
|
|
|
|
return <li key={user_id}>{ user_id } - <span onClick={function() {self.removeUser(user_id);}}>X</span></li>;
|
|
|
|
}) }
|
2015-11-26 20:37:40 +03:00
|
|
|
</ul>
|
2019-12-08 15:16:17 +03:00
|
|
|
<input type="text" ref={this._user_id_input} defaultValue="" className="mx_UserSelector_userIdInput" placeholder={_t("ex. @bob:example.com")} />
|
2015-11-26 20:37:40 +03:00
|
|
|
<button onClick={this.onAddUserId} className="mx_UserSelector_AddUserId">
|
2017-10-11 19:56:17 +03:00
|
|
|
{ _t("Add User") }
|
2015-11-26 20:37:40 +03:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
);
|
2017-10-11 19:56:17 +03:00
|
|
|
},
|
2015-11-26 20:37:40 +03:00
|
|
|
});
|