import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import dateFnsFormat from 'date-fns/format'; import { createSubscribedElement } from '../../UnstatedUtils'; import AppContainer from '../../../services/AppContainer'; import AdminExternalAccountsContainer from '../../../services/AdminExternalAccountsContainer'; import { toastSuccess, toastError } from '../../../util/apiNotification'; class ExternalAccountTable extends React.Component { constructor(props) { super(props); this.state = { }; this.getUserStatusLabel = this.getUserStatusLabel.bind(this); this.removeExtenalAccount = this.removeExtenalAccount.bind(this); } // remove external-account async removeExtenalAccount(externalAccountId) { try { await this.props.adminExternalAccountsContainer.removeExternal(externalAccountId); toastSuccess(`Removed "${this.xss.process(externalAccountId)}"`); } catch (err) { toastError(new Error(`Unable to remove "${this.xss.process(externalAccountId)}"`)); } } /** * 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, adminExternalAccountsContainer } = this.props; return ( {adminExternalAccountsContainer.state.exteranalAccounts.map((ea) => { const { externalAccount } = ea; return ( ); })}
{ t('user_management.authentication_provider') } accountId { t('user_management.related_username', 'username') } { t('user_management.password_setting') }
{ t('Created') }
{externalAccount.providerType} {externalAccount.accountId} {externalAccount.user.username} { externalAccount.password ? ( { t('user_management.set') } ) : ( { t('user_management.unset') } ) } {dateFnsFormat(new Date(externalAccount.createdAt), 'yyyy-MM-dd')}
); } } ExternalAccountTable.propTypes = { t: PropTypes.func.isRequired, // i18next appContainer: PropTypes.instanceOf(AppContainer).isRequired, adminExternalAccountsContainer: PropTypes.instanceOf(AdminExternalAccountsContainer).isRequired, }; const ExternalAccountTableWrapper = (props) => { return createSubscribedElement(ExternalAccountTable, props, [AppContainer, AdminExternalAccountsContainer]); }; export default withTranslation()(ExternalAccountTableWrapper);