Browse Source

replace retrieveData to swr

kaori 3 năm trước cách đây
mục cha
commit
0f6689e752

+ 12 - 5
packages/app/src/components/Admin/LegacySlackIntegration/LegacySlackIntegration.jsx

@@ -1,10 +1,11 @@
-import React, { useMemo, useState } from 'react';
+import React, { useEffect, useMemo, useState } from 'react';
 
 
 import { useTranslation } from 'next-i18next';
 import { useTranslation } from 'next-i18next';
 import PropTypes from 'prop-types';
 import PropTypes from 'prop-types';
 
 
 import AdminSlackIntegrationLegacyContainer from '~/client/services/AdminSlackIntegrationLegacyContainer';
 import AdminSlackIntegrationLegacyContainer from '~/client/services/AdminSlackIntegrationLegacyContainer';
 import { toastError } from '~/client/util/apiNotification';
 import { toastError } from '~/client/util/apiNotification';
+import { useSWRxLegacySlackIntegrationSetting } from '~/stores/legacy-slack-integration';
 import { toArrayIfNot } from '~/utils/array-utils';
 import { toArrayIfNot } from '~/utils/array-utils';
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 
 
@@ -15,11 +16,17 @@ import SlackConfiguration from './SlackConfiguration';
 
 
 const logger = loggerFactory('growi:NotificationSetting');
 const logger = loggerFactory('growi:NotificationSetting');
 
 
-const retrieveErrors = null;
+// const retrieveErrors = null;
 function LegacySlackIntegration(props) {
 function LegacySlackIntegration(props) {
   const { t } = useTranslation();
   const { t } = useTranslation();
+  const { data: legacySlackIntegrationSettingData } = useSWRxLegacySlackIntegrationSetting();
   const { adminSlackIntegrationLegacyContainer } = props;
   const { adminSlackIntegrationLegacyContainer } = props;
 
 
+
+  useEffect(() => {
+
+  }, [legacySlackIntegrationSettingData]);
+
   if (adminSlackIntegrationLegacyContainer.state.webhookUrl === adminSlackIntegrationLegacyContainer.dummyWebhookUrl) {
   if (adminSlackIntegrationLegacyContainer.state.webhookUrl === adminSlackIntegrationLegacyContainer.dummyWebhookUrl) {
     // TODO: SWRize  adminSlackIntegrationLegacyContainer.retrieveData();
     // TODO: SWRize  adminSlackIntegrationLegacyContainer.retrieveData();
     // throw (async() => {
     // throw (async() => {
@@ -36,9 +43,9 @@ function LegacySlackIntegration(props) {
     // })();
     // })();
   }
   }
 
 
-  if (adminSlackIntegrationLegacyContainer.state.webhookUrl === adminSlackIntegrationLegacyContainer.dummyWebhookUrlForError) {
-    throw new Error(`${retrieveErrors.length} errors occured`);
-  }
+  // if (adminSlackIntegrationLegacyContainer.state.webhookUrl === adminSlackIntegrationLegacyContainer.dummyWebhookUrlForError) {
+  //   throw new Error(`${retrieveErrors.length} errors occured`);
+  // }
 
 
   const isDisabled = adminSlackIntegrationLegacyContainer.state.isSlackbotConfigured;
   const isDisabled = adminSlackIntegrationLegacyContainer.state.isSlackbotConfigured;
 
 

+ 10 - 0
packages/app/src/stores/legacy-slack-integration.ts

@@ -0,0 +1,10 @@
+import useSWR, { SWRResponse } from 'swr';
+
+import { apiv3Get } from '../client/util/apiv3-client';
+
+
+export const useSWRxLegacySlackIntegrationSetting = (): SWRResponse<any, Error> => {
+  return useSWR<any, Error>(
+    apiv3Get('/slack-integration-legacy-settings/').then(response => response.data),
+  );
+};