supermemory/apps/web/hooks/use-org-summaries.ts
MaheshtheDev ac43fe157f fix(web): org plan badges via org-summaries and refresh Nova chat empty state (#968)
Use /v3/auth/org-summaries for per-org plan tiers in settings (same as console v2).
Extract chat empty state, add space-aware subtitle, and use AutoSpaceIcon in selectors.
2026-05-18 23:44:09 +00:00

38 lines
1,013 B
TypeScript

import { useQuery } from "@tanstack/react-query"
import { useAuth } from "@lib/auth-context"
import { normalizePlanType, type PlanType } from "@/hooks/use-token-usage"
const API_BASE =
process.env.NEXT_PUBLIC_BACKEND_URL ?? "https://api.supermemory.ai"
export type OrgSummary = {
orgId: string
plan: PlanType
activeConnectors: number
containerTagCount: number
documentCount: number
}
export function useOrgSummaries() {
const { user } = useAuth()
return useQuery({
queryKey: ["account", "org-summaries"],
queryFn: async (): Promise<OrgSummary[]> => {
const res = await fetch(`${API_BASE}/v3/auth/org-summaries`, {
credentials: "include",
headers: { "X-App-Source": "nova" },
})
if (!res.ok) {
throw new Error("Failed to load organization plans")
}
const data = (await res.json()) as { summaries: OrgSummary[] }
return (data.summaries ?? []).map((s) => ({
...s,
plan: normalizePlanType(s.plan),
}))
},
enabled: !!user?.id,
staleTime: 60 * 1000,
})
}