|
|
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
|
|
|
import { withTranslation } from 'react-i18next';
|
|
|
import Modal from 'react-bootstrap/es/Modal';
|
|
|
|
|
|
+import UserGroupUserFormByInput from './UserGroupUserFormByInput';
|
|
|
import { createSubscribedElement } from '../../UnstatedUtils';
|
|
|
import AppContainer from '../../../services/AppContainer';
|
|
|
import { toastSuccess, toastError } from '../../../util/apiNotification';
|
|
|
@@ -12,29 +13,10 @@ class UserGroupUserModal extends React.Component {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
|
|
|
- this.state = {
|
|
|
- username: '',
|
|
|
- };
|
|
|
-
|
|
|
this.xss = window.xss;
|
|
|
|
|
|
- this.handleChange = this.handleChange.bind(this);
|
|
|
- this.addUserBySubmit = this.addUserBySubmit.bind(this);
|
|
|
this.addUserByClick = this.addUserByClick.bind(this);
|
|
|
- this.addUser = this.addUser.bind(this);
|
|
|
- }
|
|
|
-
|
|
|
- handleChange(e) {
|
|
|
- this.setState({ username: e.target.value });
|
|
|
- }
|
|
|
-
|
|
|
- async addUserBySubmit(e) {
|
|
|
- e.preventDefault();
|
|
|
-
|
|
|
- const { user, userGroup, userGroupRelation } = await this.addUser(this.state.username);
|
|
|
-
|
|
|
- this.setState({ username: '' });
|
|
|
- this.handlePostAdd(user, userGroup, userGroupRelation);
|
|
|
+ this.addUserByUsername = this.addUserByUsername.bind(this);
|
|
|
}
|
|
|
|
|
|
async addUserByClick(username) {
|
|
|
@@ -43,23 +25,17 @@ class UserGroupUserModal extends React.Component {
|
|
|
this.handlePostAdd(user, userGroup, userGroupRelation);
|
|
|
}
|
|
|
|
|
|
- async addUser(username) {
|
|
|
+ async addUserByUsername(username) {
|
|
|
try {
|
|
|
const res = await this.props.appContainer.apiv3.post(`/user-groups/${this.props.userGroup._id}/users/${username}`);
|
|
|
- toastSuccess(`Added "${username}" to "${this.xss.process(this.props.userGroup.name)}"`);
|
|
|
-
|
|
|
- return res.data;
|
|
|
+ const { user, userGroup, userGroupRelation } = res.data;
|
|
|
+ this.props.onAdd(user, userGroup, userGroupRelation);
|
|
|
}
|
|
|
catch (err) {
|
|
|
toastError(new Error(`Unable to add "${this.xss.process(username)}" to "${this.xss.process(this.props.userGroup.name)}"`));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- handlePostAdd(user, userGroup, userGroupRelation) {
|
|
|
- this.props.onAdd(user, userGroup, userGroupRelation);
|
|
|
- this.props.onClose();
|
|
|
- }
|
|
|
-
|
|
|
render() {
|
|
|
const { t } = this.props;
|
|
|
|
|
|
@@ -72,20 +48,11 @@ class UserGroupUserModal extends React.Component {
|
|
|
<p>
|
|
|
<strong>{ t('Method') }1.</strong> { t('user_group_management.how_to_add1') }
|
|
|
</p>
|
|
|
- <form className="form-inline" onSubmit={this.addUserBySubmit}>
|
|
|
- <div className="form-group">
|
|
|
- <input
|
|
|
- type="text"
|
|
|
- name="username"
|
|
|
- className="form-control input-sm"
|
|
|
- placeholder={t('User Name')}
|
|
|
- value={this.state.username}
|
|
|
- onChange={this.handleChange}
|
|
|
- />
|
|
|
- </div>
|
|
|
- <button type="submit" className="btn btn-sm btn-success">{ t('Add') }</button>
|
|
|
- </form>
|
|
|
-
|
|
|
+ <UserGroupUserFormByInput
|
|
|
+ addUserByUsername={this.addUserByUsername}
|
|
|
+ onAdd={this.props.onAdd}
|
|
|
+ onClose={this.props.onClose}
|
|
|
+ />
|
|
|
<hr />
|
|
|
<p>
|
|
|
<strong>{ t('Method') }2.</strong> { t('user_group_management.how_to_add2') }
|