import React, { useState, useEffect } from 'react'; import { useTranslation } from 'next-i18next'; import PropTypes from 'prop-types'; import { apiv3Put } from '~/client/util/apiv3-client'; import { toastSuccess, toastError } from '~/client/util/toastr'; import { withUnstatedContainers } from '../../UnstatedUtils'; import AdminUpdateButtonRow from '../Common/AdminUpdateButtonRow'; const CustomBotWithoutProxySecretTokenSection = (props) => { const { slackSigningSecret, slackBotToken, slackSigningSecretEnv, slackBotTokenEnv, onUpdatedSecretToken, } = props; const { t } = useTranslation(); const [inputSigningSecret, setInputSigningSecret] = useState(slackSigningSecret || ''); const [inputBotToken, setInputBotToken] = useState(slackBotToken || ''); // update states when props are updated useEffect(() => { setInputSigningSecret(slackSigningSecret || ''); }, [slackSigningSecret]); useEffect(() => { setInputBotToken(slackBotToken || ''); }, [slackBotToken]); const updatedSecretToken = async() => { try { await apiv3Put('/slack-integration-settings/without-proxy/update-settings', { slackSigningSecret: inputSigningSecret, slackBotToken: inputBotToken, }); if (onUpdatedSecretToken != null) { onUpdatedSecretToken(inputSigningSecret, inputBotToken); } toastSuccess(t('toaster.update_successed', { target: t('admin:slack_integration.custom_bot_without_proxy_settings'), ns: 'commons' })); } catch (err) { toastError(err); } }; return (
Database
setInputSigningSecret(e.target.value)} />Environment variables
{/* eslint-disable-next-line max-len, react/no-danger */}
Database
setInputBotToken(e.target.value)} />Environment variables
{/* eslint-disable-next-line react/no-danger */}