A Vite + React 18 + TypeScript SPA, same-origin with the API (no CORS, no Go server changes). Full management parity with the urapt CLI: - First-run setup (admin bootstrap via needs_setup), login/logout - Repositories: list, create, tabbed detail (overview edit/delete, members CRUD, distributions/components/architectures manager, package list + .deb upload + detail + delete, apt-config panel) - API tokens: show-once creation + revoke - Admin users: toggle admin / delete - Settings + dark mode Stack: Tailwind + shadcn/ui (New York), React Router v7 (lazy routes), TanStack Query v5, Zustand, Vitest. Hand-written typed API client mirroring shared/api + shared/models. Dev proxy forwards /api + /apt to a local urapt-server; deploy behind nginx/Caddy (see urapt-web/README).
26 lines
805 B
TypeScript
26 lines
805 B
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { createToken, listTokens, revokeToken } from "@/lib/api";
|
|
import type { CreateTokenRequest } from "@/lib/api/types";
|
|
|
|
export const TOKENS_KEY = ["me", "tokens"] as const;
|
|
|
|
export function useTokens() {
|
|
return useQuery({ queryKey: TOKENS_KEY, queryFn: listTokens });
|
|
}
|
|
|
|
export function useCreateToken() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (body: CreateTokenRequest) => createToken(body),
|
|
onSuccess: () => qc.invalidateQueries({ queryKey: TOKENS_KEY }),
|
|
});
|
|
}
|
|
|
|
export function useRevokeToken() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (id: string) => revokeToken(id),
|
|
onSuccess: () => qc.invalidateQueries({ queryKey: TOKENS_KEY }),
|
|
});
|
|
}
|