53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { api } from "@/lib/api";
|
|
import { useAuthContext } from "@/context/auth-context";
|
|
|
|
export function useProviderConfigs() {
|
|
const { token } = useAuthContext();
|
|
return useQuery({
|
|
queryKey: ["admin", "providers"],
|
|
queryFn: () => api.admin.providers.getProviders(token!),
|
|
enabled: !!token,
|
|
});
|
|
}
|
|
|
|
export function useUpdateProvider() {
|
|
const { token } = useAuthContext();
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: ({
|
|
type,
|
|
payload,
|
|
}: {
|
|
type: string;
|
|
payload: { config_json: Record<string, string>; enabled: boolean };
|
|
}) => api.admin.providers.updateProvider(token!, type, payload),
|
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["admin", "providers"] }),
|
|
});
|
|
}
|
|
|
|
export function useDeleteProvider() {
|
|
const { token } = useAuthContext();
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (type: string) =>
|
|
api.admin.providers.deleteProvider(token!, type),
|
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["admin", "providers"] }),
|
|
});
|
|
}
|
|
|
|
export function useTestProvider() {
|
|
const { token } = useAuthContext();
|
|
return useMutation({
|
|
mutationFn: ({
|
|
type,
|
|
payload,
|
|
}: {
|
|
type: string;
|
|
payload: { config_json: Record<string, string>; enabled: boolean };
|
|
}) => api.admin.providers.testProvider(token!, type, payload),
|
|
});
|
|
}
|