import React, { useState, useEffect, useCallback } from 'react';
import PropTypes from 'prop-types';
import AppContainer from '../../../services/AppContainer';
import { withUnstatedContainers } from '../../UnstatedUtils';
import { toastError } from '../../../util/apiNotification';
import AccessTokenSettings from './AccessTokenSettings';
import OfficialBotSettings from './OfficialBotSettings';
import CustomBotWithoutProxySettings from './CustomBotWithoutProxySettings';
import CustomBotWithProxySettings from './CustomBotWithProxySettings';
import ConfirmBotChangeModal from './ConfirmBotChangeModal';
const SlackIntegration = (props) => {
const { appContainer } = props;
const [currentBotType, setCurrentBotType] = useState(null);
const [selectedBotType, setSelectedBotType] = useState(null);
const fetchData = useCallback(async() => {
try {
const response = await appContainer.apiv3.get('slack-integration/');
setCurrentBotType(response.currentBotType);
}
catch (err) {
toastError(err);
}
}, [appContainer]);
useEffect(() => {
fetchData();
}, [fetchData]);
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;
}
if (currentBotType === null) {
setCurrentBotType(clickedBotType);
return;
}
setSelectedBotType(clickedBotType);
};
const handleCancelBotChange = () => {
setSelectedBotType(null);
};
const changeCurrentBotSettings = () => {
resetBotType();
setCurrentBotType(selectedBotType);
setSelectedBotType(null);
};
let settingsComponent = null;
switch (currentBotType) {
case 'official-bot':
settingsComponent =
This is a wider card with supporting text below as a natural lead-in to additional content.
This is a wider card with supporting text below as a natural lead-in to additional content.
This is a wider card with supporting text below as a natural lead-in to additional content.