AccessTokenSettings.jsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { useTranslation } from 'react-i18next';
  4. import AppContainer from '../../../services/AppContainer';
  5. import { withUnstatedContainers } from '../../UnstatedUtils';
  6. import { toastSuccess } from '../../../util/apiNotification';
  7. const AccessTokenSettings = (props) => {
  8. const { t } = useTranslation('admin');
  9. const discardTokenHandler = () => {
  10. if (props.discardTokenHandler != null) {
  11. props.discardTokenHandler();
  12. }
  13. };
  14. const generateTokenHandler = () => {
  15. if (props.generateTokenHandler != null) {
  16. props.generateTokenHandler();
  17. }
  18. };
  19. const textboxClickHandler = (e) => {
  20. e.target.select();
  21. if (props.accessToken != null) {
  22. navigator.clipboard.writeText(props.accessToken)
  23. .then(() => { toastSuccess('slack_integration.copied_to_clipboard') });
  24. }
  25. };
  26. return (
  27. <div className="row">
  28. <div className="col-lg-12">
  29. <h2 className="admin-setting-header">Access Token</h2>
  30. <div className="form-group row my-5">
  31. <label className="text-left text-md-right col-md-3 col-form-label">Access Token</label>
  32. <div className="col-md-6">
  33. <input className="form-control" type="text" value={props.accessToken} onClick={e => textboxClickHandler(e)} readOnly />
  34. </div>
  35. </div>
  36. <div className="row">
  37. <div className="mx-auto">
  38. <button type="button" className="btn btn-outline-secondary text-nowrap mx-1" onClick={discardTokenHandler}>
  39. {t('slack_integration.access_token_settings.discard')}
  40. </button>
  41. <button type="button" className="btn btn-primary text-nowrap mx-1" onClick={generateTokenHandler}>
  42. {t('slack_integration.access_token_settings.generate')}
  43. </button>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. );
  49. };
  50. const AccessTokenSettingsWrapper = withUnstatedContainers(AccessTokenSettings, [AppContainer]);
  51. AccessTokenSettings.propTypes = {
  52. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  53. accessToken: PropTypes.string,
  54. discardTokenHandler: PropTypes.func,
  55. generateTokenHandler: PropTypes.func,
  56. };
  57. export default AccessTokenSettingsWrapper;