Checkpoint GitLab integration group support

This commit is contained in:
Tuan Dang
2023-03-09 11:52:34 +07:00
parent 4edfc1e0be
commit 3f3516b7ba
21 changed files with 572 additions and 149 deletions
@@ -1,3 +1,4 @@
export {
useGetIntegrationAuthApps,
useGetIntegrationAuthById} from './queries';
useGetIntegrationAuthById,
useGetIntegrationAuthTeams} from './queries';
@@ -4,11 +4,13 @@ import { apiRequest } from "@app/config/request";
import {
App,
IntegrationAuth} from './types';
IntegrationAuth,
Team} from './types';
const integrationAuthKeys = {
getIntegrationAuthById: (integrationAuthId: string) => [{ integrationAuthId }, 'integrationAuth'] as const,
getIntegrationAuthApps: (integrationAuthId: string) => [{ integrationAuthId }, 'integrationAuthApps'] as const,
getIntegrationAuthApps: (integrationAuthId: string, teamId?: string) => [{ integrationAuthId, teamId }, 'integrationAuthApps'] as const,
getIntegrationAuthTeams: (integrationAuthId: string) => [{ integrationAuthId }, 'integrationAuthTeams'] as const
}
const fetchIntegrationAuthById = async (integrationAuthId: string) => {
@@ -16,11 +18,27 @@ const fetchIntegrationAuthById = async (integrationAuthId: string) => {
return data.integrationAuth;
}
const fetchIntegrationAuthApps = async (integrationAuthId: string) => {
const { data } = await apiRequest.get<{ apps: App[] }>(`/api/v1/integration-auth/${integrationAuthId}/apps`);
const fetchIntegrationAuthApps = async ({
integrationAuthId,
teamId
}: {
integrationAuthId: string;
teamId?: string;
}) => {
console.log('fetchIntegrationAuthApps: ', integrationAuthId);
const searchParams = new URLSearchParams(teamId ? { teamId } : undefined);
const { data } = await apiRequest.get<{ apps: App[] }>(
`/api/v1/integration-auth/${integrationAuthId}/apps`,
{ params: searchParams }
);
return data.apps;
}
const fetchIntegrationAuthTeams = async (integrationAuthId: string) => {
const { data } = await apiRequest.get<{ teams: Team[] }>(`/api/v1/integration-auth/${integrationAuthId}/teams`);
return data.teams;
}
export const useGetIntegrationAuthById = (integrationAuthId: string) => {
return useQuery({
queryKey: integrationAuthKeys.getIntegrationAuthById(integrationAuthId),
@@ -29,10 +47,28 @@ export const useGetIntegrationAuthById = (integrationAuthId: string) => {
});
}
export const useGetIntegrationAuthApps = (integrationAuthId: string) => {
// TODO: fix to teamId
export const useGetIntegrationAuthApps = ({
integrationAuthId,
teamId
}: {
integrationAuthId: string;
teamId?: string;
}) => {
return useQuery({
queryKey: integrationAuthKeys.getIntegrationAuthApps(integrationAuthId),
queryFn: () => fetchIntegrationAuthApps(integrationAuthId),
queryKey: integrationAuthKeys.getIntegrationAuthApps(integrationAuthId, teamId),
queryFn: () => fetchIntegrationAuthApps({
integrationAuthId,
teamId
}),
enabled: true
});
}
export const useGetIntegrationAuthTeams = (integrationAuthId: string) => {
return useQuery({
queryKey: integrationAuthKeys.getIntegrationAuthTeams(integrationAuthId),
queryFn: () => fetchIntegrationAuthTeams(integrationAuthId),
enabled: true
});
}
@@ -10,4 +10,9 @@ export type App = {
name: string;
appId?: string;
owner?: string;
}
export type Team = {
name: string;
teamId: string;
}