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

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) {
redisClient = new Redis(process.env.REDIS_URL as string);
} else {
console.warn("Redis URL not set, skipping Redis initialization.");
redisClient = null
redisClient = null;
}
export { redisClient }
export { redisClient };

View File

@@ -270,7 +270,6 @@ export const UpdateSecretByNameRawV3 = z.object({
workspaceId: z.string().trim(),
environment: z.string().trim(),
secretValue: z.string().trim(),
secretName: z.string().trim(),
secretPath: z.string().trim().default("/"),
type: z.enum([SECRET_SHARED, SECRET_PERSONAL]).default(SECRET_SHARED)
})

View File

@@ -51,17 +51,20 @@ export const IntegrationsPage = withProjectPermission(
const { data: cloudIntegrations, isLoading: isCloudIntegrationsLoading } =
useGetCloudIntegrations();
const { data: integrationAuths, isLoading: isIntegrationAuthLoading } =
useGetWorkspaceAuthorizations(
workspaceId,
useCallback((data: IntegrationAuth[]) => {
const groupBy: Record<string, IntegrationAuth> = {};
data.forEach((el) => {
groupBy[el.integration] = el;
});
return groupBy;
}, [])
);
const {
data: integrationAuths,
isLoading: isIntegrationAuthLoading,
isFetching: isIntegrationAuthFetching
} = useGetWorkspaceAuthorizations(
workspaceId,
useCallback((data: IntegrationAuth[]) => {
const groupBy: Record<string, IntegrationAuth> = {};
data.forEach((el) => {
groupBy[el.integration] = el;
});
return groupBy;
}, [])
);
// mutation
const {
data: integrations,
@@ -77,20 +80,22 @@ export const IntegrationsPage = withProjectPermission(
const { mutateAsync: deleteIntegration } = useDeleteIntegration();
const {
mutateAsync: deleteIntegrationAuth,
isLoading: isDeleteIntegrationAuthSuccess,
isSuccess: isDeleteIntegrationAuthSuccess,
reset: resetDeleteIntegrationAuth
} = 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
// details: so onsuccessfully 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
// 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 for isSuccess to go back to false
useEffect(() => {
if (
isDeleteIntegrationAuthSuccess &&
!isIntegrationFetching &&
!isIntegrationAuthLoading &&
!integrations?.length &&
!integrationAuths?.length
!isIntegrationAuthFetching &&
isIntegrationsAuthorizedEmpty &&
isIntegrationsEmpty
) {
if (bot?._id)
updateBotActiveStatusSync({
@@ -103,9 +108,9 @@ export const IntegrationsPage = withProjectPermission(
}, [
isIntegrationFetching,
isDeleteIntegrationAuthSuccess,
isIntegrationAuthLoading,
integrationAuths?.length,
integrations?.length
isIntegrationAuthFetching,
isIntegrationsAuthorizedEmpty,
isIntegrationsEmpty
]);
const handleProviderIntegration = async (provider: string) => {