|
@@ -1,12 +1,12 @@
|
|
|
-import React, { Fragment } from 'react';
|
|
|
|
|
|
|
+import React from 'react';
|
|
|
import PropTypes from 'prop-types';
|
|
import PropTypes from 'prop-types';
|
|
|
import { withTranslation } from 'react-i18next';
|
|
import { withTranslation } from 'react-i18next';
|
|
|
import dateFnsFormat from 'date-fns/format';
|
|
import dateFnsFormat from 'date-fns/format';
|
|
|
|
|
|
|
|
-import UserGroupUserModal from './UserGroupUserModal';
|
|
|
|
|
import UserPicture from '../../User/UserPicture';
|
|
import UserPicture from '../../User/UserPicture';
|
|
|
import { createSubscribedElement } from '../../UnstatedUtils';
|
|
import { createSubscribedElement } from '../../UnstatedUtils';
|
|
|
import AppContainer from '../../../services/AppContainer';
|
|
import AppContainer from '../../../services/AppContainer';
|
|
|
|
|
+import UserGroupDetailContainer from '../../../services/UserGroupDetailContainer';
|
|
|
import { toastSuccess, toastError } from '../../../util/apiNotification';
|
|
import { toastSuccess, toastError } from '../../../util/apiNotification';
|
|
|
|
|
|
|
|
class UserGroupUserTable extends React.Component {
|
|
class UserGroupUserTable extends React.Component {
|
|
@@ -14,77 +14,41 @@ class UserGroupUserTable extends React.Component {
|
|
|
constructor(props) {
|
|
constructor(props) {
|
|
|
super(props);
|
|
super(props);
|
|
|
|
|
|
|
|
- this.state = {
|
|
|
|
|
- userGroupRelations: props.userGroupRelations,
|
|
|
|
|
- notRelatedUsers: props.notRelatedUsers,
|
|
|
|
|
- isUserGroupUserModalOpen: false,
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
this.xss = window.xss;
|
|
this.xss = window.xss;
|
|
|
|
|
|
|
|
this.removeUser = this.removeUser.bind(this);
|
|
this.removeUser = this.removeUser.bind(this);
|
|
|
- this.openUserGroupUserModal = this.openUserGroupUserModal.bind(this);
|
|
|
|
|
- this.closeUserGroupUserModal = this.closeUserGroupUserModal.bind(this);
|
|
|
|
|
- this.addUser = this.addUser.bind(this);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async removeUser(username) {
|
|
async removeUser(username) {
|
|
|
try {
|
|
try {
|
|
|
- const res = await this.props.appContainer.apiv3.delete(`/user-groups/${this.props.userGroup._id}/users/${username}`);
|
|
|
|
|
-
|
|
|
|
|
- this.setState((prevState) => {
|
|
|
|
|
- return {
|
|
|
|
|
- userGroupRelations: prevState.userGroupRelations.filter((u) => { return u._id !== res.data.userGroupRelation._id }),
|
|
|
|
|
- notRelatedUsers: [...prevState.notRelatedUsers, res.data.user],
|
|
|
|
|
- };
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- toastSuccess(`Removed "${username}" from "${this.xss.process(this.props.userGroup.name)}"`);
|
|
|
|
|
|
|
+ await this.props.userGroupDetailContainer.removeUserByUsername(username);
|
|
|
|
|
+ toastSuccess(`Removed "${this.xss.process(username)}" from "${this.xss.process(this.props.userGroupDetailContainer.state.userGroup.name)}"`);
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
- toastError(new Error(`Unable to remove "${this.xss.process(username)}" from "${this.xss.process(this.props.userGroup.name)}"`));
|
|
|
|
|
|
|
+ // eslint-disable-next-line max-len
|
|
|
|
|
+ toastError(new Error(`Unable to remove "${this.xss.process(username)}" from "${this.xss.process(this.props.userGroupDetailContainer.state.userGroup.name)}"`));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- openUserGroupUserModal() {
|
|
|
|
|
- this.setState({ isUserGroupUserModalOpen: true });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- closeUserGroupUserModal() {
|
|
|
|
|
- this.setState({ isUserGroupUserModalOpen: false });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- addUser(user, userGroup, userGroupRelation) {
|
|
|
|
|
- this.setState((prevState) => {
|
|
|
|
|
- return {
|
|
|
|
|
- userGroupRelations: [...prevState.userGroupRelations, userGroupRelation],
|
|
|
|
|
- notRelatedUsers: prevState.notRelatedUsers.filter((u) => { return u._id !== user._id }),
|
|
|
|
|
- };
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
render() {
|
|
render() {
|
|
|
- const { t } = this.props;
|
|
|
|
|
|
|
+ const { t, userGroupDetailContainer } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <Fragment>
|
|
|
|
|
- <legend className="m-t-20">{ t('User List') }</legend>
|
|
|
|
|
-
|
|
|
|
|
- <table className="table table-bordered table-user-list">
|
|
|
|
|
- <thead>
|
|
|
|
|
- <tr>
|
|
|
|
|
- <th width="100px">#</th>
|
|
|
|
|
- <th>
|
|
|
|
|
- { t('User') }
|
|
|
|
|
- </th>
|
|
|
|
|
- <th>{ t('Name') }</th>
|
|
|
|
|
- <th width="100px">{ t('Created') }</th>
|
|
|
|
|
- <th width="160px">{ t('Last Login')}</th>
|
|
|
|
|
- <th width="70px"></th>
|
|
|
|
|
- </tr>
|
|
|
|
|
- </thead>
|
|
|
|
|
- <tbody>
|
|
|
|
|
- {this.state.userGroupRelations.map((sRelation) => {
|
|
|
|
|
|
|
+ <table className="table table-bordered table-user-list">
|
|
|
|
|
+ <thead>
|
|
|
|
|
+ <tr>
|
|
|
|
|
+ <th width="100px">#</th>
|
|
|
|
|
+ <th>
|
|
|
|
|
+ { t('User') }
|
|
|
|
|
+ </th>
|
|
|
|
|
+ <th>{ t('Name') }</th>
|
|
|
|
|
+ <th width="100px">{ t('Created') }</th>
|
|
|
|
|
+ <th width="160px">{ t('Last Login')}</th>
|
|
|
|
|
+ <th width="70px"></th>
|
|
|
|
|
+ </tr>
|
|
|
|
|
+ </thead>
|
|
|
|
|
+ <tbody>
|
|
|
|
|
+ {userGroupDetailContainer.state.userGroupRelations.map((sRelation) => {
|
|
|
const { relatedUser } = sRelation;
|
|
const { relatedUser } = sRelation;
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
@@ -96,8 +60,8 @@ class UserGroupUserTable extends React.Component {
|
|
|
<strong>{relatedUser.username}</strong>
|
|
<strong>{relatedUser.username}</strong>
|
|
|
</td>
|
|
</td>
|
|
|
<td>{relatedUser.name}</td>
|
|
<td>{relatedUser.name}</td>
|
|
|
- <td>{relatedUser.createdAt ? dateFnsFormat(new Date(relatedUser.createdAt), 'yyyy-MM-dd') : ''}</td>
|
|
|
|
|
- <td>{relatedUser.lastLoginAt ? dateFnsFormat(new Date(relatedUser.lastLoginAt), 'yyyy-MM-dd HH:mm:ss') : ''}</td>
|
|
|
|
|
|
|
+ <td>{relatedUser.createdAt ? dateFnsFormat(new Date(relatedUser.createdAt), 'YYYY-MM-DD') : ''}</td>
|
|
|
|
|
+ <td>{relatedUser.lastLoginAt ? dateFnsFormat(new Date(relatedUser.lastLoginAt), 'YYYY-MM-DD HH:mm:ss') : ''}</td>
|
|
|
<td>
|
|
<td>
|
|
|
<div className="btn-group admin-user-menu">
|
|
<div className="btn-group admin-user-menu">
|
|
|
<button type="button" className="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
|
|
<button type="button" className="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
|
|
@@ -116,31 +80,21 @@ class UserGroupUserTable extends React.Component {
|
|
|
);
|
|
);
|
|
|
})}
|
|
})}
|
|
|
|
|
|
|
|
- <tr>
|
|
|
|
|
- <td></td>
|
|
|
|
|
- <td className="text-center">
|
|
|
|
|
- <button className="btn btn-default" type="button" onClick={this.openUserGroupUserModal}>
|
|
|
|
|
- <i className="ti-plus"></i>
|
|
|
|
|
- </button>
|
|
|
|
|
- </td>
|
|
|
|
|
- <td></td>
|
|
|
|
|
- <td></td>
|
|
|
|
|
- <td></td>
|
|
|
|
|
- <td></td>
|
|
|
|
|
- </tr>
|
|
|
|
|
-
|
|
|
|
|
- </tbody>
|
|
|
|
|
- </table>
|
|
|
|
|
-
|
|
|
|
|
- <UserGroupUserModal
|
|
|
|
|
- show={this.state.isUserGroupUserModalOpen}
|
|
|
|
|
- onClose={this.closeUserGroupUserModal}
|
|
|
|
|
- onAdd={this.addUser}
|
|
|
|
|
- notRelatedUsers={this.state.notRelatedUsers}
|
|
|
|
|
- userGroup={this.props.userGroup}
|
|
|
|
|
- />
|
|
|
|
|
-
|
|
|
|
|
- </Fragment>
|
|
|
|
|
|
|
+ <tr>
|
|
|
|
|
+ <td></td>
|
|
|
|
|
+ <td className="text-center">
|
|
|
|
|
+ <button className="btn btn-default" type="button" onClick={userGroupDetailContainer.openUserGroupUserModal}>
|
|
|
|
|
+ <i className="ti-plus"></i>
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </td>
|
|
|
|
|
+ <td></td>
|
|
|
|
|
+ <td></td>
|
|
|
|
|
+ <td></td>
|
|
|
|
|
+ <td></td>
|
|
|
|
|
+ </tr>
|
|
|
|
|
+
|
|
|
|
|
+ </tbody>
|
|
|
|
|
+ </table>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -149,16 +103,14 @@ class UserGroupUserTable extends React.Component {
|
|
|
UserGroupUserTable.propTypes = {
|
|
UserGroupUserTable.propTypes = {
|
|
|
t: PropTypes.func.isRequired, // i18next
|
|
t: PropTypes.func.isRequired, // i18next
|
|
|
appContainer: PropTypes.instanceOf(AppContainer).isRequired,
|
|
appContainer: PropTypes.instanceOf(AppContainer).isRequired,
|
|
|
- userGroupRelations: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
|
|
|
- notRelatedUsers: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
|
|
|
- userGroup: PropTypes.object.isRequired,
|
|
|
|
|
|
|
+ userGroupDetailContainer: PropTypes.instanceOf(UserGroupDetailContainer).isRequired,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Wrapper component for using unstated
|
|
* Wrapper component for using unstated
|
|
|
*/
|
|
*/
|
|
|
const UserGroupUserTableWrapper = (props) => {
|
|
const UserGroupUserTableWrapper = (props) => {
|
|
|
- return createSubscribedElement(UserGroupUserTable, props, [AppContainer]);
|
|
|
|
|
|
|
+ return createSubscribedElement(UserGroupUserTable, props, [AppContainer, UserGroupDetailContainer]);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export default withTranslation()(UserGroupUserTableWrapper);
|
|
export default withTranslation()(UserGroupUserTableWrapper);
|