mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 05:13:43 +00:00
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
|
|
import { apiRequest } from "@app/config/request";
|
|
|
|
import { workspaceKeys } from "../workspace";
|
|
import { TCertificate, TDeleteCertDTO, TRevokeCertDTO } from "./types";
|
|
|
|
export const useDeleteCert = () => {
|
|
const queryClient = useQueryClient();
|
|
return useMutation<TCertificate, object, TDeleteCertDTO>({
|
|
mutationFn: async ({ serialNumber }) => {
|
|
const {
|
|
data: { certificate }
|
|
} = await apiRequest.delete<{ certificate: TCertificate }>(
|
|
`/api/v1/pki/certificates/${serialNumber}`
|
|
);
|
|
return certificate;
|
|
},
|
|
onSuccess: (_, { projectSlug }) => {
|
|
queryClient.invalidateQueries({
|
|
queryKey: workspaceKeys.forWorkspaceCertificates(projectSlug)
|
|
});
|
|
}
|
|
});
|
|
};
|
|
|
|
export const useRevokeCert = () => {
|
|
const queryClient = useQueryClient();
|
|
return useMutation<TCertificate, object, TRevokeCertDTO>({
|
|
mutationFn: async ({ serialNumber, revocationReason }) => {
|
|
const {
|
|
data: { certificate }
|
|
} = await apiRequest.post<{ certificate: TCertificate }>(
|
|
`/api/v1/pki/certificates/${serialNumber}/revoke`,
|
|
{
|
|
revocationReason
|
|
}
|
|
);
|
|
return certificate;
|
|
},
|
|
onSuccess: (_, { projectSlug }) => {
|
|
queryClient.invalidateQueries({
|
|
queryKey: workspaceKeys.forWorkspaceCertificates(projectSlug)
|
|
});
|
|
}
|
|
});
|
|
};
|