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 = ; break; case 'custom-bot-without-proxy': settingsComponent = ; break; case 'custom-bot-with-proxy': settingsComponent = ; break; } return ( <>

Access Token

handleBotTypeSelect('official-bot')} style={{ cursor: 'pointer' }} >
Official Bot

This is a wider card with supporting text below as a natural lead-in to additional content.

handleBotTypeSelect('custom-bot-without-proxy')} style={{ cursor: 'pointer' }} >
Custom Bot (Without Proxy)

This is a wider card with supporting text below as a natural lead-in to additional content.

handleBotTypeSelect('custom-bot-with-proxy')} style={{ cursor: 'pointer' }} >
Custom Bot (With Proxy)

This is a wider card with supporting text below as a natural lead-in to additional content.

{settingsComponent} ); }; const SlackIntegrationWrapper = withUnstatedContainers(SlackIntegration, [AppContainer]); SlackIntegration.propTypes = { appContainer: PropTypes.instanceOf(AppContainer).isRequired, }; export default SlackIntegrationWrapper;