ExternalAccountLinkedMe.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import React, { Fragment } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import { createSubscribedElement } from '../UnstatedUtils';
  5. import { toastError } from '../../util/apiNotification';
  6. import AppContainer from '../../services/AppContainer';
  7. import PersonalContainer from '../../services/PersonalContainer';
  8. import ExternalAccountRow from './ExternalAccountRow';
  9. import AssociateModal from './AssociateModal';
  10. class ExternalAccountLinkedMe extends React.Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. isAssociatModalOpen: false,
  15. };
  16. this.openAssociatModal = this.openAssociatModal.bind(this);
  17. this.closeAssociatModal = this.closeAssociatModal.bind(this);
  18. }
  19. async componentDidMount() {
  20. try {
  21. await this.props.personalContainer.retrieveExternalAccounts();
  22. }
  23. catch (err) {
  24. toastError(err);
  25. }
  26. }
  27. openAssociatModal() {
  28. this.setState({ isAssociatModalOpen: true });
  29. }
  30. closeAssociatModal() {
  31. this.setState({ isAssociatModalOpen: false });
  32. }
  33. render() {
  34. const { t, personalContainer } = this.props;
  35. const { externalAccounts } = personalContainer.state;
  36. return (
  37. <Fragment>
  38. <div className="container-fluid">
  39. <h2 className="border-bottom">
  40. <button type="button" className="btn btn-default btn-sm pull-right" onClick={this.openAssociatModal}>
  41. <i className="icon-plus" aria-hidden="true" />
  42. Add
  43. </button>
  44. { t('External Accounts') }
  45. </h2>
  46. </div>
  47. <div className="row">
  48. <div className="col-md-12">
  49. <table className="table table-bordered table-user-list">
  50. <thead>
  51. <tr>
  52. <th width="120px">Authentication Provider</th>
  53. <th>
  54. <code>accountId</code>
  55. </th>
  56. <th width="200px">{ t('Created') }</th>
  57. <th width="150px">{ t('Admin') }</th>
  58. </tr>
  59. </thead>
  60. <tbody>
  61. {externalAccounts !== 0 && externalAccounts.map(account => <ExternalAccountRow account={account} key={account._id} />)}
  62. </tbody>
  63. </table>
  64. </div>
  65. </div>
  66. <AssociateModal
  67. isOpen={this.state.isAssociatModalOpen}
  68. onClose={this.closeAssociatModal}
  69. />
  70. </Fragment>
  71. );
  72. }
  73. }
  74. const ExternalAccountLinkedMeWrapper = (props) => {
  75. return createSubscribedElement(ExternalAccountLinkedMe, props, [AppContainer, PersonalContainer]);
  76. };
  77. ExternalAccountLinkedMe.propTypes = {
  78. t: PropTypes.func.isRequired, // i18next
  79. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  80. personalContainer: PropTypes.instanceOf(PersonalContainer).isRequired,
  81. };
  82. export default withTranslation()(ExternalAccountLinkedMeWrapper);