|
|
@@ -1,8 +1,9 @@
|
|
|
import React, { useState } from 'react';
|
|
|
import PropTypes from 'prop-types';
|
|
|
+import { useTranslation } from 'react-i18next';
|
|
|
import AppContainer from '../../../services/AppContainer';
|
|
|
import { withUnstatedContainers } from '../../UnstatedUtils';
|
|
|
-import { toastError } from '../../../util/apiNotification';
|
|
|
+import { toastSuccess, toastError } from '../../../util/apiNotification';
|
|
|
import AccessTokenSettings from './AccessTokenSettings';
|
|
|
import OfficialBotSettings from './OfficialBotSettings';
|
|
|
import CustomBotWithoutProxySettings from './CustomBotWithoutProxySettings';
|
|
|
@@ -11,23 +12,10 @@ import ConfirmBotChangeModal from './ConfirmBotChangeModal';
|
|
|
|
|
|
const SlackIntegration = (props) => {
|
|
|
const { appContainer } = props;
|
|
|
-
|
|
|
+ const { t } = useTranslation();
|
|
|
const [currentBotType, setCurrentBotType] = useState(null);
|
|
|
const [selectedBotType, setSelectedBotType] = useState(null);
|
|
|
|
|
|
- const resetBotType = async() => {
|
|
|
- try {
|
|
|
- await appContainer.apiv3.put('slack-integration/custom-bot-without-proxy', {
|
|
|
- slackSigningSecret: '',
|
|
|
- slackBotToken: '',
|
|
|
- botType: '',
|
|
|
- });
|
|
|
- }
|
|
|
- catch (err) {
|
|
|
- toastError(err);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
const handleBotTypeSelect = (clickedBotType) => {
|
|
|
if (clickedBotType === currentBotType) {
|
|
|
return;
|
|
|
@@ -43,10 +31,20 @@ const SlackIntegration = (props) => {
|
|
|
setSelectedBotType(null);
|
|
|
};
|
|
|
|
|
|
- const changeCurrentBotSettings = () => {
|
|
|
- resetBotType();
|
|
|
- setCurrentBotType(selectedBotType);
|
|
|
- setSelectedBotType(null);
|
|
|
+ const handleChangeCurrentBotSettings = async() => {
|
|
|
+ try {
|
|
|
+ await appContainer.apiv3.put('slack-integration/custom-bot-without-proxy', {
|
|
|
+ slackSigningSecret: '',
|
|
|
+ slackBotToken: '',
|
|
|
+ botType: '',
|
|
|
+ });
|
|
|
+ setCurrentBotType(selectedBotType);
|
|
|
+ setSelectedBotType(null);
|
|
|
+ toastSuccess(t('toaster.update_successed'), { target: t('admin:slack_integration.bot_reset_successful') });
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ toastError(err);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
let settingsComponent = null;
|
|
|
@@ -68,7 +66,7 @@ const SlackIntegration = (props) => {
|
|
|
<div className="container">
|
|
|
<ConfirmBotChangeModal
|
|
|
isOpen={selectedBotType != null}
|
|
|
- onConfirmClick={changeCurrentBotSettings}
|
|
|
+ onConfirmClick={handleChangeCurrentBotSettings}
|
|
|
onCancelClick={handleCancelBotChange}
|
|
|
/>
|
|
|
</div>
|