import React from 'react'; import { useTranslation } from 'next-i18next'; import PropTypes from 'prop-types'; import AdminSlackIntegrationLegacyContainer from '~/client/services/AdminSlackIntegrationLegacyContainer'; import { toastSuccess, toastError } from '~/client/util/toastr'; import loggerFactory from '~/utils/logger'; import { withUnstatedContainers } from '../../UnstatedUtils'; import AdminUpdateButtonRow from '../Common/AdminUpdateButtonRow'; const logger = loggerFactory('growi:slackAppConfiguration'); class SlackConfiguration extends React.Component { constructor(props) { super(props); this.onClickSubmit = this.onClickSubmit.bind(this); } async onClickSubmit() { const { t, adminSlackIntegrationLegacyContainer } = this.props; try { await adminSlackIntegrationLegacyContainer.updateSlackAppConfiguration(); toastSuccess(t('notification_settings.updated_slackApp')); } catch (err) { toastError(err); logger.error(err); } } render() { const { t, adminSlackIntegrationLegacyContainer } = this.props; return ( {`Slack ${adminSlackIntegrationLegacyContainer.state.selectSlackOption}`} adminSlackIntegrationLegacyContainer.switchSlackOption('Incoming Webhooks')}> Slack Incoming Webhooks adminSlackIntegrationLegacyContainer.switchSlackOption('App')}>Slack App {adminSlackIntegrationLegacyContainer.state.selectSlackOption === 'Incoming Webhooks' ? ( {t('notification_settings.slack_incoming_configuration')} Webhook URL adminSlackIntegrationLegacyContainer.changeWebhookUrl(e.target.value)} /> { adminSlackIntegrationLegacyContainer.switchIsIncomingWebhookPrioritized() }} /> {t('notification_settings.prioritize_webhook')} {t('notification_settings.prioritize_webhook_desc')} ) : ( {t('notification_settings.slack_app_configuration')} NOT RECOMMENDED {/* eslint-disable-next-line react/no-danger */} adminSlackIntegrationLegacyContainer.switchSlackOption('Incoming Webhooks')} > {t('notification_settings.use_instead')} OAuth access token adminSlackIntegrationLegacyContainer.changeSlackToken(e.target.value)} /> ) } {' '} {t('notification_settings.how_to.header')} {t('notification_settings.how_to.workspace')} {/* eslint-disable-next-line react/no-danger */} {t('notification_settings.how_to.workspace_desc2')} {t('notification_settings.how_to.workspace_desc3')} {t('notification_settings.how_to.at_growi')} {/* eslint-disable-next-line react/no-danger */} ); } } SlackConfiguration.propTypes = { t: PropTypes.func.isRequired, // i18next adminSlackIntegrationLegacyContainer: PropTypes.instanceOf(AdminSlackIntegrationLegacyContainer).isRequired, }; const SlackConfigurationWrapperFc = (props) => { const { t } = useTranslation('admin'); return ; }; const SlackConfigurationWrapper = withUnstatedContainers(SlackConfigurationWrapperFc, [AdminSlackIntegrationLegacyContainer]); export default SlackConfigurationWrapper;
{t('notification_settings.prioritize_webhook_desc')}