import React from 'react'; import { UserPicture } from '@growi/ui'; import dateFnsFormat from 'date-fns/format'; import { useTranslation } from 'next-i18next'; import PropTypes from 'prop-types'; import AdminUserGroupDetailContainer from '~/client/services/AdminUserGroupDetailContainer'; import { toastSuccess, toastError } from '~/client/util/apiNotification'; import Xss from '~/services/xss'; import { useSWRxMyUserGroupRelations } from '~/stores/user-group'; 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, userGroupRelations } = this.props; return ( {userGroupRelations != null && userGroupRelations.map((relation) => { const { relatedUser } = relation; 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 adminUserGroupDetailContainer: PropTypes.instanceOf(AdminUserGroupDetailContainer).isRequired, userGroupRelations: PropTypes.object, }; const UserGroupUserTableWrapperFC = (props) => { const { t } = useTranslation(); const { data: myUserGroupRelations } = useSWRxMyUserGroupRelations(); return ; }; /** * Wrapper component for using unstated */ const UserGroupUserTableWrapper = withUnstatedContainers(UserGroupUserTableWrapperFC, [AdminUserGroupDetailContainer]); export default UserGroupUserTableWrapper;