diff --git a/apps/web/components/settings/billing.tsx b/apps/web/components/settings/billing.tsx index fcf450bc..8de02cf1 100644 --- a/apps/web/components/settings/billing.tsx +++ b/apps/web/components/settings/billing.tsx @@ -4,35 +4,41 @@ import { dmSans125ClassName } from "@/lib/fonts" import { calculateUsagePercent } from "@/lib/billing-utils" import { PLAN_DISPLAY_NAMES, useTokenUsage } from "@/hooks/use-token-usage" import { cn } from "@lib/utils" +import { useAuth } from "@lib/auth-context" import { Dialog, DialogClose, DialogContent, DialogTrigger, } from "@ui/components/dialog" -import { useQueryClient } from "@tanstack/react-query" -import { useCustomer, useListPlans } from "autumn-js/react" +import { Coins as PhosphorCoins } from "@phosphor-icons/react" +import { useQuery, useQueryClient } from "@tanstack/react-query" +import { useCustomer } from "autumn-js/react" import { - Check, CreditCard, ExternalLink, LoaderIcon, + Plus, ReceiptText, Settings, X, Zap, } from "lucide-react" -import { useEffect, useMemo, useState } from "react" +import { type ComponentType, useEffect, useMemo, useState } from "react" import { toast } from "sonner" const API_BASE = process.env.NEXT_PUBLIC_BACKEND_URL ?? "https://api.supermemory.ai" const CREDIT_FEATURE_ID = "usd_credits" -const FALLBACK_TOP_UP_PLAN_ID = "api_topup" -const TOP_UP_AMOUNTS = [10, 25, 50] as const +const TOP_UP_PLAN_ID = "credits_topup" +const TOP_UP_AMOUNTS = [10, 25, 50, 100] as const const AUTO_TOP_UP_THRESHOLDS = [2, 5, 10] as const const AUTO_TOP_UP_AMOUNTS = [10, 25, 50] as const +const ConsoleCoinsIcon = PhosphorCoins as unknown as ComponentType<{ + className?: string + weight?: "light" +}> type BillingInvoice = { planIds?: string[] @@ -44,19 +50,26 @@ type BillingInvoice = { hostedInvoiceUrl?: string | null } -type BillingAutoTopup = { +type AutoTopupConfig = { featureId: string enabled: boolean threshold: number quantity: number - invoiceMode?: boolean - purchaseLimit?: { + purchaseLimit: { interval: "hour" | "day" | "week" | "month" - intervalCount?: number + intervalCount: number limit: number - } + } | null } +type AutoTopupsResponse = + | { + ok: true + hasPaymentMethod: boolean + autoTopup: AutoTopupConfig | null + } + | { ok: false; reason: string; message?: string } + function SectionTitle({ children, aside, @@ -133,8 +146,14 @@ function FieldSelect({ onChange: (value: number) => void disabled?: boolean }) { + const cols = values.length <= 3 ? "grid-cols-3" : "grid-cols-4" return ( -