2024-08-16 23:10:19 +07:00
|
|
|
import api from "@/lib/api";
|
|
|
|
|
import {
|
|
|
|
|
useMutation,
|
|
|
|
|
UseMutationOptions,
|
|
|
|
|
useQuery,
|
|
|
|
|
} from "@tanstack/react-query";
|
|
|
|
|
import { Key } from "./types";
|
|
|
|
|
import { CreateKeySchema } from "./schema";
|
|
|
|
|
|
|
|
|
|
export const useKeys = () => {
|
|
|
|
|
return useQuery({
|
|
|
|
|
queryKey: ["keys"],
|
2025-07-15 15:59:47 +08:00
|
|
|
queryFn: () => api.get<Key[]>("/v2/ListKeys"),
|
2024-08-16 23:10:19 +07:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const useCreateKey = (
|
2025-07-15 15:59:47 +08:00
|
|
|
options?: UseMutationOptions<unknown, Error, CreateKeySchema>
|
2024-08-16 23:10:19 +07:00
|
|
|
) => {
|
|
|
|
|
return useMutation({
|
|
|
|
|
mutationFn: async (body) => {
|
|
|
|
|
if (body.isImport) {
|
2025-07-15 15:59:47 +08:00
|
|
|
return api.post("/v2/ImportKey", { body });
|
2024-08-16 23:10:19 +07:00
|
|
|
}
|
2025-07-15 15:59:47 +08:00
|
|
|
return api.post("/v2/CreateKey", { body });
|
2024-08-16 23:10:19 +07:00
|
|
|
},
|
|
|
|
|
...options,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const useRemoveKey = (
|
2025-07-15 15:59:47 +08:00
|
|
|
options?: UseMutationOptions<unknown, Error, string>
|
2024-08-16 23:10:19 +07:00
|
|
|
) => {
|
|
|
|
|
return useMutation({
|
2025-07-31 18:10:39 -04:00
|
|
|
mutationFn: (id) => api.post("/v2/DeleteKey", { params: { id } }),
|
2024-08-16 23:10:19 +07:00
|
|
|
...options,
|
|
|
|
|
});
|
|
|
|
|
};
|