mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-07 02:58:11 +00:00
The subscription check on plugins, connections, and usage pages was hardcoded to only look at `api_pro`. Users on scale or enterprise plans saw "Upgrade to Pro" and couldn't create plugin keys or manage connections. Also, the check only looked at product `status` but not the `allowed` flag from autumn — so users who downgraded but were still in their billing period got locked out early.
37 lines
988 B
TypeScript
37 lines
988 B
TypeScript
import {
|
|
DEFAULT_SUBSCRIPTION_STATUS,
|
|
fetchMemoriesFeature,
|
|
fetchSubscriptionStatus,
|
|
isAllowedFrom,
|
|
} from "@lib/queries"
|
|
import type { useCustomer } from "autumn-js/react"
|
|
|
|
export function useMemoriesUsage(autumn: ReturnType<typeof useCustomer>) {
|
|
const {
|
|
data: status = DEFAULT_SUBSCRIPTION_STATUS,
|
|
isLoading: isCheckingStatus,
|
|
} = fetchSubscriptionStatus(autumn, !autumn.isLoading)
|
|
|
|
const hasProProduct = isAllowedFrom(status, "api_pro")
|
|
|
|
const { data: memoriesCheck, isLoading: isLoadingMemories } =
|
|
fetchMemoriesFeature(autumn, !isCheckingStatus && !autumn.isLoading)
|
|
|
|
const memoriesUsed = memoriesCheck?.usage ?? 0
|
|
const memoriesLimit = memoriesCheck?.included_usage ?? 0
|
|
|
|
const isLoading = autumn.isLoading || isCheckingStatus || isLoadingMemories
|
|
|
|
const usagePercent =
|
|
memoriesLimit <= 0
|
|
? 0
|
|
: Math.min(Math.max((memoriesUsed / memoriesLimit) * 100, 0), 100)
|
|
|
|
return {
|
|
memoriesUsed,
|
|
memoriesLimit,
|
|
hasProProduct,
|
|
isLoading,
|
|
usagePercent,
|
|
}
|
|
}
|