feat: slack channel suggestions

This commit is contained in:
Sheen Capadngan
2024-09-04 18:03:07 +08:00
parent 15c5fe4095
commit 71b8c59050
10 changed files with 284 additions and 78 deletions
@@ -7,5 +7,6 @@ export {
fetchSlackInstallUrl,
fetchSlackReinstallUrl,
useGetSlackIntegrationById,
useGetSlackIntegrationChannels,
useGetSlackIntegrations
} from "./queries";
@@ -20,8 +20,8 @@ export const useUpdateSlackIntegration = () => {
return data;
},
onSuccess: (_, { orgId, id }) => {
queryClient.invalidateQueries(workflowIntegrationKeys.getSlackWorkflowIntegration(id));
queryClient.invalidateQueries(workflowIntegrationKeys.getSlackWorkflowIntegrations(orgId));
queryClient.invalidateQueries(workflowIntegrationKeys.getSlackIntegration(id));
queryClient.invalidateQueries(workflowIntegrationKeys.getSlackIntegrations(orgId));
}
});
};
@@ -36,8 +36,8 @@ export const useDeleteSlackIntegration = () => {
return data;
},
onSuccess: (_, { orgId, id }) => {
queryClient.invalidateQueries(workflowIntegrationKeys.getSlackWorkflowIntegration(id));
queryClient.invalidateQueries(workflowIntegrationKeys.getSlackWorkflowIntegrations(orgId));
queryClient.invalidateQueries(workflowIntegrationKeys.getSlackIntegration(id));
queryClient.invalidateQueries(workflowIntegrationKeys.getSlackIntegrations(orgId));
}
});
};
@@ -2,11 +2,12 @@ import { useQuery } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { SlackIntegration } from "./types";
import { SlackIntegration, SlackIntegrationChannel } from "./types";
export const workflowIntegrationKeys = {
getSlackWorkflowIntegrations: (orgId?: string) => [{ orgId }, "slack-workflow-integrations"],
getSlackWorkflowIntegration: (id?: string) => [{ id }, "slack-workflow-integration"]
getSlackIntegrations: (orgId?: string) => [{ orgId }, "slack-workflow-integrations"],
getSlackIntegration: (id?: string) => [{ id }, "slack-workflow-integration"],
getSlackIntegrationChannels: (id?: string) => [{ id }, "slack-workflow-integration-channels"]
};
export const fetchSlackInstallUrl = async ({
@@ -54,16 +55,31 @@ export const fetchSlackIntegrationById = async (id?: string) => {
return data;
};
export const fetchSlackIntegrationChannels = async (id?: string) => {
const { data } = await apiRequest.get<SlackIntegrationChannel[]>(
`/api/v1/workflow-integrations/slack/${id}/channels`
);
return data;
};
export const useGetSlackIntegrations = (orgId?: string) =>
useQuery({
queryKey: workflowIntegrationKeys.getSlackWorkflowIntegrations(orgId),
queryKey: workflowIntegrationKeys.getSlackIntegrations(orgId),
queryFn: () => fetchSlackIntegrations(),
enabled: Boolean(orgId)
});
export const useGetSlackIntegrationById = (id?: string) =>
useQuery({
queryKey: workflowIntegrationKeys.getSlackWorkflowIntegration(id),
queryKey: workflowIntegrationKeys.getSlackIntegration(id),
queryFn: () => fetchSlackIntegrationById(id),
enabled: Boolean(id)
});
export const useGetSlackIntegrationChannels = (id?: string) =>
useQuery({
queryKey: workflowIntegrationKeys.getSlackIntegrationChannels(id),
queryFn: () => fetchSlackIntegrationChannels(id),
enabled: Boolean(id)
});
@@ -9,6 +9,11 @@ export type SlackIntegration = {
teamName: string;
};
export type SlackIntegrationChannel = {
id: string;
name: string;
};
export type TUpdateSlackIntegrationDTO = {
id: string;
orgId: string;