feat: finished org-level integration management flow

This commit is contained in:
Sheen Capadngan
2024-09-03 22:08:31 +08:00
parent 9120367562
commit a2b555dd81
23 changed files with 865 additions and 234 deletions
+1
View File
@@ -45,4 +45,5 @@ export * from "./tags";
export * from "./trustedIps";
export * from "./users";
export * from "./webhooks";
export * from "./workflowIntegrations";
export * from "./workspace";
+1 -1
View File
@@ -1,2 +1,2 @@
export { useDeleteSlackIntegration, useUpdateSlackIntegration } from "./mutation";
export { fetchSlackInstallUrl, useGetSlackIntegrationByProject } from "./queries";
export { useGetSlackIntegrationByProject } from "./queries";
-10
View File
@@ -11,16 +11,6 @@ export const slackKeys = {
]
};
export const fetchSlackInstallUrl = async (workspaceId?: string) => {
const { data } = await apiRequest.get<string>("/api/v1/slack/install", {
params: {
projectId: workspaceId
}
});
return data;
};
export const fetchSlackIntegrationByProject = async (workspaceId?: string) => {
const { data } = await apiRequest.get<ProjectSlackIntegration>("/api/v1/slack", {
params: {
@@ -0,0 +1,6 @@
export { useDeleteSlackIntegration, useUpdateSlackIntegration } from "./mutation";
export {
fetchSlackInstallUrl,
useGetSlackIntegrationById,
useGetSlackIntegrations
} from "./queries";
@@ -0,0 +1,38 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { workflowIntegrationKeys } from "./queries";
import { TDeleteSlackIntegrationDTO, TUpdateSlackIntegrationDTO } from "./types";
export const useUpdateSlackIntegration = () => {
const queryClient = useQueryClient();
return useMutation<{}, {}, TUpdateSlackIntegrationDTO>({
mutationFn: async (dto) => {
const { data } = await apiRequest.patch(`/api/v1/workflow-integrations/slack/${dto.id}`, dto);
return data;
},
onSuccess: (_, { orgId, id }) => {
queryClient.invalidateQueries(workflowIntegrationKeys.getSlackWorkflowIntegration(id));
queryClient.invalidateQueries(workflowIntegrationKeys.getSlackWorkflowIntegrations(orgId));
}
});
};
export const useDeleteSlackIntegration = () => {
const queryClient = useQueryClient();
return useMutation<{}, {}, TDeleteSlackIntegrationDTO>({
mutationFn: async (dto) => {
const { data } = await apiRequest.delete(`/api/v1/workflow-integrations/slack/${dto.id}`);
return data;
},
onSuccess: (_, { orgId, id }) => {
queryClient.invalidateQueries(workflowIntegrationKeys.getSlackWorkflowIntegration(id));
queryClient.invalidateQueries(workflowIntegrationKeys.getSlackWorkflowIntegrations(orgId));
}
});
};
@@ -0,0 +1,55 @@
import { useQuery } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { SlackIntegration } from "./types";
export const workflowIntegrationKeys = {
getSlackWorkflowIntegrations: (orgId?: string) => [{ orgId }, "slack-workflow-integrations"],
getSlackWorkflowIntegration: (id?: string) => [{ id }, "slack-workflow-integration"]
};
export const fetchSlackInstallUrl = async ({
slug,
description
}: {
slug: string;
description?: string;
}) => {
const { data } = await apiRequest.get<string>("/api/v1/workflow-integrations/slack/install", {
params: {
slug,
description
}
});
return data;
};
export const fetchSlackIntegrations = async () => {
const { data } = await apiRequest.get<SlackIntegration[]>("/api/v1/workflow-integrations/slack");
return data;
};
export const fetchSlackIntegrationById = async (id?: string) => {
const { data } = await apiRequest.get<SlackIntegration>(
`/api/v1/workflow-integrations/slack/${id}`
);
return data;
};
export const useGetSlackIntegrations = (orgId?: string) =>
useQuery({
queryKey: workflowIntegrationKeys.getSlackWorkflowIntegrations(orgId),
queryFn: () => fetchSlackIntegrations(),
enabled: Boolean(orgId)
});
export const useGetSlackIntegrationById = (id?: string) =>
useQuery({
queryKey: workflowIntegrationKeys.getSlackWorkflowIntegration(id),
queryFn: () => fetchSlackIntegrationById(id),
enabled: Boolean(id)
});
@@ -0,0 +1,22 @@
export enum WorkflowIntegrationPlatform {
SLACK = "slack"
}
export type SlackIntegration = {
id: string;
slug: string;
description: string;
teamName: string;
};
export type TUpdateSlackIntegrationDTO = {
id: string;
orgId: string;
slug?: string;
description?: string;
};
export type TDeleteSlackIntegrationDTO = {
id: string;
orgId: string;
};