feat(ui): added dynamic secret and lease api hook

This commit is contained in:
Akhil Mohan
2024-03-21 20:22:30 +05:30
parent ab48c3b4fe
commit 177cd385cc
14 changed files with 449 additions and 3 deletions
@@ -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 }));
}
});
};