import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import PaginationWrapper from '../PaginationWrapper'; import { createSubscribedElement } from '../UnstatedUtils'; import { toastError } from '../../util/apiNotification'; import AppContainer from '../../services/AppContainer'; import AdminUsersContainer from '../../services/AdminUsersContainer'; import PasswordResetModal from './Users/PasswordResetModal'; import InviteUserControl from './Users/InviteUserControl'; import UserTable from './Users/UserTable'; class UserManagement extends React.Component { constructor(props) { super(); this.handlePage = this.handlePage.bind(this); this.handleChangeSearchText = this.handleChangeSearchText.bind(this); } componentWillMount() { this.handlePage(1); } async handlePage(selectedPage) { try { await this.props.adminUsersContainer.retrieveUsersByPagingNum(selectedPage); } catch (err) { toastError(err); } } /** * For checking same check box twice * @param {string} statusType */ handleClick(statusType) { const { adminUsersContainer } = this.props; if (!this.validateToggleStatus(statusType)) { adminUsersContainer.setNotifyComment('You should check at least one checkbox.'); return; } if (adminUsersContainer.state.notifyComment.length > 0) { adminUsersContainer.setNotifyComment(''); } adminUsersContainer.handleClick(statusType); } /** * Workaround user status check box * @param {string} statusType */ validateToggleStatus(statusType) { if (this.props.adminUsersContainer.isSelected(statusType)) { return this.props.adminUsersContainer.state.selectedStatusList.size > 1; } return true; } /** * Workaround increamental search * @param {string} event */ handleChangeSearchText(event) { this.props.adminUsersContainer.handleChangeSearchText(event.target.value); } render() { const { t, adminUsersContainer } = this.props; const pager = (
); const notifyComment = (adminUsersContainer.state.notifyComment && { adminUsersContainer.state.notifyComment }); const clearButton = ( adminUsersContainer.state.searchText.length > 0 ? ( { adminUsersContainer.clearSearchText(); this.searchUserElement.value = ''; }} /> ) : '' ); return ( {adminUsersContainer.state.userForPasswordResetModal && }

{t('admin:user_management.external_account')}

{t('User_Management')}

{ this.searchUserElement = searchUserElement }} onChange={this.handleChangeSearchText} /> { clearButton }
{ this.handleClick('all') }} /> { this.handleClick('registered') }} /> { this.handleClick('active') }} /> { this.handleClick('suspended') }} /> { this.handleClick('invited') }} />
{ notifyComment }
{pager} {pager}
); } } UserManagement.propTypes = { t: PropTypes.func.isRequired, // i18next appContainer: PropTypes.instanceOf(AppContainer).isRequired, adminUsersContainer: PropTypes.instanceOf(AdminUsersContainer).isRequired, }; const UserManagementWrapper = (props) => { return createSubscribedElement(UserManagement, props, [AppContainer, AdminUsersContainer]); }; export default withTranslation()(UserManagementWrapper);