import React from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import dateFnsFormat from 'date-fns/format'; import UserPicture from '../../User/UserPicture'; import { createSubscribedElement } from '../../UnstatedUtils'; import AppContainer from '../../../services/AppContainer'; import UserGroupDetailContainer from '../../../services/UserGroupDetailContainer'; import { toastSuccess, toastError } from '../../../util/apiNotification'; class UserGroupUserTable extends React.Component { constructor(props) { super(props); this.xss = window.xss; this.removeUser = this.removeUser.bind(this); } async removeUser(username) { try { await this.props.userGroupDetailContainer.removeUserByUsername(username); toastSuccess(`Removed "${this.xss.process(username)}" from "${this.xss.process(this.props.userGroupDetailContainer.state.userGroup.name)}"`); } catch (err) { // 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)}"`)); } } render() { const { t, userGroupDetailContainer } = this.props; return ( {userGroupDetailContainer.state.userGroupRelations.map((sRelation) => { const { relatedUser } = sRelation; return ( ); })}
# {t('username')} {t('Name')} {t('Created')} {t('Last_Login')}
{relatedUser.username} {relatedUser.name} {relatedUser.createdAt ? dateFnsFormat(new Date(relatedUser.createdAt), 'yyyy-MM-dd') : ''} {relatedUser.lastLoginAt ? dateFnsFormat(new Date(relatedUser.lastLoginAt), 'yyyy-MM-dd HH:mm:ss') : ''}
); } } UserGroupUserTable.propTypes = { t: PropTypes.func.isRequired, // i18next appContainer: PropTypes.instanceOf(AppContainer).isRequired, userGroupDetailContainer: PropTypes.instanceOf(UserGroupDetailContainer).isRequired, }; /** * Wrapper component for using unstated */ const UserGroupUserTableWrapper = (props) => { return createSubscribedElement(UserGroupUserTable, props, [AppContainer, UserGroupDetailContainer]); }; export default withTranslation()(UserGroupUserTableWrapper);