Merge pull request #996 from akhilmhdh/fix/integration-revoke

fix: integration bot deactive resolved and redis type error
This commit is contained in:
BlackMagiq
2023-09-16 14:26:43 +01:00
committed by GitHub
3 changed files with 29 additions and 25 deletions
+4 -4
View File
@@ -1,12 +1,12 @@
import { Redis } from "ioredis" import Redis, { Redis as TRedis } from "ioredis";
let redisClient: Redis | null; let redisClient: TRedis | null;
if (process.env.REDIS_URL) { if (process.env.REDIS_URL) {
redisClient = new Redis(process.env.REDIS_URL as string); redisClient = new Redis(process.env.REDIS_URL as string);
} else { } else {
console.warn("Redis URL not set, skipping Redis initialization."); console.warn("Redis URL not set, skipping Redis initialization.");
redisClient = null redisClient = null;
} }
export { redisClient } export { redisClient };
-1
View File
@@ -270,7 +270,6 @@ export const UpdateSecretByNameRawV3 = z.object({
workspaceId: z.string().trim(), workspaceId: z.string().trim(),
environment: z.string().trim(), environment: z.string().trim(),
secretValue: z.string().trim(), secretValue: z.string().trim(),
secretName: z.string().trim(),
secretPath: z.string().trim().default("/"), secretPath: z.string().trim().default("/"),
type: z.enum([SECRET_SHARED, SECRET_PERSONAL]).default(SECRET_SHARED) type: z.enum([SECRET_SHARED, SECRET_PERSONAL]).default(SECRET_SHARED)
}) })
@@ -51,17 +51,20 @@ export const IntegrationsPage = withProjectPermission(
const { data: cloudIntegrations, isLoading: isCloudIntegrationsLoading } = const { data: cloudIntegrations, isLoading: isCloudIntegrationsLoading } =
useGetCloudIntegrations(); useGetCloudIntegrations();
const { data: integrationAuths, isLoading: isIntegrationAuthLoading } = const {
useGetWorkspaceAuthorizations( data: integrationAuths,
workspaceId, isLoading: isIntegrationAuthLoading,
useCallback((data: IntegrationAuth[]) => { isFetching: isIntegrationAuthFetching
const groupBy: Record<string, IntegrationAuth> = {}; } = useGetWorkspaceAuthorizations(
data.forEach((el) => { workspaceId,
groupBy[el.integration] = el; useCallback((data: IntegrationAuth[]) => {
}); const groupBy: Record<string, IntegrationAuth> = {};
return groupBy; data.forEach((el) => {
}, []) groupBy[el.integration] = el;
); });
return groupBy;
}, [])
);
// mutation // mutation
const { const {
data: integrations, data: integrations,
@@ -77,20 +80,22 @@ export const IntegrationsPage = withProjectPermission(
const { mutateAsync: deleteIntegration } = useDeleteIntegration(); const { mutateAsync: deleteIntegration } = useDeleteIntegration();
const { const {
mutateAsync: deleteIntegrationAuth, mutateAsync: deleteIntegrationAuth,
isLoading: isDeleteIntegrationAuthSuccess, isSuccess: isDeleteIntegrationAuthSuccess,
reset: resetDeleteIntegrationAuth reset: resetDeleteIntegrationAuth
} = useDeleteIntegrationAuth(); } = useDeleteIntegrationAuth();
const isIntegrationsAuthorizedEmpty = !Object.keys(integrationAuths || {}).length;
const isIntegrationsEmpty = !integrations?.length;
// summary: this use effect is trigger when all integration auths are removed thus deactivate bot // summary: this use effect is trigger when all integration auths are removed thus deactivate bot
// details: so onsuccessfully deleting an integration auth, immediately integration list is refeteched // details: so on successfully deleting an integration auth, immediately integration list is refeteched
// After the refetch is completed check if its empty. Then set bot active and reset the submit hook // After the refetch is completed check if its empty. Then set bot active and reset the submit hook for isSuccess to go back to false
useEffect(() => { useEffect(() => {
if ( if (
isDeleteIntegrationAuthSuccess && isDeleteIntegrationAuthSuccess &&
!isIntegrationFetching && !isIntegrationFetching &&
!isIntegrationAuthLoading && !isIntegrationAuthFetching &&
!integrations?.length && isIntegrationsAuthorizedEmpty &&
!integrationAuths?.length isIntegrationsEmpty
) { ) {
if (bot?._id) if (bot?._id)
updateBotActiveStatusSync({ updateBotActiveStatusSync({
@@ -103,9 +108,9 @@ export const IntegrationsPage = withProjectPermission(
}, [ }, [
isIntegrationFetching, isIntegrationFetching,
isDeleteIntegrationAuthSuccess, isDeleteIntegrationAuthSuccess,
isIntegrationAuthLoading, isIntegrationAuthFetching,
integrationAuths?.length, isIntegrationsAuthorizedEmpty,
integrations?.length isIntegrationsEmpty
]); ]);
const handleProviderIntegration = async (provider: string) => { const handleProviderIntegration = async (provider: string) => {