mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 21:37:59 +00:00
feat(ui): added dynamic secret and lease api hook
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { dynamicSecretKeys } from "./queries";
|
||||
import {
|
||||
TCreateDynamicSecretDTO,
|
||||
TDeleteDynamicSecretDTO,
|
||||
TDynamicSecret,
|
||||
TUpdateDynamicSecretDTO
|
||||
} from "./types";
|
||||
|
||||
export const useCreateDynamicSecret = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<{}, {}, TCreateDynamicSecretDTO>({
|
||||
mutationFn: async (dto) => {
|
||||
const { data } = await apiRequest.post<{ dynamicSecret: TDynamicSecret }>(
|
||||
"/api/v1/dynamic-secrets",
|
||||
dto
|
||||
);
|
||||
return data.dynamicSecret;
|
||||
},
|
||||
onSuccess: (_, { path, environment, projectId }) => {
|
||||
queryClient.invalidateQueries(dynamicSecretKeys.list({ path, projectId, environment }));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateDynamicSecret = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<{}, {}, TUpdateDynamicSecretDTO>({
|
||||
mutationFn: async (dto) => {
|
||||
const { data } = await apiRequest.patch<{ dynamicSecret: TDynamicSecret }>(
|
||||
`/api/v1/dynamic-secrets/${dto.slug}`,
|
||||
dto
|
||||
);
|
||||
return data.dynamicSecret;
|
||||
},
|
||||
onSuccess: (_, { path, environment, projectId }) => {
|
||||
queryClient.invalidateQueries(dynamicSecretKeys.list({ path, projectId, environment }));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteDynamicSecret = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<{}, {}, TDeleteDynamicSecretDTO>({
|
||||
mutationFn: async (dto) => {
|
||||
const { data } = await apiRequest.delete<{ dynamicSecret: TDynamicSecret }>(
|
||||
`/api/v1/dynamic-secrets/${dto.slug}`,
|
||||
{ data: dto }
|
||||
);
|
||||
return data.dynamicSecret;
|
||||
},
|
||||
onSuccess: (_, { path, environment, projectId }) => {
|
||||
queryClient.invalidateQueries(dynamicSecretKeys.list({ path, projectId, environment }));
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user