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.removeExtenalAccount = this.removeExtenalAccount.bind(this); } // remove external-account async removeExtenalAccount(externalAccountId) { const { t } = this.props; try { const accountId = await this.props.adminExternalAccountsContainer.removeExternalAccountById(externalAccountId); toastSuccess(t('toaster:remove_external_user_success', { accountId })); } catch (err) { toastError(err); } } render() { const { t, adminExternalAccountsContainer } = this.props; return ( {adminExternalAccountsContainer.state.externalAccounts.map((ea) => { return ( ); })}
{t('user_management:authentication_provider')} accountId {t('user_management:related_username')}username {t('user_management:password_setting')}
{t('Created')}
{ea.providerType} {ea.accountId} {ea.user.username} {ea.user.password ? ( {t('user_management:set')} ) : ( {t('user_management:unset')} ) } {dateFnsFormat(new Date(ea.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);