feat: admin provider UI (types, hooks, guard, settings panel, conditional admin nav)

This commit is contained in:
2026-03-16 03:38:37 +01:00
parent 87f94fcc51
commit 89036ba62d
8 changed files with 367 additions and 26 deletions

View File

@@ -0,0 +1,52 @@
"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),
});
}