Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(billing): show the covering workspace plan instead of "Free"

Gabriel Steindea65c486092
diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsx
index 8cbf95bfb..efaa64d46 100644
--- a/src/components/SettingsPage.tsx
+++ b/src/components/SettingsPage.tsx
@@ -95,6 +95,7 @@ import type {
GpuDevice,
LocalTranscriptionProvider,
InferenceMode,
+ Workspace,
} from "../types/electron";
import logger from "../utils/logger";
import { SettingsRow, InferenceModeSelector } from "./ui/SettingsSection";
@@ -112,6 +113,7 @@ import {
useSettingsStore,
} from "../stores/settingsStore";
import { useWorkspaceStore } from "../stores/workspaceStore";
+import { highestPlan } from "../lib/usageStore";
import {
canChangeCloudBackupPreference,
effectiveAudioRetentionDays,
@@ -1007,9 +1009,24 @@ export default function SettingsPage({
const { theme, setTheme } = useTheme();
const usage = useUsage();
const billingWorkspaces = useWorkspaceStore((s) => s.workspaces);
- const coveringWorkspaceNames = (usage?.entitledWorkspaceIds ?? [])
- .map((id) => billingWorkspaces.find((workspace) => workspace.id === id)?.name)
- .filter((name): name is string => Boolean(name));
+ const coveringWorkspaces = (usage?.entitledWorkspaceIds ?? [])
+ .map((id) => billingWorkspaces.find((workspace) => workspace.id === id))
+ .filter((workspace): workspace is Workspace => Boolean(workspace));
+ const coveringWorkspaceNames = coveringWorkspaces.map((workspace) => workspace.name);
+ // Gated on the usage payload rather than the resolved workspaces: the workspace
+ // store loads separately, and the upgrade affordances must stay hidden while it
+ // does, or a covered member is invited to buy a plan their seat already grants.
+ const isWorkspaceCovered =
+ !usage?.isPersonallySubscribed && (usage?.entitledWorkspaceIds?.length ?? 0) > 0;
+ // Names the tier the seat actually grants. Null until the store resolves, which
+ // leaves the personal-plan label untouched rather than guessing at a tier.
+ const coveringPlanLabel = coveringWorkspaces.length
+ ? t(
+ `settingsPage.workspace.billing.planLabel.${highestPlan(
+ coveringWorkspaces.map((workspace) => workspace.plan)
+ )}`
+ )
+ : null;
const hasShownApproachingToast = useRef(false);
useEffect(() => {
if (usage?.isApproachingLimit && !hasShownApproachingToast.current) {
@@ -1900,7 +1917,8 @@ export default function SettingsPage({
? usage.plan === "business"
? t("settingsPage.account.planLabels.business")
: t("settingsPage.account.planLabels.pro")
- : t("settingsPage.account.planLabels.free")
+ : (coveringPlanLabel ??
+ t("settingsPage.account.planLabels.free"))
}
description={
usage.isTrial
@@ -1925,10 +1943,15 @@ export default function SettingsPage({
? t("settingsPage.unifiedBilling.providedBy", {
workspaces: coveringWorkspaceNames.join(", "),
})
- : t("settingsPage.account.planDescriptions.freeUsage", {
- used: usage.wordsUsed.toLocaleString(i18n.language),
- limit: usage.limit.toLocaleString(i18n.language),
- })
+ : // Covered, but the workspace store hasn't resolved a
+ // name yet. The free-usage copy would print the
+ // subscribed sentinel limit as "-1 words".
+ isWorkspaceCovered
+ ? t("settingsPage.account.planDescriptions.unlimited")
+ : t("settingsPage.account.planDescriptions.freeUsage", {
+ used: usage.wordsUsed.toLocaleString(i18n.language),
+ limit: usage.limit.toLocaleString(i18n.language),
+ })
}
>
{usage.isTrial ? (
@@ -1943,6 +1966,8 @@ export default function SettingsPage({
? t("settingsPage.account.badges.business")
: t("settingsPage.account.badges.pro")}
</Badge>
+ ) : coveringPlanLabel ? (
+ <Badge variant="success">{coveringPlanLabel}</Badge>
) : usage.isOverLimit ? (
<Badge variant="warning">
{t("settingsPage.account.badges.limitReached")}
@@ -2022,7 +2047,7 @@ export default function SettingsPage({
? t("settingsPage.account.billing.opening")
: t("settingsPage.account.billing.manageBilling")}
</Button>
- ) : (
+ ) : isWorkspaceCovered ? null : (
<Button
onClick={async () => {
setCheckoutTier("plan-upgrade");
@@ -2062,7 +2087,10 @@ export default function SettingsPage({
<div
className={cn(
"rounded-md p-2.5 flex flex-col",
- planStateKnown && !usage?.isPersonallySubscribed && !usage?.isTrial
+ planStateKnown &&
+ !usage?.isPersonallySubscribed &&
+ !usage?.isTrial &&
+ !isWorkspaceCovered
? "border-2 border-primary/30 bg-primary/3 dark:border-primary/20 dark:bg-primary/5"
: "border border-border/50 dark:border-border-subtle/60 bg-card/30 dark:bg-surface-2/30"
)}
@@ -2123,7 +2151,7 @@ export default function SettingsPage({
? t("settingsPage.account.billing.opening")
: t("settingsPage.account.pricing.downgrade")}
</Button>
- ) : planStateKnown ? (
+ ) : planStateKnown && !isWorkspaceCovered ? (
<div className="mt-2 text-center">
<span className="text-[9px] font-medium text-primary/70">
{t("settingsPage.account.pricing.currentPlan")}
diff --git a/src/lib/usageStore.ts b/src/lib/usageStore.ts
index 6c1d9ac42..4ac671e74 100644
--- a/src/lib/usageStore.ts
+++ b/src/lib/usageStore.ts
@@ -6,6 +6,17 @@ const USAGE_CACHE_TTL = CACHE_CONFIG.API_KEY_TTL;
const RETRY_DELAYS_MS = [2000, 4000, 8000];
const PAID_PLANS = new Set(["pro", "business", "enterprise"]);
+// Ascending tier ladder. Unknown plans rank as free so a tier this build has
+// never heard of can never out-rank a known paid one.
+const PLAN_ORDER: Record<string, number> = { free: 0, pro: 1, business: 2, enterprise: 3 };
+
+export function highestPlan(plans: string[]): string {
+ return plans.reduce(
+ (best, plan) => ((PLAN_ORDER[plan] ?? 0) > (PLAN_ORDER[best] ?? 0) ? plan : best),
+ "free"
+ );
+}
+
export interface UsageData {
wordsUsed: number;
wordsRemaining: number;
diff --git a/test/lib/highestPlan.test.js b/test/lib/highestPlan.test.js
new file mode 100644
index 000000000..bf3f70229
--- /dev/null
+++ b/test/lib/highestPlan.test.js
@@ -0,0 +1,20 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+
+const { highestPlan } = require("../../src/lib/usageStore.ts");
+
+test("the best tier a covering workspace grants wins", () => {
+ assert.equal(highestPlan(["free", "business"]), "business");
+ assert.equal(highestPlan(["pro", "enterprise", "business"]), "enterprise");
+ assert.equal(highestPlan(["pro", "pro"]), "pro");
+});
+
+test("nothing to rank falls back to free", () => {
+ assert.equal(highestPlan([]), "free");
+ assert.equal(highestPlan(["free"]), "free");
+});
+
+test("an unrecognized tier never out-ranks a known paid one", () => {
+ assert.equal(highestPlan(["mystery"]), "free");
+ assert.equal(highestPlan(["mystery", "pro"]), "pro");
+});