The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.
/*
* Copyright 2025 Daytona Platforms Inc.
* Modified by BoxLite AI, 2025-2026
* SPDX-License-Identifier: AGPL-3.0
*/
import { SubscriptionCancellationProvider } from '@/components/billing/SubscriptionCancellation'
import { TabIcon } from '@/components/ui/TabIcon'
import { BalanceLowBanner } from '@/components/billing/BalanceLowBanner'
import { BillingAlerts } from '@/components/billing/BillingAlerts'
import { PlansSection } from '@/components/billing/PlansSection'
import { PlanSection } from '@/components/billing/PlanSection'
import { PlanUpgradeReturn } from '@/components/billing/PlanUpgradeReturn'
import { UsageSection } from '@/components/billing/UsageSection'
import { WalletSection } from '@/components/billing/WalletSection'
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
import { billingTab } from '@/lib/billing-tab'
import { RoutePath } from '@/enums/RoutePath'
import { useConfig } from '@/hooks/useConfig'
import { Clock, Cpu, Database, MemoryStick, type LucideIcon } from '@/components/ui/icon'
import { Link, useSearchParams } from 'react-router-dom'
import { usePageTitle } from '@/hooks/usePageTitle'
import { readPendingPlanUpgrade } from '@/lib/pending-plan-upgrade'
import { useCallback, useState } from 'react'
const TAB_PANE = 'py-6'
const DIMENSIONS: { icon: LucideIcon; name: string; unit: string }[] = [
{ icon: Cpu, name: 'CPU', unit: 'per vCPU·hr' },
{ icon: MemoryStick, name: 'Memory', unit: 'per GiB·hr' },
{ icon: Database, name: 'Disk', unit: 'per GiB·mo' },
{ icon: Clock, name: 'Runtime', unit: 'per second' },
]
function SegBars() {
return (
<div className="mt-3 flex w-full gap-[3px]">
{Array.from({ length: 8 }).map((_, i) => (
<span key={i} className="h-[5px] flex-1 bg-brand/15" />
))}
</div>
)
}
/** Stands in until a billing service is deployed — nothing below it can load without one. */
function BillingComingSoon() {
return (
<div className="flex min-h-[var(--app-content-height,calc(100svh_-_60px))] items-center justify-center px-6 py-14 lg:px-[40px]">
<div className="w-full max-w-[560px] text-center" style={{ animation: 'stat-in 0.5s ease both' }}>
<h1 className="mb-3 text-page font-semibold leading-tight tracking-[-0.5px]">Billing is on the way</h1>
<p className="mx-auto mb-2 max-w-[440px] text-body leading-relaxed text-muted-foreground">
BoxLite is <span className="text-foreground">free while we finish metering</span>. Nothing is charged today —
run as many boxes as you need.
</p>
<p className="mx-auto mb-[30px] max-w-[440px] text-meta leading-relaxed text-muted-foreground">
When billing launches, usage will be metered across four dimensions:
</p>
<div className="mb-[34px] grid grid-cols-4 gap-[10px]">
{DIMENSIONS.map(({ icon: Icon, name, unit }) => (
<div
key={name}
className="flex flex-col items-center gap-[9px] border border-border bg-card px-[10px] pb-[14px] pt-4"
>
<Icon className="size-[18px] text-muted-foreground" strokeWidth={1.6} />
<div className="text-meta uppercase tracking-[1px] text-foreground">{name}</div>
<div className="text-meta tracking-[0.5px] text-muted-foreground">{unit}</div>
<SegBars />
</div>
))}
</div>
<Link
to={RoutePath.BOXES}
className="inline-flex items-center gap-[9px] bg-primary px-[22px] py-3 text-meta font-semibold tracking-[0.3px] text-primary-foreground transition-opacity hover:opacity-85"
>
Back to Boxes
<span className="text-body leading-none">→</span>
</Link>
</div>
</div>
)
}
/**
* One page, four tabs — the arrangement in the design. Each tab is a section
* that keeps its own hooks; this only composes and switches them. Critical wallet
* warnings stay above the tabs; identity and payment guidance stays in Overview.
*/
function Billing() {
usePageTitle('Billing')
const config = useConfig()
const [pendingUpgrade, setPendingUpgrade] = useState(readPendingPlanUpgrade)
const finishUpgradeReturn = useCallback(() => setPendingUpgrade(null), [])
// Controlled, so the page-level balance warning can send the user to Wallet.
const [searchParams, setSearchParams] = useSearchParams()
const tab = billingTab(searchParams)
const setTab = (value: string) =>
setSearchParams((previous) => {
const next = new URLSearchParams(previous)
next.set('tab', value)
return next
})
if (!config.billingApiUrl) {
return <BillingComingSoon />
}
if (pendingUpgrade) {
return <PlanUpgradeReturn selection={pendingUpgrade} onFinish={finishUpgradeReturn} />
}
return (
<SubscriptionCancellationProvider>
<Tabs value={tab} onValueChange={setTab} className="w-full gap-0">
<div className="page-container">
<div className="pt-6">
<h1 className="resource-title">Billing</h1>
<p className="mt-2 text-body leading-relaxed text-muted-foreground">
Track resource usage, manage your plan, and top up your balance.
</p>
<div className="mt-4 w-full empty:hidden">
<BalanceLowBanner onGoToWallet={() => setTab('wallet')} />
</div>
<div className="mt-5 flex items-center gap-3">
<TabsList variant="underline" aria-label="Billing views" className="min-w-0 flex-1 gap-3 sm:gap-6">
<TabsTrigger data-console-action="view_billing_overview" value="overview">
<TabIcon name="overview" />
Overview
</TabsTrigger>
<TabsTrigger data-console-action="view_billing_plans" value="plans">
<TabIcon name="list" />
Plans
</TabsTrigger>
<TabsTrigger data-console-action="view_billing_usage" value="usage">
<TabIcon name="chart" />
Usage
</TabsTrigger>
<TabsTrigger data-console-action="view_billing_wallet" value="wallet">
<TabIcon name="wallet" />
Wallet
</TabsTrigger>
</TabsList>
</div>
</div>
<TabsContent value="overview">
<div className={TAB_PANE}>
<div className="mb-8 flex flex-col gap-4 empty:hidden">
<BillingAlerts />
</div>
<PlanSection onViewPlans={() => setTab('plans')} />
</div>
</TabsContent>
<TabsContent value="plans">
<div className={TAB_PANE}>
<PlansSection />
</div>
</TabsContent>
<TabsContent value="usage">
<div className={TAB_PANE}>
<UsageSection />
</div>
</TabsContent>
<TabsContent value="wallet">
<div className={TAB_PANE}>
<WalletSection
linkCouponCode={searchParams.get('code') ?? undefined}
onCouponClaimAccepted={() =>
// An accepted claim no longer needs its code in the URL.
setSearchParams(
(previous) => {
const next = new URLSearchParams(previous)
next.delete('code')
return next
},
{ replace: true },
)
}
/>
</div>
</TabsContent>
</div>
</Tabs>
</SubscriptionCancellationProvider>
)
}
export default Billing