import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import PaginationWrapper from '../PaginationWrapper'; import { withUnstatedContainers } from '../UnstatedUtils'; import { toastError } from '~/client/util/apiNotification'; import AppContainer from '~/client/services/AppContainer'; import AdminUsersContainer from '~/client/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.state = { isNotifyCommentShow: false, }; 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 */ async handleClick(statusType) { const { adminUsersContainer } = this.props; if (!this.validateToggleStatus(statusType)) { return this.setState({ isNotifyCommentShow: true }); } if (this.state.isNotifyCommentShow) { await this.setState({ isNotifyCommentShow: false }); } 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; } /** * Reset button */ resetButtonClickHandler() { const { adminUsersContainer } = this.props; try { adminUsersContainer.resetAllChanges(); this.searchUserElement.value = ''; this.state.isNotifyCommentShow = false; } catch (err) { toastError(err); } } /** * Workaround increamental search * @param {string} event */ handleChangeSearchText(event) { this.props.adminUsersContainer.handleChangeSearchText(event.target.value); } renderCheckbox(status, statusLabel, statusColor) { return (