"use client"; import { useMutation } from "convex/react"; import { useAuthQuery } from "@/hooks/use-auth-query"; import { useTranslations } from "next-intl"; import { api } from "@/convex/_generated/api"; import { Coins } from "lucide-react"; import { toast } from "@/lib/toast"; const TIER_LABELS: Record = { free: "Free", starter: "Starter", pro: "Pro", max: "Max", business: "Business", }; const TIER_COLORS: Record = { free: "text-muted-foreground", starter: "text-blue-500", pro: "text-purple-500", max: "text-amber-500", business: "text-amber-500", }; const showTestCreditGrant = typeof process.env.NEXT_PUBLIC_ALLOW_TEST_CREDIT_GRANT === "string" && process.env.NEXT_PUBLIC_ALLOW_TEST_CREDIT_GRANT === "true"; export function CreditDisplay() { const t = useTranslations('toasts'); const balance = useAuthQuery(api.credits.getBalance); const subscription = useAuthQuery(api.credits.getSubscription); const grantTestCredits = useMutation(api.credits.grantTestCredits); if (balance === undefined || subscription === undefined) { return (
); } const available = balance.balance - balance.reserved; const tier = subscription.tier; const tierLabel = TIER_LABELS[tier] ?? tier; const tierColor = TIER_COLORS[tier] ?? "text-muted-foreground"; const isLow = available < 10; const isEmpty = available <= 0; return (
{available.toLocaleString("de-DE")} Cr {balance.reserved > 0 && ( ({balance.reserved} reserved) )} · {tierLabel}
{showTestCreditGrant && ( )}
); }