videogen/apps/web/components/workspace/WorkspaceBillingSummary.tsx
caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

94 lines
3.3 KiB
TypeScript

"use client";
import * as React from "react";
import Link from "next/link";
import { AlertTriangle, ArrowUpRight, CreditCard } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Card, CardContent } from "@/components/ui/card";
import { Skeleton } from "@/components/ui/skeleton";
import { EntitlementsCard } from "@/components/billing/EntitlementsCard";
import { UsageMeters } from "@/components/billing/UsageMeters";
import { useWorkspaceBilling } from "@/lib/use-workspace-billing";
import { useWorkspacePermissions } from "@/lib/use-workspace-permissions";
export interface WorkspaceBillingSummaryProps {
/** The selected workspace, or `null` while none is chosen. */
workspaceId: string | null;
}
/**
* A read-only plan + usage snapshot for the selected workspace, shown beneath
* the members pane on the Workspaces surface. Entitlements and usage are
* membership reads (any member sees them); the "Manage billing" link only
* appears for callers who hold `billing.manage`. Tenant-scoped — every read is
* keyed to `workspaceId`, so no other workspace's numbers ever appear.
*/
export function WorkspaceBillingSummary({
workspaceId,
}: Readonly<WorkspaceBillingSummaryProps>) {
const perms = useWorkspacePermissions(workspaceId);
const canManage = perms.has("billing.manage");
const { status, entitlements, usage, errorMessage, period } =
useWorkspaceBilling(workspaceId, canManage);
if (!workspaceId) return null;
return (
<section aria-labelledby="workspace-billing" className="space-y-4">
<div className="flex items-center justify-between gap-4">
<h2
id="workspace-billing"
className="flex items-center gap-2 text-lg font-semibold tracking-tight"
>
<CreditCard className="size-5 text-primary" aria-hidden />
Plan &amp; usage
</h2>
{canManage && (
<Button asChild variant="outline" size="sm">
<Link href="/settings/billing">
Manage billing
<ArrowUpRight className="size-4" aria-hidden />
</Link>
</Button>
)}
</div>
{(status === "loading" || status === "idle") && (
<div className="grid gap-4 lg:grid-cols-2">
<Skeleton className="h-56 w-full rounded-lg" />
<Skeleton className="h-56 w-full rounded-lg" />
</div>
)}
{status === "error" && (
<Card className="border-destructive/40 bg-destructive/5">
<CardContent className="flex items-start gap-3 p-6">
<AlertTriangle
className="mt-0.5 size-5 shrink-0 text-destructive"
aria-hidden
/>
<div>
<p className="font-medium">Couldn&apos;t load billing details</p>
<p className="text-sm text-muted-foreground">{errorMessage}</p>
</div>
</CardContent>
</Card>
)}
{status === "ready" && (
<>
{errorMessage && (
<p className="text-sm text-muted-foreground" role="status">
Some billing details couldn&apos;t be loaded: {errorMessage}
</p>
)}
<div className="grid gap-4 lg:grid-cols-2">
<EntitlementsCard entitlements={entitlements} />
<UsageMeters usage={usage} period={period} />
</div>
</>
)}
</section>
);
}