Added pki collection table, pki alert modal

This commit is contained in:
Tuan Dang
2024-08-07 17:09:07 -07:00
parent 1690a9429c
commit 556e4d62c4
44 changed files with 1442 additions and 244 deletions
@@ -1,48 +0,0 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { workspaceKeys } from "../workspace/queries";
import { alertKeys } from "./queries";
import { TAlert, TCreateAlertDTO, TDeleteAlertDTO,TUpdateAlertDTO } from "./types";
export const useCreateAlert = () => {
const queryClient = useQueryClient();
return useMutation<TAlert, {}, TCreateAlertDTO>({
mutationFn: async (body) => {
const { data: alert } = await apiRequest.post<TAlert>("/api/v1/alerts", body);
return alert;
},
onSuccess: (_, { projectId }) => {
queryClient.invalidateQueries(workspaceKeys.getWorkspaceAlerts(projectId));
}
});
};
export const useUpdateAlert = () => {
const queryClient = useQueryClient();
return useMutation<TAlert, {}, TUpdateAlertDTO>({
mutationFn: async ({ alertId, ...body }) => {
const { data: alert } = await apiRequest.patch<TAlert>(`/api/v1/alerts/${alertId}`, body);
return alert;
},
onSuccess: (_, { projectId, alertId }) => {
queryClient.invalidateQueries(workspaceKeys.getWorkspaceAlerts(projectId));
queryClient.invalidateQueries(alertKeys.getAlertById(alertId));
}
});
};
export const useDeleteAlert = () => {
const queryClient = useQueryClient();
return useMutation<TAlert, {}, TDeleteAlertDTO>({
mutationFn: async ({ alertId }) => {
const { data: alert } = await apiRequest.delete<TAlert>(`/api/v1/alerts/${alertId}`);
return alert;
},
onSuccess: (_, { projectId, alertId }) => {
queryClient.invalidateQueries(workspaceKeys.getWorkspaceAlerts(projectId));
queryClient.invalidateQueries(alertKeys.getAlertById(alertId));
}
});
};
-20
View File
@@ -1,20 +0,0 @@
import { useQuery } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { TAlert } from "./types";
export const alertKeys = {
getAlertById: (alertId: string) => [{ alertId }, "alert"]
};
export const useGetAlertById = (alertId: string) => {
return useQuery({
queryKey: alertKeys.getAlertById(alertId),
queryFn: async () => {
const { data: alert } = await apiRequest.get<TAlert>(`/api/v1/alerts/${alertId}`);
return alert;
},
enabled: Boolean(alertId)
});
};
+2 -1
View File
@@ -1,6 +1,5 @@
export * from "./accessApproval";
export * from "./admin";
export * from "./alerts";
export * from "./apiKeys";
export * from "./auditLogs";
export * from "./auditLogStreams";
@@ -22,6 +21,8 @@ export * from "./ldapConfig";
export * from "./oidcConfig";
export * from "./orgAdmin";
export * from "./organization";
export * from "./pkiAlerts";
export * from "./pkiCollections";
export * from "./projectUserAdditionalPrivilege";
export * from "./rateLimit";
export * from "./roles";
@@ -0,0 +1,51 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { workspaceKeys } from "../workspace/queries";
import { pkiAlertKeys } from "./queries";
import { TCreatePkiAlertDTO, TDeletePkiAlertDTO, TPkiAlert, TUpdatePkiAlertDTO } from "./types";
export const useCreateAlert = () => {
const queryClient = useQueryClient();
return useMutation<TPkiAlert, {}, TCreatePkiAlertDTO>({
mutationFn: async (body) => {
const { data: alert } = await apiRequest.post<TPkiAlert>("/api/v1/pki/alerts", body);
return alert;
},
onSuccess: (_, { projectId }) => {
queryClient.invalidateQueries(workspaceKeys.getWorkspacePkiAlerts(projectId));
}
});
};
export const useUpdateAlert = () => {
const queryClient = useQueryClient();
return useMutation<TPkiAlert, {}, TUpdatePkiAlertDTO>({
mutationFn: async ({ alertId, ...body }) => {
const { data: alert } = await apiRequest.patch<TPkiAlert>(
`/api/v1/pki/alerts/${alertId}`,
body
);
return alert;
},
onSuccess: (_, { projectId, alertId }) => {
queryClient.invalidateQueries(workspaceKeys.getWorkspacePkiAlerts(projectId));
queryClient.invalidateQueries(pkiAlertKeys.getPkiAlertById(alertId));
}
});
};
export const useDeleteAlert = () => {
const queryClient = useQueryClient();
return useMutation<TPkiAlert, {}, TDeletePkiAlertDTO>({
mutationFn: async ({ alertId }) => {
const { data: alert } = await apiRequest.delete<TPkiAlert>(`/api/v1/pki/alerts/${alertId}`);
return alert;
},
onSuccess: (_, { projectId, alertId }) => {
queryClient.invalidateQueries(workspaceKeys.getWorkspacePkiAlerts(projectId));
queryClient.invalidateQueries(pkiAlertKeys.getPkiAlertById(alertId));
}
});
};
@@ -0,0 +1,20 @@
import { useQuery } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { TPkiAlert } from "./types";
export const pkiAlertKeys = {
getPkiAlertById: (alertId: string) => [{ alertId }, "alert"]
};
export const useGetAlertById = (alertId: string) => {
return useQuery({
queryKey: pkiAlertKeys.getPkiAlertById(alertId),
queryFn: async () => {
const { data: alert } = await apiRequest.get<TPkiAlert>(`/api/v1/pki/alerts/${alertId}`);
return alert;
},
enabled: Boolean(alertId)
});
};
@@ -1,29 +1,32 @@
export type TAlert = {
export type TPkiAlert = {
id: string;
name: string;
projectId: string;
pkiCollectionId: string;
alertBeforeDays: number;
recipientEmails: string;
createdAt: string;
updatedAt: string;
};
export type TCreateAlertDTO = {
export type TCreatePkiAlertDTO = {
projectId: string;
name: string;
pkiCollectionId: string;
alertBeforeDays: number;
emails: string[];
};
export type TUpdateAlertDTO = {
export type TUpdatePkiAlertDTO = {
alertId: string;
projectId: string;
pkiCollectionId?: string;
name?: string;
alertBeforeDays?: number;
emails?: string[];
};
export type TDeleteAlertDTO = {
export type TDeletePkiAlertDTO = {
alertId: string;
projectId: string;
};
@@ -0,0 +1,5 @@
export {
useCreatePkiCollection,
useDeletePkiCollection,
useUpdatePkiCollection} from "./mutations";
export { useGetPkiCollectionById } from "./queries";
@@ -0,0 +1,64 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { workspaceKeys } from "../workspace/queries";
// import { alertKeys } from "./queries";
// import { TAlert, TCreateAlertDTO, TDeleteAlertDTO, TUpdateAlertDTO } from "./types";
import { pkiCollectionKeys } from "./queries";
import {
TCreatePkiCollectionDTO,
TDeletePkiCollectionDTO,
TPkiCollection,
TUpdatePkiCollectionTO} from "./types";
export const useCreatePkiCollection = () => {
const queryClient = useQueryClient();
return useMutation<TPkiCollection, {}, TCreatePkiCollectionDTO>({
mutationFn: async (body) => {
const { data: pkiCollection } = await apiRequest.post<TPkiCollection>(
"/api/v1/pki/collections",
body
);
return pkiCollection;
},
onSuccess: (_, { projectId }) => {
queryClient.invalidateQueries(workspaceKeys.getWorkspacePkiCollections(projectId));
}
});
};
export const useUpdatePkiCollection = () => {
const queryClient = useQueryClient();
return useMutation<TPkiCollection, {}, TUpdatePkiCollectionTO>({
mutationFn: async ({ collectionId, ...body }) => {
const { data: pkiCollection } = await apiRequest.patch<TPkiCollection>(
`/api/v1/pki/collections/${collectionId}`,
body
);
return pkiCollection;
},
onSuccess: (_, { projectId, collectionId }) => {
queryClient.invalidateQueries(workspaceKeys.getWorkspacePkiCollections(projectId));
queryClient.invalidateQueries(pkiCollectionKeys.getPkiCollectionById(collectionId));
}
});
};
export const useDeletePkiCollection = () => {
const queryClient = useQueryClient();
return useMutation<TPkiCollection, {}, TDeletePkiCollectionDTO>({
mutationFn: async ({ collectionId }) => {
const { data: pkiCollection } = await apiRequest.delete<TPkiCollection>(
`/api/v1/pki/collections/${collectionId}`
);
return pkiCollection;
},
onSuccess: (_, { projectId, collectionId }) => {
queryClient.invalidateQueries(workspaceKeys.getWorkspacePkiCollections(projectId));
queryClient.invalidateQueries(pkiCollectionKeys.getPkiCollectionById(collectionId));
}
});
};
// TODO: add PKI Collection Item
@@ -0,0 +1,22 @@
import { useQuery } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { TPkiCollection } from "./types";
export const pkiCollectionKeys = {
getPkiCollectionById: (collectionId: string) => [{ collectionId }, "pki-collection"]
};
export const useGetPkiCollectionById = (collectionId: string) => {
return useQuery({
queryKey: pkiCollectionKeys.getPkiCollectionById(collectionId),
queryFn: async () => {
const { data: pkiCollection } = await apiRequest.get<TPkiCollection>(
`/api/v1/pki/collections/${collectionId}`
);
return pkiCollection;
},
enabled: Boolean(collectionId)
});
};
@@ -0,0 +1,23 @@
export type TPkiCollection = {
id: string;
name: string;
projectId: string;
createdAt: string;
updatedAt: string;
};
export type TCreatePkiCollectionDTO = {
projectId: string;
name: string;
};
export type TUpdatePkiCollectionTO = {
collectionId: string;
projectId: string;
name?: string;
};
export type TDeletePkiCollectionDTO = {
collectionId: string;
projectId: string;
};
+3 -1
View File
@@ -27,10 +27,12 @@ export {
useListWorkspaceCas,
useListWorkspaceCertificates,
useListWorkspaceGroups,
useListWorkspacePkiCollections,
useNameWorkspaceSecrets,
useRenameWorkspace,
useToggleAutoCapitalization,
useUpdateIdentityWorkspaceRole,
useUpdateUserWorkspaceRole,
useUpdateWsEnvironment,
useUpgradeProject} from "./queries";
useUpgradeProject
} from "./queries";
+25 -4
View File
@@ -2,7 +2,6 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { TAlert } from "../alerts/types";
import { CaStatus } from "../ca/enums";
import { TCertificateAuthority } from "../ca/types";
import { TCertificate } from "../certificates/types";
@@ -11,6 +10,8 @@ import { identitiesKeys } from "../identities/queries";
import { IdentityMembership } from "../identities/types";
import { IntegrationAuth } from "../integrationAuth/types";
import { TIntegration } from "../integrations/types";
import { TPkiAlert } from "../pkiAlerts/types";
import { TPkiCollection } from "../pkiCollections/types";
import { EncryptedSecret } from "../secrets/types";
import { userKeys } from "../users/queries";
import { TWorkspaceUser } from "../users/types";
@@ -64,7 +65,9 @@ export const workspaceKeys = {
offset: number;
limit: number;
}) => [...workspaceKeys.forWorkspaceCertificates(slug), { offset, limit }] as const,
getWorkspaceAlerts: (workspaceId: string) => [{ workspaceId }, "workspace-alerts"] as const
getWorkspacePkiAlerts: (workspaceId: string) => [{ workspaceId }, "workspace-alerts"] as const,
getWorkspacePkiCollections: (workspaceId: string) =>
[{ workspaceId }, "workspace-pki-collections"] as const
};
const fetchWorkspaceById = async (workspaceId: string) => {
@@ -606,14 +609,32 @@ export const useListWorkspaceCertificates = ({
export const useListWorkspaceAlerts = ({ workspaceId }: { workspaceId: string }) => {
return useQuery({
queryKey: workspaceKeys.getWorkspaceAlerts(workspaceId),
queryKey: workspaceKeys.getWorkspacePkiAlerts(workspaceId),
queryFn: async () => {
const {
data: { alerts }
} = await apiRequest.get<{ alerts: TAlert[] }>(`/api/v2/workspace/${workspaceId}/alerts`);
} = await apiRequest.get<{ alerts: TPkiAlert[] }>(
`/api/v2/workspace/${workspaceId}/pki-alerts`
);
return { alerts };
},
enabled: Boolean(workspaceId)
});
};
export const useListWorkspacePkiCollections = ({ workspaceId }: { workspaceId: string }) => {
return useQuery({
queryKey: workspaceKeys.getWorkspacePkiCollections(workspaceId),
queryFn: async () => {
const {
data: { collections }
} = await apiRequest.get<{ collections: TPkiCollection[] }>(
`/api/v2/workspace/${workspaceId}/pki-collections`
);
return { collections };
},
enabled: Boolean(workspaceId)
});
};