import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import dateFnsFormat from 'date-fns/format'; import UserPicture from '../../User/UserPicture'; import UserMenu from './UserMenu'; import { createSubscribedElement } from '../../UnstatedUtils'; import AppContainer from '../../../services/AppContainer'; import AdminUsersContainer from '../../../services/AdminUsersContainer'; class UserTable extends React.Component { constructor(props) { super(props); this.state = { }; this.getUserStatusLabel = this.getUserStatusLabel.bind(this); } /** * user.statusをみてステータスのラベルを返す * @param {string} userStatus * @return ステータスラベル */ getUserStatusLabel(userStatus) { let additionalClassName; let text; switch (userStatus) { case 1: additionalClassName = 'label-info'; text = 'Approval Pending'; break; case 2: additionalClassName = 'label-success'; text = 'Active'; break; case 3: additionalClassName = 'label-warning'; text = 'Suspended'; break; case 4: additionalClassName = 'label-danger'; text = 'Deleted'; break; case 5: additionalClassName = 'label-info'; text = 'Invited'; break; } return ( {text} ); } render() { const { t, adminUsersContainer } = this.props; return ( {adminUsersContainer.state.users.map((user) => { return ( ); })}
# { t('status') } username { t('Name') } { t('Email') } { t('Created') } { t('Last_Login') }
{user.admin && { t('administrator') }} {this.getUserStatusLabel(user.status)} {user.username} {user.name} {user.email} {dateFnsFormat(new Date(user.createdAt), 'yyyy-MM-dd')} { user.lastLoginAt && {dateFnsFormat(new Date(user.lastLoginAt), 'yyyy-MM-dd HH:mm')} }
); } } const UserTableWrapper = (props) => { return createSubscribedElement(UserTable, props, [AppContainer, AdminUsersContainer]); }; UserTable.propTypes = { t: PropTypes.func.isRequired, // i18next appContainer: PropTypes.instanceOf(AppContainer).isRequired, adminUsersContainer: PropTypes.instanceOf(AdminUsersContainer).isRequired, }; export default withTranslation()(UserTableWrapper);