import React from 'react'; import { UserPicture } from '@growi/ui'; import dateFnsFormat from 'date-fns/format'; import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next'; import AdminUserGroupDetailContainer from '~/client/services/AdminUserGroupDetailContainer'; import AppContainer from '~/client/services/AppContainer'; import { toastSuccess, toastError } from '~/client/util/apiNotification'; import Xss from '~/services/xss'; import { withUnstatedContainers } from '../../UnstatedUtils'; class UserGroupUserTable extends React.Component { constructor(props) { super(props); this.xss = new Xss(); this.removeUser = this.removeUser.bind(this); } async removeUser(username) { try { await this.props.adminUserGroupDetailContainer.removeUserByUsername(username); toastSuccess(`Removed "${this.xss.process(username)}" from "${this.xss.process(this.props.adminUserGroupDetailContainer.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.adminUserGroupDetailContainer.state.userGroup.name)}"`)); } } render() { const { t, adminUserGroupDetailContainer } = this.props; return ( {adminUserGroupDetailContainer.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, adminUserGroupDetailContainer: PropTypes.instanceOf(AdminUserGroupDetailContainer).isRequired, }; const UserGroupUserTableWrapperFC = (props) => { const { t } = useTranslation(); return ; }; /** * Wrapper component for using unstated */ const UserGroupUserTableWrapper = withUnstatedContainers(UserGroupUserTableWrapperFC, [AppContainer, AdminUserGroupDetailContainer]); export default UserGroupUserTableWrapper;