|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useState, useEffect, useCallback } from 'react';
|
|
|
|
|
|
|
+import React, { useState } from 'react';
|
|
|
import PropTypes from 'prop-types';
|
|
import PropTypes from 'prop-types';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
import AppContainer from '../../../services/AppContainer';
|
|
import AppContainer from '../../../services/AppContainer';
|
|
@@ -15,39 +15,19 @@ export const botInstallationStep = {
|
|
|
CONNECTION_TEST: 'connection-test',
|
|
CONNECTION_TEST: 'connection-test',
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const CustomBotWithoutProxySettingsAccordion = ({ appContainer, adminAppContainer, activeStep }) => {
|
|
|
|
|
- const { t } = useTranslation('admin');
|
|
|
|
|
|
|
+const CustomBotWithoutProxySettingsAccordion = ({
|
|
|
|
|
+ appContainer,
|
|
|
|
|
+ activeStep, slackSigningSecret, slackSigningSecretEnv, slackBotToken,
|
|
|
|
|
+ slackBotTokenEnv, isRegisterSlackCredentials, isSendTestMessage,
|
|
|
|
|
+ setSlackSigningSecret, setSlackBotToken, setIsSendTestMessage, setIsRegisterSlackCredentials,
|
|
|
|
|
+}) => {
|
|
|
|
|
+ const { t } = useTranslation();
|
|
|
// TODO: GW-5644 Store default open accordion
|
|
// TODO: GW-5644 Store default open accordion
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
const [defaultOpenAccordionKeys, setDefaultOpenAccordionKeys] = useState(new Set([activeStep]));
|
|
const [defaultOpenAccordionKeys, setDefaultOpenAccordionKeys] = useState(new Set([activeStep]));
|
|
|
const [connectionErrorCode, setConnectionErrorCode] = useState(null);
|
|
const [connectionErrorCode, setConnectionErrorCode] = useState(null);
|
|
|
const [connectionErrorMessage, setConnectionErrorMessage] = useState(null);
|
|
const [connectionErrorMessage, setConnectionErrorMessage] = useState(null);
|
|
|
- const [slackSigningSecret, setSlackSigningSecret] = useState('');
|
|
|
|
|
- const [slackBotToken, setSlackBotToken] = useState('');
|
|
|
|
|
- const [slackSigningSecretEnv, setSlackSigningSecretEnv] = useState('');
|
|
|
|
|
- const [slackBotTokenEnv, setSlackBotTokenEnv] = useState('');
|
|
|
|
|
- const currentBotType = 'custom-bot-without-proxy';
|
|
|
|
|
-
|
|
|
|
|
- const fetchData = useCallback(async() => {
|
|
|
|
|
- try {
|
|
|
|
|
- await adminAppContainer.retrieveAppSettingsData();
|
|
|
|
|
- const res = await appContainer.apiv3.get('/slack-integration/');
|
|
|
|
|
- const {
|
|
|
|
|
- slackSigningSecret, slackBotToken, slackSigningSecretEnvVars, slackBotTokenEnvVars,
|
|
|
|
|
- } = res.data.slackBotSettingParams.customBotWithoutProxySettings;
|
|
|
|
|
- setSlackSigningSecret(slackSigningSecret);
|
|
|
|
|
- setSlackBotToken(slackBotToken);
|
|
|
|
|
- setSlackSigningSecretEnv(slackSigningSecretEnvVars);
|
|
|
|
|
- setSlackBotTokenEnv(slackBotTokenEnvVars);
|
|
|
|
|
- }
|
|
|
|
|
- catch (err) {
|
|
|
|
|
- toastError(err);
|
|
|
|
|
- }
|
|
|
|
|
- }, [appContainer, adminAppContainer]);
|
|
|
|
|
-
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- fetchData();
|
|
|
|
|
- }, [fetchData]);
|
|
|
|
|
|
|
+ const currentBotType = 'customBotWithoutProxy';
|
|
|
|
|
|
|
|
const updateSecretTokenHandler = async() => {
|
|
const updateSecretTokenHandler = async() => {
|
|
|
try {
|
|
try {
|
|
@@ -56,10 +36,10 @@ const CustomBotWithoutProxySettingsAccordion = ({ appContainer, adminAppContaine
|
|
|
slackBotToken,
|
|
slackBotToken,
|
|
|
currentBotType,
|
|
currentBotType,
|
|
|
});
|
|
});
|
|
|
- fetchData();
|
|
|
|
|
- toastSuccess(t('toaster.update_successed', { target: t('slack_integration.custom_bot_without_proxy_settings') }));
|
|
|
|
|
|
|
+ toastSuccess(t('toaster.update_successed', { target: t('admin:slack_integration.custom_bot_without_proxy_settings') }));
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
|
|
+ setIsRegisterSlackCredentials(false);
|
|
|
toastError(err);
|
|
toastError(err);
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
@@ -76,12 +56,14 @@ const CustomBotWithoutProxySettingsAccordion = ({ appContainer, adminAppContaine
|
|
|
setConnectionErrorCode(null);
|
|
setConnectionErrorCode(null);
|
|
|
setConnectionErrorMessage(null);
|
|
setConnectionErrorMessage(null);
|
|
|
try {
|
|
try {
|
|
|
- await appContainer.apiv3.post('slack-integration/notification-test-to-slack-work-space', {
|
|
|
|
|
|
|
+ await appContainer.apiv3.post('admin:slack-integration/notification-test-to-slack-work-space', {
|
|
|
// TODO put proper request
|
|
// TODO put proper request
|
|
|
- channel: 'testchannel',
|
|
|
|
|
|
|
+ // channel: 'testchannel',
|
|
|
});
|
|
});
|
|
|
|
|
+ setIsSendTestMessage(true);
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
|
|
+ setIsSendTestMessage(false);
|
|
|
setConnectionErrorCode(err[0].code);
|
|
setConnectionErrorCode(err[0].code);
|
|
|
setConnectionErrorMessage(err[0].message);
|
|
setConnectionErrorMessage(err[0].message);
|
|
|
}
|
|
}
|
|
@@ -91,13 +73,13 @@ const CustomBotWithoutProxySettingsAccordion = ({ appContainer, adminAppContaine
|
|
|
<div className="card border-0 rounded-lg shadow overflow-hidden">
|
|
<div className="card border-0 rounded-lg shadow overflow-hidden">
|
|
|
<Accordion
|
|
<Accordion
|
|
|
defaultIsActive={defaultOpenAccordionKeys.has(botInstallationStep.CREATE_BOT)}
|
|
defaultIsActive={defaultOpenAccordionKeys.has(botInstallationStep.CREATE_BOT)}
|
|
|
- title={<><span className="mr-2">①</span>{t('slack_integration.without_proxy.create_bot')}</>}
|
|
|
|
|
|
|
+ title={<><span className="mr-2">①</span>{t('admin:slack_integration.without_proxy.create_bot')}</>}
|
|
|
>
|
|
>
|
|
|
<div className="row my-5">
|
|
<div className="row my-5">
|
|
|
<div className="mx-auto">
|
|
<div className="mx-auto">
|
|
|
<div>
|
|
<div>
|
|
|
<button type="button" className="btn btn-primary text-nowrap mx-1" onClick={() => window.open('https://api.slack.com/apps', '_blank')}>
|
|
<button type="button" className="btn btn-primary text-nowrap mx-1" onClick={() => window.open('https://api.slack.com/apps', '_blank')}>
|
|
|
- {t('slack_integration.without_proxy.create_bot')}
|
|
|
|
|
|
|
+ {t('admin:slack_integration.without_proxy.create_bot')}
|
|
|
<i className="fa fa-external-link ml-2" aria-hidden="true" />
|
|
<i className="fa fa-external-link ml-2" aria-hidden="true" />
|
|
|
</button>
|
|
</button>
|
|
|
</div>
|
|
</div>
|
|
@@ -105,7 +87,7 @@ const CustomBotWithoutProxySettingsAccordion = ({ appContainer, adminAppContaine
|
|
|
<a href="#">
|
|
<a href="#">
|
|
|
<p className="text-center mt-1">
|
|
<p className="text-center mt-1">
|
|
|
<small>
|
|
<small>
|
|
|
- {t('slack_integration.without_proxy.how_to_create_a_bot')}
|
|
|
|
|
|
|
+ {t('admin:slack_integration.without_proxy.how_to_create_a_bot')}
|
|
|
<i className="fa fa-external-link ml-2" aria-hidden="true" />
|
|
<i className="fa fa-external-link ml-2" aria-hidden="true" />
|
|
|
</small>
|
|
</small>
|
|
|
</p>
|
|
</p>
|
|
@@ -115,25 +97,26 @@ const CustomBotWithoutProxySettingsAccordion = ({ appContainer, adminAppContaine
|
|
|
</Accordion>
|
|
</Accordion>
|
|
|
<Accordion
|
|
<Accordion
|
|
|
defaultIsActive={defaultOpenAccordionKeys.has(botInstallationStep.INSTALL_BOT)}
|
|
defaultIsActive={defaultOpenAccordionKeys.has(botInstallationStep.INSTALL_BOT)}
|
|
|
- title={<><span className="mr-2">②</span>{t('slack_integration.without_proxy.install_bot_to_slack')}</>}
|
|
|
|
|
|
|
+ title={<><span className="mr-2">②</span>{t('admin:slack_integration.without_proxy.install_bot_to_slack')}</>}
|
|
|
>
|
|
>
|
|
|
<div className="container w-75 py-5">
|
|
<div className="container w-75 py-5">
|
|
|
- <p>1. Install your app をクリックします。</p>
|
|
|
|
|
|
|
+ <p>1. {t('admin:slack_integration.without_proxy.select_install_your_app')}</p>
|
|
|
<img src="/images/slack-integration/slack-bot-install-your-app-introduction.png" className="border border-light img-fluid mb-5" />
|
|
<img src="/images/slack-integration/slack-bot-install-your-app-introduction.png" className="border border-light img-fluid mb-5" />
|
|
|
- <p>2. Install to Workspace をクリックします。</p>
|
|
|
|
|
|
|
+ <p>2. {t('admin:slack_integration.without_proxy.select_install_to_workspace')}</p>
|
|
|
<img src="/images/slack-integration/slack-bot-install-to-workspace.png" className="border border-light img-fluid mb-5" />
|
|
<img src="/images/slack-integration/slack-bot-install-to-workspace.png" className="border border-light img-fluid mb-5" />
|
|
|
- <p>3. 遷移先の画面にて、Allowをクリックします。</p>
|
|
|
|
|
|
|
+ <p>3. {t('admin:slack_integration.without_proxy.click_allow')}</p>
|
|
|
<img src="/images/slack-integration/slack-bot-install-your-app-transition-destination.png" className="border border-light img-fluid mb-5" />
|
|
<img src="/images/slack-integration/slack-bot-install-your-app-transition-destination.png" className="border border-light img-fluid mb-5" />
|
|
|
- <p>4. Install your app の右側に 緑色のチェックがつけばワークスペースへのインストール完了です。</p>
|
|
|
|
|
|
|
+ <p>4. {t('admin:slack_integration.without_proxy.install_complete_if_checked')}</p>
|
|
|
<img src="/images/slack-integration/slack-bot-install-your-app-complete.png" className="border border-light img-fluid mb-5" />
|
|
<img src="/images/slack-integration/slack-bot-install-your-app-complete.png" className="border border-light img-fluid mb-5" />
|
|
|
- <p>5. GROWI bot を使いたいチャンネルに @example を使用して招待します。</p>
|
|
|
|
|
|
|
+ <p>5. {t('admin:slack_integration.without_proxy.invite_bot_to_channel')}</p>
|
|
|
<img src="/images/slack-integration/slack-bot-install-to-workspace-joined-bot.png" className="border border-light img-fluid mb-1" />
|
|
<img src="/images/slack-integration/slack-bot-install-to-workspace-joined-bot.png" className="border border-light img-fluid mb-1" />
|
|
|
<img src="/images/slack-integration/slack-bot-install-your-app-introduction-to-channel.png" className="border border-light img-fluid" />
|
|
<img src="/images/slack-integration/slack-bot-install-your-app-introduction-to-channel.png" className="border border-light img-fluid" />
|
|
|
</div>
|
|
</div>
|
|
|
</Accordion>
|
|
</Accordion>
|
|
|
<Accordion
|
|
<Accordion
|
|
|
defaultIsActive={defaultOpenAccordionKeys.has(botInstallationStep.REGISTER_SLACK_CONFIGURATION)}
|
|
defaultIsActive={defaultOpenAccordionKeys.has(botInstallationStep.REGISTER_SLACK_CONFIGURATION)}
|
|
|
- title={<><span className="mr-2">③</span>{t('slack_integration.without_proxy.register_secret_and_token')}</>}
|
|
|
|
|
|
|
+ // eslint-disable-next-line max-len
|
|
|
|
|
+ title={<><span className="mr-2">③</span>{t('admin:slack_integration.without_proxy.register_secret_and_token')}{isRegisterSlackCredentials && <i className="ml-3 text-success fa fa-check"></i>}</>}
|
|
|
>
|
|
>
|
|
|
<CustomBotWithoutProxySecretTokenSection
|
|
<CustomBotWithoutProxySecretTokenSection
|
|
|
updateSecretTokenHandler={updateSecretTokenHandler}
|
|
updateSecretTokenHandler={updateSecretTokenHandler}
|
|
@@ -147,14 +130,15 @@ const CustomBotWithoutProxySettingsAccordion = ({ appContainer, adminAppContaine
|
|
|
</Accordion>
|
|
</Accordion>
|
|
|
<Accordion
|
|
<Accordion
|
|
|
defaultIsActive={defaultOpenAccordionKeys.has(botInstallationStep.CONNECTION_TEST)}
|
|
defaultIsActive={defaultOpenAccordionKeys.has(botInstallationStep.CONNECTION_TEST)}
|
|
|
- title={<><span className="mr-2">④</span>{t('slack_integration.without_proxy.test_connection')}</>}
|
|
|
|
|
|
|
+ // eslint-disable-next-line max-len
|
|
|
|
|
+ title={<><span className="mr-2">④</span>{t('admin:slack_integration.without_proxy.test_connection')}{isSendTestMessage && <i className="ml-3 text-success fa fa-check"></i>}</>}
|
|
|
>
|
|
>
|
|
|
- <p className="text-center m-4">以下のテストボタンを押して、Slack連携が完了しているかの確認をしましょう</p>
|
|
|
|
|
|
|
+ <p className="text-center m-4">{t('admin:slack_integration.without_proxy.test_connection_by_pressing_button')}</p>
|
|
|
<div className="d-flex justify-content-center">
|
|
<div className="d-flex justify-content-center">
|
|
|
<button type="button" className="btn btn-info m-3 px-5 font-weight-bold" onClick={onTestConnectionHandler}>Test</button>
|
|
<button type="button" className="btn btn-info m-3 px-5 font-weight-bold" onClick={onTestConnectionHandler}>Test</button>
|
|
|
</div>
|
|
</div>
|
|
|
{connectionErrorMessage != null
|
|
{connectionErrorMessage != null
|
|
|
- && <p className="text-danger text-center m-4">エラーが発生しました。下記のログを確認してください。</p>
|
|
|
|
|
|
|
+ && <p className="text-danger text-center m-4">{t('admin:slack_integration.without_proxy.error_check_logs_below')}</p>
|
|
|
}
|
|
}
|
|
|
<div className="row m-3 justify-content-center">
|
|
<div className="row m-3 justify-content-center">
|
|
|
<div className="col-sm-5 slack-connection-error-log">
|
|
<div className="col-sm-5 slack-connection-error-log">
|
|
@@ -174,6 +158,16 @@ const CustomBotWithoutProxySettingsAccordionWrapper = withUnstatedContainers(Cus
|
|
|
|
|
|
|
|
CustomBotWithoutProxySettingsAccordion.propTypes = {
|
|
CustomBotWithoutProxySettingsAccordion.propTypes = {
|
|
|
appContainer: PropTypes.instanceOf(AppContainer).isRequired,
|
|
appContainer: PropTypes.instanceOf(AppContainer).isRequired,
|
|
|
|
|
+ slackSigningSecret: PropTypes.string,
|
|
|
|
|
+ slackSigningSecretEnv: PropTypes.string,
|
|
|
|
|
+ slackBotToken: PropTypes.string,
|
|
|
|
|
+ slackBotTokenEnv: PropTypes.string,
|
|
|
|
|
+ isRegisterSlackCredentials: PropTypes.bool,
|
|
|
|
|
+ isSendTestMessage: PropTypes.bool,
|
|
|
|
|
+ setSlackSigningSecret: PropTypes.string,
|
|
|
|
|
+ setSlackBotToken: PropTypes.string,
|
|
|
|
|
+ setIsSendTestMessage: PropTypes.func,
|
|
|
|
|
+ setIsRegisterSlackCredentials: PropTypes.func,
|
|
|
adminAppContainer: PropTypes.instanceOf(AdminAppContainer).isRequired,
|
|
adminAppContainer: PropTypes.instanceOf(AdminAppContainer).isRequired,
|
|
|
activeStep: PropTypes.oneOf(Object.values(botInstallationStep)).isRequired,
|
|
activeStep: PropTypes.oneOf(Object.values(botInstallationStep)).isRequired,
|
|
|
};
|
|
};
|