|
|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useState, useEffect } from 'react';
|
|
|
+import React, { useState, useEffect, useCallback } from 'react';
|
|
|
import PropTypes from 'prop-types';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
|
@@ -8,12 +8,15 @@ import { toastSuccess, toastError } from '~/client/util/apiNotification';
|
|
|
import CustomBotWithProxyConnectionStatus from './CustomBotWithProxyConnectionStatus';
|
|
|
import WithProxyAccordions from './WithProxyAccordions';
|
|
|
import DeleteSlackBotSettingsModal from './DeleteSlackBotSettingsModal';
|
|
|
+import { SlackAppIntegrationControl } from './SlackAppIntegrationControl';
|
|
|
|
|
|
const logger = loggerFactory('growi:cli:SlackIntegration:OfficialBotSettings');
|
|
|
|
|
|
const OfficialBotSettings = (props) => {
|
|
|
const {
|
|
|
- appContainer, slackAppIntegrations, onClickAddSlackWorkspaceBtn, connectionStatuses, onUpdateTokens, onSubmitForm,
|
|
|
+ appContainer, slackAppIntegrations,
|
|
|
+ onClickAddSlackWorkspaceBtn, onPrimaryUpdated,
|
|
|
+ connectionStatuses, onUpdateTokens, onSubmitForm,
|
|
|
} = props;
|
|
|
const [siteName, setSiteName] = useState('');
|
|
|
const [integrationIdToDelete, setIntegrationIdToDelete] = useState(null);
|
|
|
@@ -25,6 +28,25 @@ const OfficialBotSettings = (props) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ const isPrimaryChangedHandler = useCallback(async(slackIntegrationToChange, newValue) => {
|
|
|
+ // do nothing when turning off
|
|
|
+ if (!newValue) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ await appContainer.apiv3.put(`/slack-integration-settings/slack-app-integrations/${slackIntegrationToChange._id}/make-primary`);
|
|
|
+ if (onPrimaryUpdated != null) {
|
|
|
+ onPrimaryUpdated();
|
|
|
+ }
|
|
|
+ toastSuccess(t('toaster.update_successed', { target: 'Primary' }));
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ toastError(err, 'Failed to change isPrimary');
|
|
|
+ logger.error('Failed to change isPrimary', err);
|
|
|
+ }
|
|
|
+ }, [appContainer.apiv3, t, onPrimaryUpdated]);
|
|
|
+
|
|
|
const deleteSlackAppIntegrationHandler = async() => {
|
|
|
await appContainer.apiv3.delete(`/slack-integration-settings/slack-app-integrations/${integrationIdToDelete}`);
|
|
|
try {
|
|
|
@@ -79,28 +101,12 @@ const OfficialBotSettings = (props) => {
|
|
|
<h2 id={_id || `settings-accordions-${i}`}>
|
|
|
{(workspaceName != null) ? `${workspaceName} Work Space` : `Settings #${i}`}
|
|
|
</h2>
|
|
|
- <div className="d-flex align-items-center">
|
|
|
- <div className="my-1 custom-control custom-switch">
|
|
|
- <input
|
|
|
- className="custom-control-input"
|
|
|
- id="cb-primary"
|
|
|
- type="checkbox"
|
|
|
- checked
|
|
|
- onChange={() => {}}
|
|
|
- />
|
|
|
- <label className="custom-control-label" htmlFor="cb-primary">
|
|
|
- Primary
|
|
|
- </label>
|
|
|
- </div>
|
|
|
- <button
|
|
|
- className="btn btn-outline-danger ml-3"
|
|
|
- type="button"
|
|
|
- onClick={() => setIntegrationIdToDelete(slackAppIntegration._id)}
|
|
|
- >
|
|
|
- <i className="icon-trash mr-1" />
|
|
|
- {t('admin:slack_integration.delete')}
|
|
|
- </button>
|
|
|
- </div>
|
|
|
+ <SlackAppIntegrationControl
|
|
|
+ slackAppIntegration={slackAppIntegration}
|
|
|
+ onIsPrimaryChanged={isPrimaryChangedHandler}
|
|
|
+ // set state to open DeleteSlackBotSettingsModal
|
|
|
+ onDeleteButtonClicked={saiToDelete => setIntegrationIdToDelete(saiToDelete._id)}
|
|
|
+ />
|
|
|
</div>
|
|
|
<WithProxyAccordions
|
|
|
botType="officialBot"
|
|
|
@@ -147,6 +153,7 @@ OfficialBotSettings.propTypes = {
|
|
|
|
|
|
slackAppIntegrations: PropTypes.array,
|
|
|
onClickAddSlackWorkspaceBtn: PropTypes.func,
|
|
|
+ onPrimaryUpdated: PropTypes.func,
|
|
|
onDeleteSlackAppIntegration: PropTypes.func,
|
|
|
connectionStatuses: PropTypes.object.isRequired,
|
|
|
onUpdateTokens: PropTypes.func,
|