Просмотр исходного кода

added fetch integration data after deleting tokens

Steven Fukase 4 лет назад
Родитель
Сommit
533068075a

+ 15 - 7
src/client/js/components/Admin/SlackIntegration/CustomBotWithProxySettings.jsx

@@ -13,10 +13,15 @@ const logger = loggerFactory('growi:SlackBotSettings');
 
 
 const CustomBotWithProxySettings = (props) => {
 const CustomBotWithProxySettings = (props) => {
   const { appContainer, slackAppIntegrations, proxyServerUri } = props;
   const { appContainer, slackAppIntegrations, proxyServerUri } = props;
-  const [isDeleteConfirmModalShown, setIsDeleteConfirmModalShown] = useState(false);
+  const [newProxyServerUri, setNewProxyServerUri] = useState();
+  const [deleteTokenObject, setDeleteTokenObject] = useState(null);
   const { t } = useTranslation();
   const { t } = useTranslation();
 
 
-  const [newProxyServerUri, setNewProxyServerUri] = useState();
+  const fetchSlackIntegrationData = () => {
+    if (props.fetchSlackIntegrationData != null) {
+      fetchSlackIntegrationData();
+    }
+  };
 
 
   useEffect(() => {
   useEffect(() => {
     if (proxyServerUri != null) {
     if (proxyServerUri != null) {
@@ -28,10 +33,12 @@ const CustomBotWithProxySettings = (props) => {
     // TODO GW-6067 implement
     // TODO GW-6067 implement
   };
   };
 
 
-  const deleteSlackAppIntegrationHandler = async(tokenGtoP, tokenPtoG) => {
+  const deleteSlackAppIntegrationHandler = async() => {
     try {
     try {
       // GW-6068 set new value after this
       // GW-6068 set new value after this
-      await appContainer.apiv3.delete('/slack-integration-settings/slack-app-integration', { tokenGtoP, tokenPtoG });
+      await appContainer.apiv3.delete('/slack-integration-settings/slack-app-integration', deleteTokenObject);
+      fetchSlackIntegrationData();
+      toastSuccess(t('toaster.update_successed', { target: 'Successfully deleted workspace connection' }));
     }
     }
     catch (err) {
     catch (err) {
       toastError(err);
       toastError(err);
@@ -111,7 +118,7 @@ const CustomBotWithProxySettings = (props) => {
                 <button
                 <button
                   className="my-3 btn btn-outline-danger"
                   className="my-3 btn btn-outline-danger"
                   type="button"
                   type="button"
-                  onClick={() => setIsDeleteConfirmModalShown(true)}
+                  onClick={() => setDeleteTokenObject({ tokenGtoP, tokenPtoG })}
                 >
                 >
                   <i className="icon-trash mr-1" />
                   <i className="icon-trash mr-1" />
                   {t('admin:slack_integration.delete')}
                   {t('admin:slack_integration.delete')}
@@ -138,8 +145,8 @@ const CustomBotWithProxySettings = (props) => {
       </div>
       </div>
       <DeleteSlackBotSettingsModal
       <DeleteSlackBotSettingsModal
         isResetAll={false}
         isResetAll={false}
-        isOpen={isDeleteConfirmModalShown}
-        onClose={() => setIsDeleteConfirmModalShown(false)}
+        isOpen={deleteTokenObject != null}
+        onClose={() => setDeleteTokenObject(null)}
         onClickDeleteButton={deleteSlackAppIntegrationHandler}
         onClickDeleteButton={deleteSlackAppIntegrationHandler}
       />
       />
     </>
     </>
@@ -156,6 +163,7 @@ CustomBotWithProxySettings.propTypes = {
   appContainer: PropTypes.instanceOf(AppContainer).isRequired,
   appContainer: PropTypes.instanceOf(AppContainer).isRequired,
   slackAppIntegrations: PropTypes.array,
   slackAppIntegrations: PropTypes.array,
   proxyServerUri: PropTypes.string,
   proxyServerUri: PropTypes.string,
+  fetchSlackIntegrationData: PropTypes.func,
 };
 };
 
 
 export default CustomBotWithProxySettingsWrapper;
 export default CustomBotWithProxySettingsWrapper;

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

@@ -145,7 +145,13 @@ const SlackIntegration = (props) => {
       );
       );
       break;
       break;
     case 'customBotWithProxy':
     case 'customBotWithProxy':
-      settingsComponent = <CustomBotWithProxySettings slackAppIntegrations={slackAppIntegrations} proxyServerUri={proxyServerUri} />;
+      settingsComponent = (
+        <CustomBotWithProxySettings
+          slackAppIntegrations={slackAppIntegrations}
+          proxyServerUri={proxyServerUri}
+          fetchSlackIntegrationData={fetchSlackIntegrationData}
+        />
+      );
       break;
       break;
   }
   }
 
 

+ 1 - 1
src/server/routes/apiv3/slack-integration-settings.js

@@ -409,7 +409,7 @@ module.exports = (crowi) => {
   router.delete('/slack-app-integration', validator.AccessTokens, apiV3FormValidator, async(req, res) => {
   router.delete('/slack-app-integration', validator.AccessTokens, apiV3FormValidator, async(req, res) => {
     const SlackAppIntegration = mongoose.model('SlackAppIntegration');
     const SlackAppIntegration = mongoose.model('SlackAppIntegration');
     const { tokenGtoP, tokenPtoG } = req.query;
     const { tokenGtoP, tokenPtoG } = req.query;
-    console.log(tokenGtoP, tokenPtoG);
+
     try {
     try {
       const response = await SlackAppIntegration.findOneAndDelete({ tokenGtoP, tokenPtoG });
       const response = await SlackAppIntegration.findOneAndDelete({ tokenGtoP, tokenPtoG });
       return res.apiv3({ response });
       return res.apiv3({ response });