Bladeren bron

added get request on render

Steven Fukase 5 jaren geleden
bovenliggende
commit
19a1d9948f

+ 14 - 1
src/client/js/components/Admin/SlackIntegration/SlackIntegration.jsx

@@ -1,4 +1,4 @@
-import React, { useState } from 'react';
+import React, { useState, useEffect, useCallback } from 'react';
 import PropTypes from 'prop-types';
 import PropTypes from 'prop-types';
 import AppContainer from '../../../services/AppContainer';
 import AppContainer from '../../../services/AppContainer';
 import { withUnstatedContainers } from '../../UnstatedUtils';
 import { withUnstatedContainers } from '../../UnstatedUtils';
@@ -15,6 +15,19 @@ const SlackIntegration = (props) => {
   const [currentBotType, setCurrentBotType] = useState(null);
   const [currentBotType, setCurrentBotType] = useState(null);
   const [selectedBotType, setSelectedBotType] = useState(null);
   const [selectedBotType, setSelectedBotType] = useState(null);
 
 
+  const fetchData = useCallback(async() => {
+    try {
+      console.log(await appContainer.apiv3.get('slack-integration/'));
+    }
+    catch (err) {
+      toastError(err);
+    }
+  }, [appContainer]);
+
+  useEffect(() => {
+    fetchData();
+  }, [fetchData]);
+
   const resetBotType = async() => {
   const resetBotType = async() => {
     try {
     try {
       await appContainer.apiv3.put('slack-integration/custom-bot-without-proxy', {
       await appContainer.apiv3.put('slack-integration/custom-bot-without-proxy', {

+ 2 - 4
src/server/routes/apiv3/slack-integration.js

@@ -46,7 +46,6 @@ module.exports = (crowi) => {
     ],
     ],
     SlackIntegration: [
     SlackIntegration: [
       body('currentBotType')
       body('currentBotType')
-        .isString()
         .isIn(['official-bot', 'custom-bot-without-proxy', 'custom-bot-with-proxy']),
         .isIn(['official-bot', 'custom-bot-without-proxy', 'custom-bot-with-proxy']),
     ],
     ],
   };
   };
@@ -73,7 +72,7 @@ module.exports = (crowi) => {
   router.get('/', accessTokenParser, loginRequiredStrictly, adminRequired, async(req, res) => {
   router.get('/', accessTokenParser, loginRequiredStrictly, adminRequired, async(req, res) => {
 
 
     const slackBotSettingParams = {
     const slackBotSettingParams = {
-      slackBotType: crowi.configManager.getConfig('crowi', 'slackbot:type'),
+      currentBotType: crowi.configManager.getConfig('crowi', 'slackbot:type'),
       // TODO impl when creating official bot
       // TODO impl when creating official bot
       officialBotSettings: {
       officialBotSettings: {
         // TODO impl this after GW-4939
         // TODO impl this after GW-4939
@@ -119,11 +118,10 @@ module.exports = (crowi) => {
       catch (error) {
       catch (error) {
         const msg = 'Error occured in updating Slack bot setting';
         const msg = 'Error occured in updating Slack bot setting';
         logger.error('Error', error);
         logger.error('Error', error);
-        return res.apiv3Err(new ErrorV3(msg, 'update-SlackBotSetting-failed'));
+        return res.apiv3Err(new ErrorV3(msg, 'update-SlackIntegrationSetting-failed'));
       }
       }
     });
     });
 
 
-
   /**
   /**
    * @swagger
    * @swagger
    *
    *