Add React Query hooks for Hashicorp Vault config overrides

This commit is contained in:
Ryan Crabbe 2026-02-28 13:38:28 -08:00
parent d8b367b4c7
commit a21ed7528a
2 changed files with 44 additions and 0 deletions

View file

@ -0,0 +1,23 @@
import { getHashicorpVaultConfig } from "@/components/networking";
import { useQuery } from "@tanstack/react-query";
import useAuthorized from "../useAuthorized";
import { createQueryKeys } from "../common/queryKeysFactory";
const hashicorpVaultKeys = createQueryKeys("hashicorpVaultConfig");
export const useHashicorpVaultConfig = () => {
const { accessToken } = useAuthorized();
return useQuery<Record<string, any>>({
queryKey: hashicorpVaultKeys.list({}),
queryFn: async () => {
if (!accessToken) {
throw new Error("Access token is required");
}
return getHashicorpVaultConfig(accessToken);
},
enabled: !!accessToken,
staleTime: 60 * 60 * 1000,
gcTime: 60 * 60 * 1000,
});
};

View file

@ -0,0 +1,21 @@
import { updateHashicorpVaultConfig } from "@/components/networking";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { createQueryKeys } from "../common/queryKeysFactory";
const hashicorpVaultKeys = createQueryKeys("hashicorpVaultConfig");
export const useUpdateHashicorpVaultConfig = (accessToken: string) => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async (config: Record<string, any>) => {
if (!accessToken) {
throw new Error("Access token is required");
}
return updateHashicorpVaultConfig(accessToken, config);
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: hashicorpVaultKeys.all });
},
});
};