import { createFileRoute, Link } from "@tanstack/react-router"; import { useCustomer, useListPlans } from "autumn-js/react"; import { trackEvent } from "@executor-js/react/api/analytics"; import { Button } from "@executor-js/react/components/button"; import { Badge } from "@executor-js/react/components/badge"; import { PageContainer, PageHeader } from "@executor-js/react/components/page"; type Plan = NonNullable["data"]>[number]; export const Route = createFileRoute("/{-$orgSlug}/billing")({ component: BillingPage, }); const PLAN_TAGLINES: Record = { free: "Free for up to 3 members", team: "$15 per member per month", enterprise: "Custom enterprise agreement", }; function BillingPage() { const { data: customer, openCustomerPortal, isLoading: customerLoading } = useCustomer(); const { data: plans, isLoading: plansLoading } = useListPlans(); if (customerLoading || plansLoading) { return (
); } const allPlans: Plan[] = plans ?? []; const activePlan = allPlans.find( (p) => p.customerEligibility?.status === "active" && p.id !== "free", ); const scheduledPlan = allPlans.find( (p) => p.customerEligibility?.status === "scheduled" && p.id !== "free", ); const isCanceling = activePlan?.customerEligibility?.canceling ?? false; const isSwitching = isCanceling && scheduledPlan != null; const isTrialing = activePlan?.customerEligibility?.trialing ?? false; const displayPlan = isSwitching ? scheduledPlan : activePlan; const planId = displayPlan?.id ?? "free"; const planName = displayPlan?.name ?? "Free"; const tagline = PLAN_TAGLINES[planId] ?? ""; const sub = customer?.subscriptions?.find( (s) => s.planId === (activePlan?.id ?? "free") && (s.status === "active" || s.status === "trialing"), ); const executions = customer?.balances?.executions; const members = customer?.balances?.members; return ( {/* Current plan */}

{planName}

{isSwitching && Switching} {isCanceling && !isSwitching && ( Canceling )} {isTrialing && !isCanceling && ( Free trial )}

{isSwitching && sub?.currentPeriodEnd ? `Starts ${new Date(sub.currentPeriodEnd).toLocaleDateString(undefined, { month: "long", day: "numeric", year: "numeric" })}` : isCanceling && sub?.currentPeriodEnd ? `Access until ${new Date(sub.currentPeriodEnd).toLocaleDateString(undefined, { month: "long", day: "numeric", year: "numeric" })}` : isTrialing && sub?.currentPeriodEnd ? `Trial ends, then billing starts ${new Date(sub.currentPeriodEnd).toLocaleDateString(undefined, { month: "long", day: "numeric", year: "numeric" })}` : sub?.currentPeriodEnd ? `Renews ${new Date(sub.currentPeriodEnd).toLocaleDateString(undefined, { month: "long", day: "numeric", year: "numeric" })}` : tagline}

{activePlan && !isCanceling && ( )} trackEvent("billing_manage_opened")} className="rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground transition-colors hover:bg-primary/90" > Manage
{/* Divider */}
{/* Usage */} {members && (

Members

{members.usage.toLocaleString()} {!members.unlimited && ( {" / "} {members.granted.toLocaleString()} )}

)} {executions && (

Executions

{executions.usage.toLocaleString()} {!executions.unlimited && ( {" / "} {executions.granted.toLocaleString()} this month )}

{!executions.unlimited && executions.granted > 0 && (
)}
)} ); }