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
@@ -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));
}
});
};