Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Split organization billing runtime owners

rcourtman2c1a89402b2e
diff --git a/docs/release-control/v6/internal/subsystems/cloud-paid.md b/docs/release-control/v6/internal/subsystems/cloud-paid.md
index 29d3109377..d98a77d86a 100644
--- a/docs/release-control/v6/internal/subsystems/cloud-paid.md
+++ b/docs/release-control/v6/internal/subsystems/cloud-paid.md
@@ -49,13 +49,15 @@ agreement, and cloud-specific enforcement rules.
27. `frontend-modern/src/components/Dashboard/RelayOnboardingCard.tsx`
28. `frontend-modern/src/components/Settings/BillingAdminPanel.tsx`
29. `frontend-modern/src/components/Settings/OrganizationBillingPanel.tsx`
-30. `frontend-modern/src/components/Settings/ProLicensePanel.tsx`
-31. `frontend-modern/src/components/Settings/CommercialBillingSections.tsx`
-32. `frontend-modern/src/components/Settings/SelfHostedCommercialActivationSection.tsx`
-33. `frontend-modern/src/components/Settings/RelaySettingsPanel.tsx`
-34. `frontend-modern/src/pages/CloudPricing.tsx`
-35. `frontend-modern/src/utils/apiClient.ts`
-36. `frontend-modern/src/utils/commercialBillingModel.ts`
+30. `frontend-modern/src/components/Settings/OrganizationBillingLoadingState.tsx`
+31. `frontend-modern/src/components/Settings/ProLicensePanel.tsx`
+32. `frontend-modern/src/components/Settings/CommercialBillingSections.tsx`
+33. `frontend-modern/src/components/Settings/SelfHostedCommercialActivationSection.tsx`
+34. `frontend-modern/src/components/Settings/RelaySettingsPanel.tsx`
+35. `frontend-modern/src/components/Settings/useOrganizationBillingPanelState.ts`
+36. `frontend-modern/src/pages/CloudPricing.tsx`
+37. `frontend-modern/src/utils/apiClient.ts`
+38. `frontend-modern/src/utils/commercialBillingModel.ts`
## Shared Boundaries
@@ -78,7 +80,7 @@ agreement, and cloud-specific enforcement rules.
10. Add or change hosted signup provisioning through `internal/hosted/provisioner.go`
11. Add or change hosted billing-admin presentation through `frontend-modern/src/components/Settings/BillingAdminPanel.tsx`
12. Add or change shared commercial plan/usage presentation through `frontend-modern/src/components/Settings/CommercialBillingSections.tsx` and `frontend-modern/src/utils/commercialBillingModel.ts`
-13. Add or change organization billing and usage presentation through `frontend-modern/src/components/Settings/OrganizationBillingPanel.tsx`
+13. Add or change organization billing and usage presentation through `frontend-modern/src/components/Settings/OrganizationBillingPanel.tsx`, `frontend-modern/src/components/Settings/OrganizationBillingLoadingState.tsx`, and `frontend-modern/src/components/Settings/useOrganizationBillingPanelState.ts`
14. Add or change self-hosted Pro activation, trial, and entitlement actions through `frontend-modern/src/components/Settings/ProLicensePanel.tsx` and `frontend-modern/src/components/Settings/SelfHostedCommercialActivationSection.tsx`
15. Add or change paid relay settings and onboarding presentation through `frontend-modern/src/components/Settings/RelaySettingsPanel.tsx` and `frontend-modern/src/components/Dashboard/RelayOnboardingCard.tsx`
16. Add or change cloud plan presentation through `frontend-modern/src/pages/CloudPricing.tsx`
@@ -200,6 +202,14 @@ That same billing surface now also normalizes org scope through
`frontend-modern/src/utils/orgScope.ts` before it builds per-tenant state, so
cache keys and tenant lookups do not keep a local `getOrgID() || 'default'`
fallback in the hosted billing UI.
+That hosted organization billing owner is now intentionally split by role:
+`frontend-modern/src/components/Settings/OrganizationBillingPanel.tsx` is the
+settings shell, `frontend-modern/src/components/Settings/useOrganizationBillingPanelState.ts`
+owns org-scoped billing/runtime lifecycle and plan/usage model wiring, and
+`frontend-modern/src/components/Settings/OrganizationBillingLoadingState.tsx`
+owns the loading skeleton. Future billing work must extend that split instead
+of pulling org-switch lifecycle and hosted entitlement reads back into the
+panel render shell.
The self-hosted and hosted billing surfaces now also share a canonical
commercial page shell and plan/usage model. `ProLicensePanel.tsx` and
`OrganizationBillingPanel.tsx` may still differ in deployment-specific actions
diff --git a/docs/release-control/v6/internal/subsystems/registry.json b/docs/release-control/v6/internal/subsystems/registry.json
index 7d57e0dcff..31506260fc 100644
--- a/docs/release-control/v6/internal/subsystems/registry.json
+++ b/docs/release-control/v6/internal/subsystems/registry.json
@@ -1094,9 +1094,11 @@
"frontend-modern/src/AppLayout.tsx",
"frontend-modern/src/components/Dashboard/RelayOnboardingCard.tsx",
"frontend-modern/src/components/Settings/BillingAdminPanel.tsx",
+ "frontend-modern/src/components/Settings/OrganizationBillingLoadingState.tsx",
"frontend-modern/src/components/Settings/OrganizationBillingPanel.tsx",
"frontend-modern/src/components/Settings/ProLicensePanel.tsx",
"frontend-modern/src/components/Settings/RelaySettingsPanel.tsx",
+ "frontend-modern/src/components/Settings/useOrganizationBillingPanelState.ts",
"frontend-modern/src/pages/CloudPricing.tsx",
"frontend-modern/src/pages/HostedSignup.tsx",
"frontend-modern/src/useAppRuntimeState.ts",
@@ -1499,7 +1501,9 @@
"label": "organization billing surface proof",
"match_prefixes": [],
"match_files": [
- "frontend-modern/src/components/Settings/OrganizationBillingPanel.tsx"
+ "frontend-modern/src/components/Settings/OrganizationBillingLoadingState.tsx",
+ "frontend-modern/src/components/Settings/OrganizationBillingPanel.tsx",
+ "frontend-modern/src/components/Settings/useOrganizationBillingPanelState.ts"
],
"allow_same_subsystem_tests": false,
"test_prefixes": [],
diff --git a/frontend-modern/src/components/Settings/OrganizationBillingLoadingState.tsx b/frontend-modern/src/components/Settings/OrganizationBillingLoadingState.tsx
new file mode 100644
index 0000000000..d70fb2925a
--- /dev/null
+++ b/frontend-modern/src/components/Settings/OrganizationBillingLoadingState.tsx
@@ -0,0 +1,36 @@
+import type { Component } from 'solid-js';
+
+export const OrganizationBillingLoadingState: Component = () => (
+ <div class="space-y-5">
+ <div class="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
+ {Array.from({ length: 4 }).map(() => (
+ <div class="rounded-md border border-border p-3 space-y-2">
+ <div class="h-3 w-20 animate-pulse rounded bg-surface-hover" />
+ <div class="h-5 w-24 animate-pulse rounded bg-surface-hover" />
+ </div>
+ ))}
+ </div>
+
+ <div class="space-y-3 rounded-md border border-border p-4">
+ <div class="h-4 w-36 animate-pulse rounded bg-surface-hover" />
+ {Array.from({ length: 2 }).map(() => (
+ <div class="space-y-2">
+ <div class="flex items-center justify-between">
+ <div class="h-3 w-14 animate-pulse rounded bg-surface-hover" />
+ <div class="h-3 w-20 animate-pulse rounded bg-surface-hover" />
+ </div>
+ <div class="h-2 w-full animate-pulse rounded bg-surface-hover" />
+ </div>
+ ))}
+ </div>
+
+ <div class="grid gap-3 sm:grid-cols-2">
+ {Array.from({ length: 2 }).map(() => (
+ <div class="rounded-md border border-border p-3 space-y-2">
+ <div class="h-3 w-24 animate-pulse rounded bg-surface-hover" />
+ <div class="h-5 w-40 animate-pulse rounded bg-surface-hover" />
+ </div>
+ ))}
+ </div>
+ </div>
+);
diff --git a/frontend-modern/src/components/Settings/OrganizationBillingPanel.tsx b/frontend-modern/src/components/Settings/OrganizationBillingPanel.tsx
index aa960fc3a7..4925d9029c 100644
--- a/frontend-modern/src/components/Settings/OrganizationBillingPanel.tsx
+++ b/frontend-modern/src/components/Settings/OrganizationBillingPanel.tsx
@@ -1,18 +1,5 @@
-import { Component, For, Show, createSignal, onCleanup, onMount } from 'solid-js';
-import { LicenseAPI, type LicenseStatus } from '@/api/license';
-import { OrgsAPI } from '@/api/orgs';
-import { getOrgID } from '@/utils/apiClient';
-import { normalizeOrgScope } from '@/utils/orgScope';
-import { isMultiTenantEnabled } from '@/stores/license';
-import { eventBus } from '@/stores/events';
-import { notificationStore } from '@/stores/notifications';
-import { logger } from '@/utils/logger';
+import { Component, For, Show } from 'solid-js';
import {
- getLicenseTierLabel,
- getOrganizationBillingLicenseStatusLabel,
-} from '@/utils/licensePresentation';
-import {
- getOrganizationSettingsLoadErrorMessage,
ORGANIZATION_SETTINGS_UNAVAILABLE_CLASS,
ORGANIZATION_SETTINGS_UNAVAILABLE_MESSAGE,
} from '@/utils/organizationSettingsPresentation';
@@ -23,89 +10,19 @@ import {
CommercialStatGrid,
CommercialUsageMeters,
} from './CommercialBillingSections';
+import { OrganizationBillingLoadingState } from './OrganizationBillingLoadingState';
import {
- buildHostedCommercialPlanModel,
- buildHostedCommercialUsageModel,
-} from '@/utils/commercialBillingModel';
-
-export interface OrganizationBillingPanelProps {
- nodeUsage: number;
- guestUsage: number;
-}
-
-const formatDate = (value?: string | null) => {
- if (!value) return 'Never';
- const date = new Date(value);
- if (Number.isNaN(date.getTime())) return value;
- return date.toLocaleDateString();
-};
+ useOrganizationBillingPanelState,
+ type OrganizationBillingPanelProps,
+} from './useOrganizationBillingPanelState';
export const OrganizationBillingPanel: Component<OrganizationBillingPanelProps> = (props) => {
- const [loading, setLoading] = createSignal(true);
- const [status, setStatus] = createSignal<LicenseStatus | null>(null);
- const [orgCount, setOrgCount] = createSignal(0);
- const [memberCount, setMemberCount] = createSignal(0);
- const commercialPlanModel = () =>
- buildHostedCommercialPlanModel({
- status: status(),
- tierLabel: getLicenseTierLabel(status()?.tier || 'free'),
- licenseStatusLabel: getOrganizationBillingLicenseStatusLabel(status()),
- organizationCount: orgCount(),
- memberCount: memberCount(),
- nodeUsage: props.nodeUsage,
- guestUsage: props.guestUsage,
- renewsOrExpires: status()?.is_lifetime
- ? 'Never (Lifetime)'
- : formatDate(status()?.expires_at),
- });
- const commercialUsageModel = () =>
- buildHostedCommercialUsageModel({
- status: status(),
- tierLabel: getLicenseTierLabel(status()?.tier || 'free'),
- licenseStatusLabel: getOrganizationBillingLicenseStatusLabel(status()),
- organizationCount: orgCount(),
- memberCount: memberCount(),
- nodeUsage: props.nodeUsage,
- guestUsage: props.guestUsage,
- renewsOrExpires: status()?.is_lifetime
- ? 'Never (Lifetime)'
- : formatDate(status()?.expires_at),
- });
-
- const loadBillingData = async () => {
- setLoading(true);
- try {
- const activeOrgID = normalizeOrgScope(getOrgID());
- const [licenseStatus, orgs, members] = await Promise.all([
- LicenseAPI.getStatus(),
- OrgsAPI.list(),
- OrgsAPI.listMembers(activeOrgID),
- ]);
- setStatus(licenseStatus);
- setOrgCount(orgs.length);
- setMemberCount(members.length);
- } catch (error) {
- logger.error('Failed to load billing data', error);
- const msg = error instanceof Error ? error.message : '';
- notificationStore.error(getOrganizationSettingsLoadErrorMessage(msg, 'billing'));
- } finally {
- setLoading(false);
- }
- };
-
- onMount(() => {
- if (!isMultiTenantEnabled()) return;
- void loadBillingData();
-
- const unsubscribe = eventBus.on('org_switched', () => {
- void loadBillingData();
- });
- onCleanup(unsubscribe);
- });
+ const { commercialPlanModel, commercialUsageModel, isBillingAvailable, loading } =
+ useOrganizationBillingPanelState(props);
return (
<Show
- when={isMultiTenantEnabled()}
+ when={isBillingAvailable()}
fallback={
<div class={ORGANIZATION_SETTINGS_UNAVAILABLE_CLASS}>
{ORGANIZATION_SETTINGS_UNAVAILABLE_MESSAGE}
@@ -118,75 +35,32 @@ export const OrganizationBillingPanel: Component<OrganizationBillingPanelProps>
description="Review your organization plan, usage against limits, and available upgrade paths."
icon={<CreditCard class="w-5 h-5" />}
loading={loading()}
- loadingFallback={
- <div class="space-y-5">
- <div class="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
- {Array.from({ length: 4 }).map(() => (
- <div class="rounded-md border border-border p-3 space-y-2">
- <div class="h-3 w-20 animate-pulse rounded bg-surface-hover" />
- <div class="h-5 w-24 animate-pulse rounded bg-surface-hover" />
- </div>
- ))}
- </div>
-
- <div class="space-y-3 rounded-md border border-border p-4">
- <div class="h-4 w-36 animate-pulse rounded bg-surface-hover" />
- {Array.from({ length: 2 }).map(() => (
- <div class="space-y-2">
- <div class="flex items-center justify-between">
- <div class="h-3 w-14 animate-pulse rounded bg-surface-hover" />
- <div class="h-3 w-20 animate-pulse rounded bg-surface-hover" />
- </div>
- <div class="h-2 w-full animate-pulse rounded bg-surface-hover" />
- </div>
- ))}
- </div>
-
- <div class="grid gap-3 sm:grid-cols-2">
- {Array.from({ length: 2 }).map(() => (
- <div class="rounded-md border border-border p-3 space-y-2">
- <div class="h-3 w-24 animate-pulse rounded bg-surface-hover" />
- <div class="h-5 w-40 animate-pulse rounded bg-surface-hover" />
- </div>
- ))}
- </div>
- </div>
- }
+ loadingFallback={<OrganizationBillingLoadingState />}
>
<CommercialSection
title="Plan"
description="Review the active organization plan, subscription state, and tenant footprint tied to this billing record."
>
- <CommercialStatGrid
- columns="four"
- items={commercialPlanModel().summary}
- />
+ <CommercialStatGrid columns="four" items={commercialPlanModel().summary} />
- <div class="grid gap-3 sm:grid-cols-2">
- <For each={commercialPlanModel().details}>
- {(item) => (
- <div class="rounded-md border border-border p-3">
- <p class="text-xs uppercase tracking-wide text-muted">{item.label}</p>
- <p class="mt-1 text-sm font-medium text-base-content">
- {item.label === 'Renews / Expires' && status()?.expires_at && !status()?.is_lifetime
- ? formatDate(status()?.expires_at)
- : item.value}
- </p>
- </div>
- )}
- </For>
- </div>
- </CommercialSection>
+ <div class="grid gap-3 sm:grid-cols-2">
+ <For each={commercialPlanModel().details}>
+ {(item) => (
+ <div class="rounded-md border border-border p-3">
+ <p class="text-xs uppercase tracking-wide text-muted">{item.label}</p>
+ <p class="mt-1 text-sm font-medium text-base-content">{item.value}</p>
+ </div>
+ )}
+ </For>
+ </div>
+ </CommercialSection>
<CommercialSection
title="Usage"
description="Compare current agent and guest usage against the active organization allocation."
>
- <CommercialUsageMeters
- title="Usage vs Plan Limits"
- items={commercialUsageModel().meters}
- />
- </CommercialSection>
+ <CommercialUsageMeters title="Usage vs Plan Limits" items={commercialUsageModel().meters} />
+ </CommercialSection>
</CommercialBillingShell>
</div>
</Show>
diff --git a/frontend-modern/src/components/Settings/__tests__/OrganizationBillingPanel.test.tsx b/frontend-modern/src/components/Settings/__tests__/OrganizationBillingPanel.test.tsx
index 5842fa6dc2..987af1ab17 100644
--- a/frontend-modern/src/components/Settings/__tests__/OrganizationBillingPanel.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/OrganizationBillingPanel.test.tsx
@@ -3,12 +3,15 @@ import { cleanup, render, screen, waitFor } from '@solidjs/testing-library';
import { OrganizationBillingPanel } from '../OrganizationBillingPanel';
import organizationBillingPanelSource from '../OrganizationBillingPanel.tsx?raw';
+import organizationBillingLoadingStateSource from '../OrganizationBillingLoadingState.tsx?raw';
+import organizationBillingStateSource from '../useOrganizationBillingPanelState.ts?raw';
const getStatusMock = vi.hoisted(() => vi.fn());
const listOrgsMock = vi.hoisted(() => vi.fn());
const listMembersMock = vi.hoisted(() => vi.fn());
const errorMock = vi.hoisted(() => vi.fn());
-const eventBusOnMock = vi.hoisted(() => vi.fn(() => () => {}));
+const eventBusOnMock = vi.hoisted(() => vi.fn());
+const eventBusHandlers = vi.hoisted(() => [] as Array<() => void>);
vi.mock('@/api/license', () => ({
LicenseAPI: {
@@ -33,7 +36,7 @@ vi.mock('@/stores/license', () => ({
vi.mock('@/stores/events', () => ({
eventBus: {
- on: eventBusOnMock,
+ on: eventBusOnMock as unknown as (event: string, handler: () => void) => () => void,
},
}));
@@ -56,7 +59,11 @@ describe('OrganizationBillingPanel', () => {
listMembersMock.mockReset();
errorMock.mockReset();
eventBusOnMock.mockReset();
- eventBusOnMock.mockReturnValue(() => {});
+ eventBusHandlers.length = 0;
+ eventBusOnMock.mockImplementation((_event: string, handler: () => void) => {
+ eventBusHandlers.push(handler);
+ return () => {};
+ });
getStatusMock.mockResolvedValue({
valid: true,
@@ -94,8 +101,30 @@ describe('OrganizationBillingPanel', () => {
expect(errorMock).not.toHaveBeenCalled();
});
- it('normalizes org scope through the shared helper', () => {
- expect(organizationBillingPanelSource).toContain('normalizeOrgScope(getOrgID())');
- expect(organizationBillingPanelSource).not.toContain("getOrgID() || 'default'");
+ it('reloads billing data when the active organization changes', async () => {
+ render(() => <OrganizationBillingPanel nodeUsage={5} guestUsage={2} />);
+
+ await waitFor(() => {
+ expect(getStatusMock).toHaveBeenCalledTimes(1);
+ });
+
+ eventBusHandlers[0]?.();
+
+ await waitFor(() => {
+ expect(getStatusMock).toHaveBeenCalledTimes(2);
+ });
+ expect(listOrgsMock).toHaveBeenCalledTimes(2);
+ expect(listMembersMock).toHaveBeenCalledTimes(2);
+ });
+
+ it('keeps organization billing runtime split into dedicated state and loading owners', () => {
+ expect(organizationBillingPanelSource).toContain('./useOrganizationBillingPanelState');
+ expect(organizationBillingPanelSource).toContain('./OrganizationBillingLoadingState');
+ expect(organizationBillingPanelSource).not.toContain('createSignal(');
+ expect(organizationBillingPanelSource).not.toContain('onMount(() =>');
+ expect(organizationBillingStateSource).toContain('normalizeOrgScope(getOrgID())');
+ expect(organizationBillingStateSource).toContain("eventBus.on('org_switched'");
+ expect(organizationBillingStateSource).not.toContain("getOrgID() || 'default'");
+ expect(organizationBillingLoadingStateSource).toContain('animate-pulse');
});
});
diff --git a/frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts b/frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts
index afebfad7c5..db163aa60d 100644
--- a/frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts
+++ b/frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts
@@ -62,7 +62,9 @@ import organizationIncomingSharesSectionSource from '../OrganizationIncomingShar
import organizationAccessStateSource from '../useOrganizationAccessPanelState.ts?raw';
import organizationOverviewStateSource from '../useOrganizationOverviewPanelState.ts?raw';
import organizationSharingStateSource from '../useOrganizationSharingPanelState.ts?raw';
+import organizationBillingLoadingStateSource from '../OrganizationBillingLoadingState.tsx?raw';
import organizationBillingPanelSource from '../OrganizationBillingPanel.tsx?raw';
+import organizationBillingStateSource from '../useOrganizationBillingPanelState.ts?raw';
import proxmoxDeleteNodeDialogSource from '../ProxmoxDeleteNodeDialog.tsx?raw';
import proxmoxConfiguredNodesTableSource from '../ProxmoxConfiguredNodesTable.tsx?raw';
import proxmoxDirectConnectionsCardSource from '../ProxmoxDirectConnectionsCard.tsx?raw';
@@ -137,7 +139,9 @@ const extractedModules = [
'../OrganizationSharingLoadingState.tsx',
'../OrganizationOutgoingSharesSection.tsx',
'../OrganizationIncomingSharesSection.tsx',
+ '../OrganizationBillingLoadingState.tsx',
'../useOrganizationAccessPanelState.ts',
+ '../useOrganizationBillingPanelState.ts',
'../useOrganizationOverviewPanelState.ts',
'../useOrganizationSharingPanelState.ts',
'../RBACFeatureGateSection.tsx',
@@ -344,11 +348,17 @@ describe('Settings architecture guardrails', () => {
expect(selfHostedCommercialActivationSectionSource).toContain('License / Activation Key');
expect(selfHostedCommercialActivationSectionSource).toContain('Start 14-day Pro Trial');
expect(organizationBillingPanelSource).toContain('./CommercialBillingSections');
- expect(organizationBillingPanelSource).toContain('buildHostedCommercialPlanModel');
- expect(organizationBillingPanelSource).toContain('buildHostedCommercialUsageModel');
+ expect(organizationBillingPanelSource).toContain('./OrganizationBillingLoadingState');
+ expect(organizationBillingPanelSource).toContain('./useOrganizationBillingPanelState');
expect(organizationBillingPanelSource).toContain('CommercialBillingShell');
expect(organizationBillingPanelSource).toContain('CommercialSection');
expect(organizationBillingPanelSource).toContain('CommercialUsageMeters');
+ expect(organizationBillingPanelSource).not.toContain('createSignal(');
+ expect(organizationBillingPanelSource).not.toContain('onMount(() =>');
+ expect(organizationBillingStateSource).toContain('buildHostedCommercialPlanModel');
+ expect(organizationBillingStateSource).toContain('buildHostedCommercialUsageModel');
+ expect(organizationBillingStateSource).toContain("eventBus.on('org_switched'");
+ expect(organizationBillingLoadingStateSource).toContain('animate-pulse');
expect(settingsSource).toContain('organizationMonitoredSystemUsage');
expect(settingsSource).toContain("getLimit('max_monitored_systems')?.current ?? 0");
expect(settingsSource).not.toContain('organizationAgentUsage');
diff --git a/frontend-modern/src/components/Settings/useOrganizationBillingPanelState.ts b/frontend-modern/src/components/Settings/useOrganizationBillingPanelState.ts
new file mode 100644
index 0000000000..bb811ceb0b
--- /dev/null
+++ b/frontend-modern/src/components/Settings/useOrganizationBillingPanelState.ts
@@ -0,0 +1,113 @@
+import { createMemo, createSignal, onCleanup, onMount } from 'solid-js';
+import { LicenseAPI, type LicenseStatus } from '@/api/license';
+import { OrgsAPI } from '@/api/orgs';
+import { getOrgID } from '@/utils/apiClient';
+import { normalizeOrgScope } from '@/utils/orgScope';
+import { isMultiTenantEnabled } from '@/stores/license';
+import { eventBus } from '@/stores/events';
+import { notificationStore } from '@/stores/notifications';
+import { logger } from '@/utils/logger';
+import {
+ getLicenseTierLabel,
+ getOrganizationBillingLicenseStatusLabel,
+} from '@/utils/licensePresentation';
+import {
+ getOrganizationSettingsLoadErrorMessage,
+} from '@/utils/organizationSettingsPresentation';
+import {
+ buildHostedCommercialPlanModel,
+ buildHostedCommercialUsageModel,
+} from '@/utils/commercialBillingModel';
+
+export interface OrganizationBillingPanelProps {
+ nodeUsage: number;
+ guestUsage: number;
+}
+
+const formatBillingDate = (value?: string | null) => {
+ if (!value) return 'Never';
+ const date = new Date(value);
+ if (Number.isNaN(date.getTime())) return value;
+ return date.toLocaleDateString();
+};
+
+export function useOrganizationBillingPanelState(props: OrganizationBillingPanelProps) {
+ const [loading, setLoading] = createSignal(true);
+ const [status, setStatus] = createSignal<LicenseStatus | null>(null);
+ const [orgCount, setOrgCount] = createSignal(0);
+ const [memberCount, setMemberCount] = createSignal(0);
+
+ const activeOrgID = () => normalizeOrgScope(getOrgID());
+ const isBillingAvailable = () => isMultiTenantEnabled();
+
+ const commercialPlanModel = createMemo(() =>
+ buildHostedCommercialPlanModel({
+ status: status(),
+ tierLabel: getLicenseTierLabel(status()?.tier || 'free'),
+ licenseStatusLabel: getOrganizationBillingLicenseStatusLabel(status()),
+ organizationCount: orgCount(),
+ memberCount: memberCount(),
+ nodeUsage: props.nodeUsage,
+ guestUsage: props.guestUsage,
+ renewsOrExpires: status()?.is_lifetime
+ ? 'Never (Lifetime)'
+ : formatBillingDate(status()?.expires_at),
+ }),
+ );
+
+ const commercialUsageModel = createMemo(() =>
+ buildHostedCommercialUsageModel({
+ status: status(),
+ tierLabel: getLicenseTierLabel(status()?.tier || 'free'),
+ licenseStatusLabel: getOrganizationBillingLicenseStatusLabel(status()),
+ organizationCount: orgCount(),
+ memberCount: memberCount(),
+ nodeUsage: props.nodeUsage,
+ guestUsage: props.guestUsage,
+ renewsOrExpires: status()?.is_lifetime
+ ? 'Never (Lifetime)'
+ : formatBillingDate(status()?.expires_at),
+ }),
+ );
+
+ const loadBillingData = async () => {
+ setLoading(true);
+ try {
+ const [licenseStatus, orgs, members] = await Promise.all([
+ LicenseAPI.getStatus(),
+ OrgsAPI.list(),
+ OrgsAPI.listMembers(activeOrgID()),
+ ]);
+ setStatus(licenseStatus);
+ setOrgCount(orgs.length);
+ setMemberCount(members.length);
+ } catch (error) {
+ logger.error('Failed to load billing data', error);
+ const message = error instanceof Error ? error.message : '';
+ notificationStore.error(getOrganizationSettingsLoadErrorMessage(message, 'billing'));
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ onMount(() => {
+ if (!isBillingAvailable()) {
+ setLoading(false);
+ return;
+ }
+
+ void loadBillingData();
+
+ const unsubscribe = eventBus.on('org_switched', () => {
+ void loadBillingData();
+ });
+ onCleanup(unsubscribe);
+ });
+
+ return {
+ commercialPlanModel,
+ commercialUsageModel,
+ isBillingAvailable,
+ loading,
+ };
+}
diff --git a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
index 88f6fe29f9..1cf2786ddc 100644
--- a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
+++ b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
@@ -286,6 +286,7 @@ import organizationAccessLoadingStateSource from '@/components/Settings/Organiza
import organizationAccessManagementSectionSource from '@/components/Settings/OrganizationAccessManagementSection.tsx?raw';
import organizationAccessMembersSectionSource from '@/components/Settings/OrganizationAccessMembersSection.tsx?raw';
import billingAdminPanelSource from '@/components/Settings/BillingAdminPanel.tsx?raw';
+import organizationBillingLoadingStateSource from '@/components/Settings/OrganizationBillingLoadingState.tsx?raw';
import organizationBillingPanelSource from '@/components/Settings/OrganizationBillingPanel.tsx?raw';
import organizationOverviewLoadingStateSource from '@/components/Settings/OrganizationOverviewLoadingState.tsx?raw';
import organizationOverviewMembersSectionSource from '@/components/Settings/OrganizationOverviewMembersSection.tsx?raw';
@@ -293,6 +294,7 @@ import organizationSharingCreateSectionSource from '@/components/Settings/Organi
import organizationOutgoingSharesSectionSource from '@/components/Settings/OrganizationOutgoingSharesSection.tsx?raw';
import organizationIncomingSharesSectionSource from '@/components/Settings/OrganizationIncomingSharesSection.tsx?raw';
import organizationAccessStateSource from '@/components/Settings/useOrganizationAccessPanelState.ts?raw';
+import organizationBillingStateSource from '@/components/Settings/useOrganizationBillingPanelState.ts?raw';
import organizationOverviewStateSource from '@/components/Settings/useOrganizationOverviewPanelState.ts?raw';
import organizationSharingStateSource from '@/components/Settings/useOrganizationSharingPanelState.ts?raw';
import organizationRolePresentationSource from '@/utils/organizationRolePresentation.ts?raw';
@@ -872,14 +874,19 @@ describe('frontend resource type boundaries', () => {
expect(organizationAccessStateSource).toContain('normalizeOrgScope(getOrgID())');
expect(organizationOverviewStateSource).toContain('normalizeOrgScope(getOrgID())');
expect(organizationSharingStateSource).toContain('normalizeOrgScope(getOrgID())');
- expect(organizationBillingPanelSource).toContain('normalizeOrgScope(getOrgID())');
+ expect(organizationBillingPanelSource).toContain('./useOrganizationBillingPanelState');
+ expect(organizationBillingPanelSource).toContain('./OrganizationBillingLoadingState');
+ expect(organizationBillingStateSource).toContain('normalizeOrgScope(getOrgID())');
expect(organizationAccessStateSource).toContain('@/utils/organizationSettingsPresentation');
expect(billingAdminPanelSource).toContain('@/utils/organizationSettingsPresentation');
expect(billingAdminPanelSource).toContain('@/utils/licensePresentation');
expect(organizationOverviewStateSource).toContain('@/utils/organizationSettingsPresentation');
expect(organizationSharingStateSource).toContain('@/utils/organizationSettingsPresentation');
expect(organizationBillingPanelSource).toContain('@/utils/organizationSettingsPresentation');
- expect(organizationBillingPanelSource).toContain('@/utils/licensePresentation');
+ expect(organizationBillingStateSource).toContain('@/utils/licensePresentation');
+ expect(organizationBillingStateSource).toContain('@/utils/organizationSettingsPresentation');
+ expect(organizationBillingPanelSource).not.toContain('normalizeOrgScope(getOrgID())');
+ expect(organizationBillingPanelSource).not.toContain('createSignal(');
expect(organizationBillingPanelSource).not.toContain('Grace Period');
expect(organizationBillingPanelSource).not.toContain('No License');
expect(organizationAccessPanelSource).not.toContain(
@@ -897,6 +904,7 @@ describe('frontend resource type boundaries', () => {
'getOrganizationOverviewMembersEmptyState',
);
expect(organizationOverviewLoadingStateSource).toContain('animate-pulse');
+ expect(organizationBillingLoadingStateSource).toContain('animate-pulse');
expect(organizationOutgoingSharesSectionSource).toContain(
'getOrganizationOutgoingSharesEmptyState',
);
diff --git a/scripts/release_control/subsystem_lookup_test.py b/scripts/release_control/subsystem_lookup_test.py
index 596c85ada4..c2a14881f0 100644
--- a/scripts/release_control/subsystem_lookup_test.py
+++ b/scripts/release_control/subsystem_lookup_test.py
@@ -67,6 +67,29 @@ class SubsystemLookupTest(unittest.TestCase):
["frontend-modern/src/components/Settings/__tests__/OrganizationBillingPanel.test.tsx"],
)
+ def test_lookup_paths_assigns_organization_billing_state_owner_to_cloud_paid(self) -> None:
+ result = lookup_paths(
+ ["frontend-modern/src/components/Settings/useOrganizationBillingPanelState.ts"]
+ )
+ self.assertEqual(result["unowned_runtime_files"], [])
+ self.assertEqual(
+ {item["subsystem"] for item in result["impacted_subsystems"]},
+ {"cloud-paid"},
+ )
+ file_entry = result["files"][0]
+ self.assertEqual(file_entry["classification"], "runtime")
+ self.assertEqual(
+ {match["subsystem"] for match in file_entry["matches"]},
+ {"cloud-paid"},
+ )
+ match = file_entry["matches"][0]
+ self.assertEqual(match["contract"], "docs/release-control/v6/internal/subsystems/cloud-paid.md")
+ self.assertEqual(match["lane_context"]["lane_id"], "L3")
+ self.assertEqual(
+ match["verification_requirement"]["id"],
+ "organization-billing-surface",
+ )
+
def test_lookup_paths_assigns_pro_license_panel_to_cloud_paid(self) -> None:
result = lookup_paths(["frontend-modern/src/components/Settings/ProLicensePanel.tsx"])
self.assertEqual(result["unowned_runtime_files"], [])