mirror of
https://github.com/khairul169/vaulterm.git
synced 2025-04-29 00:59:40 +07:00
26 lines
697 B
TypeScript
26 lines
697 B
TypeScript
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
import { FormSchema } from "../schema/form";
|
|
import api, { queryClient } from "@/lib/api";
|
|
|
|
export const useKeychains = () => {
|
|
return useQuery({
|
|
queryKey: ["keychains"],
|
|
queryFn: () => api("/keychains"),
|
|
select: (i) => i.rows,
|
|
});
|
|
};
|
|
|
|
export const useSaveHost = () => {
|
|
return useMutation({
|
|
mutationFn: async (body: FormSchema) => {
|
|
return body.id
|
|
? api(`/hosts/${body.id}`, { method: "PUT", body })
|
|
: api(`/hosts`, { method: "POST", body });
|
|
},
|
|
onError: (e) => console.error(e),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ["hosts"] });
|
|
},
|
|
});
|
|
};
|