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
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.
93 lines
2.8 KiB
TypeScript
93 lines
2.8 KiB
TypeScript
/**
|
|
* ENTERPRISE Plan & Usage manager (Epic 3 Billing Platform). Lists the caller's
|
|
* workspaces and, on selecting one, opens its Plan & Usage detail (current plan,
|
|
* plan entitlements, this period's usage vs limit, and — for billing managers —
|
|
* an upgrade CTA that opens a Stripe checkout).
|
|
*
|
|
* Every read/write is authorised + tenant-scoped server-side: entitlements and
|
|
* usage are workspace-membership reads; starting a subscription is gated on
|
|
* `billing.manage`. The client only mirrors what the API returns for the ONE
|
|
* selected workspace — a caller can never see another tenant's plan or usage. No
|
|
* secrets live here; auth flows through the shared api client as `x-api-key`.
|
|
*/
|
|
|
|
import { useCallback, useMemo, useState } from "react";
|
|
import { StyleSheet, Text, View } from "react-native";
|
|
|
|
import { listMyWorkspaces } from "@/lib/api";
|
|
import type { Workspace } from "@/lib/types";
|
|
|
|
import { PlanUsageView } from "@/components/billing/PlanUsageView";
|
|
import { Section, SectionState } from "@/components/me/Section";
|
|
import { colors } from "@/components/me/theme";
|
|
import { useResource } from "@/components/me/use-resource";
|
|
import { WorkspaceCard } from "@/components/team/WorkspaceCard";
|
|
|
|
interface PlanUsageManagerProps {
|
|
token: string | undefined;
|
|
}
|
|
|
|
export function PlanUsageManager({ token }: PlanUsageManagerProps) {
|
|
const workspacesFetcher = useCallback(
|
|
() => listMyWorkspaces({ token }),
|
|
[token],
|
|
);
|
|
const { status, data, error, reload } =
|
|
useResource<Workspace[]>(workspacesFetcher);
|
|
|
|
const [selectedId, setSelectedId] = useState<string | null>(null);
|
|
|
|
const selected = useMemo(
|
|
() => (data ?? []).find((w) => w.id === selectedId) ?? null,
|
|
[data, selectedId],
|
|
);
|
|
|
|
const workspaces = data ?? [];
|
|
|
|
if (selected) {
|
|
return (
|
|
<PlanUsageView
|
|
workspace={selected}
|
|
token={token}
|
|
onBack={() => setSelectedId(null)}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<View style={styles.container}>
|
|
<Section title="WORKSPACES">
|
|
<SectionState status={status} error={error} onRetry={reload}>
|
|
{workspaces.length === 0 ? (
|
|
<Text style={styles.empty}>
|
|
No workspaces yet. Create one in Team & Workspaces to see its plan and
|
|
usage.
|
|
</Text>
|
|
) : (
|
|
<View style={styles.list}>
|
|
{workspaces.map((workspace) => (
|
|
<WorkspaceCard
|
|
key={workspace.id}
|
|
workspace={workspace}
|
|
onPress={(w) => setSelectedId(w.id)}
|
|
/>
|
|
))}
|
|
</View>
|
|
)}
|
|
</SectionState>
|
|
</Section>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: { gap: 4 },
|
|
list: { gap: 10 },
|
|
empty: {
|
|
color: colors.muted,
|
|
fontSize: 13,
|
|
lineHeight: 18,
|
|
paddingVertical: 8,
|
|
},
|
|
});
|