// Langfuse Cloud only import { api } from "@/src/utils/api"; import { MarkerBar } from "@tremor/react"; import { useQueryOrganization } from "@/src/features/organizations/hooks"; import { Card } from "@/src/components/ui/card"; import { numberFormatter, compactNumberFormatter } from "@/src/utils/numbers"; import { type Plan } from "@langfuse/shared"; import { MAX_EVENTS_FREE_PLAN } from "@/src/ee/features/billing/constants"; export const BillingUsageChart = () => { const organization = useQueryOrganization(); const usage = api.cloudBilling.getUsage.useQuery( { orgId: organization?.id as string, }, { enabled: organization !== undefined, trpc: { context: { skipBatch: true, }, }, }, ); const hobbyPlanLimit = organization?.cloudConfig?.monthlyObservationLimit ?? MAX_EVENTS_FREE_PLAN; const plan: Plan = organization?.plan ?? "cloud:hobby"; const usageType = usage.data?.usageType ? usage.data.usageType.charAt(0).toUpperCase() + usage.data.usageType.slice(1) : "Events"; if (usage.data === null) { // Might happen in dev mode if STRIPE_SECRET_KEY is not set // This avoids errors for all developers not working on or testing the billing features return null; } return (
{usage.data !== undefined ? ( <>

{usage.data.billingPeriod ? `${usageType} in current billing period (updated about once every 60 minutes)` : `${usageType} / last 30d`}

{numberFormatter(usage.data.usageCount, 0)}
{plan === "cloud:hobby" && ( <>
{`${numberFormatter((usage.data.usageCount / hobbyPlanLimit) * 100)}%`} Plan limit: {compactNumberFormatter(hobbyPlanLimit)}
)} ) : ( Loading (might take a moment) ... )}
); };