mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 02:16:34 +00:00
Added pki collection table, pki alert modal
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
export { useCreateAlert, useDeleteAlert,useUpdateAlert } from "./mutations";
|
||||
export { useGetAlertById } from "./queries";
|
||||
@@ -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)
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
export type TPkiAlert = {
|
||||
id: string;
|
||||
name: string;
|
||||
projectId: string;
|
||||
pkiCollectionId: string;
|
||||
alertBeforeDays: number;
|
||||
recipientEmails: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type TCreatePkiAlertDTO = {
|
||||
projectId: string;
|
||||
name: string;
|
||||
pkiCollectionId: string;
|
||||
alertBeforeDays: number;
|
||||
emails: string[];
|
||||
};
|
||||
|
||||
export type TUpdatePkiAlertDTO = {
|
||||
alertId: string;
|
||||
projectId: string;
|
||||
pkiCollectionId?: string;
|
||||
name?: string;
|
||||
alertBeforeDays?: number;
|
||||
emails?: string[];
|
||||
};
|
||||
|
||||
export type TDeletePkiAlertDTO = {
|
||||
alertId: string;
|
||||
projectId: string;
|
||||
};
|
||||
Reference in New Issue
Block a user