DisassociateModal.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import {
  5. Modal,
  6. ModalHeader,
  7. ModalBody,
  8. ModalFooter,
  9. } from 'reactstrap';
  10. import { toastSuccess, toastError } from '../../util/apiNotification';
  11. import { createSubscribedElement } from '../UnstatedUtils';
  12. import AppContainer from '../../services/AppContainer';
  13. import PersonalContainer from '../../services/PersonalContainer';
  14. class DisassociateModal extends React.Component {
  15. constructor(props) {
  16. super(props);
  17. this.onClickDisassociateBtn = this.onClickDisassociateBtn.bind(this);
  18. }
  19. async onClickDisassociateBtn() {
  20. const { t, personalContainer } = this.props;
  21. const { providerType, accountId } = this.props.accountForDisassociate;
  22. try {
  23. await personalContainer.disassociateLdapAccount({ providerType, accountId });
  24. this.props.onClose();
  25. toastSuccess(t('security_setting.updated_general_security_setting'));
  26. }
  27. catch (err) {
  28. toastError(err);
  29. }
  30. try {
  31. await personalContainer.retrieveExternalAccounts();
  32. }
  33. catch (err) {
  34. toastError(err);
  35. }
  36. }
  37. render() {
  38. const { t, accountForDisassociate } = this.props;
  39. const { providerType, accountId } = accountForDisassociate;
  40. return (
  41. <Modal isOpen={this.props.isOpen} toggle={this.props.onClose}>
  42. <ModalHeader className="bg-info" toggle={this.props.onClose}>
  43. {t('personal_settings.disassociate_external_account')}
  44. </ModalHeader>
  45. <ModalBody>
  46. {/* eslint-disable-next-line react/no-danger */}
  47. <p dangerouslySetInnerHTML={{ __html: t('personal_settings.disassociate_external_account_desc', { providerType, accountId }) }} />
  48. </ModalBody>
  49. <ModalFooter>
  50. <button type="button" className="btn btn-sm btn-outline-secondary" onClick={this.props.onClose}>
  51. { t('Cancel') }
  52. </button>
  53. <button type="button" className="btn btn-sm btn-danger" onClick={this.onClickDisassociateBtn}>
  54. <i className="ti-unlink"></i>
  55. { t('Disassociate') }
  56. </button>
  57. </ModalFooter>
  58. </Modal>
  59. );
  60. }
  61. }
  62. const DisassociateModalWrapper = (props) => {
  63. return createSubscribedElement(DisassociateModal, props, [AppContainer, PersonalContainer]);
  64. };
  65. DisassociateModal.propTypes = {
  66. t: PropTypes.func.isRequired, // i18next
  67. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  68. personalContainer: PropTypes.instanceOf(PersonalContainer).isRequired,
  69. isOpen: PropTypes.bool.isRequired,
  70. onClose: PropTypes.func.isRequired,
  71. accountForDisassociate: PropTypes.object.isRequired,
  72. };
  73. export default withTranslation()(DisassociateModalWrapper);