AccessTokenSettings.jsx 1.9 KB

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