mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 07:35:09 +00:00
preliminary ssh host structs, api, ui
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { workspaceKeys } from "../workspace/query-keys";
|
||||
import { TCreateSshHostDTO, TDeleteSshHostDTO, TSshHost, TUpdateSshHostDTO } from "./types";
|
||||
|
||||
export const useCreateSshHost = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TSshHost, object, TCreateSshHostDTO>({
|
||||
mutationFn: async (body) => {
|
||||
const { data: host } = await apiRequest.post("/api/v1/ssh/hosts", body);
|
||||
return host;
|
||||
},
|
||||
onSuccess: ({ projectId }) => {
|
||||
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceSshHosts(projectId) });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateSshHost = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TSshHost, object, TUpdateSshHostDTO>({
|
||||
mutationFn: async ({ sshHostId, ...body }) => {
|
||||
const { data: host } = await apiRequest.patch(`/api/v1/ssh/hosts/${sshHostId}`, body);
|
||||
return host;
|
||||
},
|
||||
onSuccess: ({ projectId }) => {
|
||||
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceSshHosts(projectId) });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteSshHost = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TSshHost, object, TDeleteSshHostDTO>({
|
||||
mutationFn: async ({ sshHostId }) => {
|
||||
const { data: host } = await apiRequest.delete(`/api/v1/ssh/hosts/${sshHostId}`);
|
||||
return host;
|
||||
},
|
||||
onSuccess: ({ projectId }) => {
|
||||
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceSshHosts(projectId) });
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user