WorkspaceSidebarFooterUsageSummary.tsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. import { SidebarNativeTooltip } from "@/ControlHintTooltip.js";
  2. import { useCodingPlanEntryGate } from "@/settings/CodingPlanEntryButton.js";
  3. /* eslint-disable max-lines -- footer 套餐徽标、升级入口与 entitlement 探测共用同一份
  4. provider 选择与 family 过滤上下文,拆文件会让 zai/bigmodel 对称性难以追踪。 */
  5. import { useEffect, useMemo } from "react";
  6. import {
  7. BUILTIN_MODEL_PROVIDER_IDS,
  8. normalizeProviderFamilyDomain,
  9. resolveModelProviderFamilyIdByProviderId,
  10. } from "@zcode/shared";
  11. import { TID_SIDEBAR_CODING_PLAN_USAGE_BUTTON } from "@zcode/shared/test-ids";
  12. import { BarChart3Icon, RocketIcon } from "lucide-react";
  13. import { DropdownMenuItem, DropdownMenuSeparator } from "@/components/ui/dropdown-menu.js";
  14. import {
  15. resolveCodingPlanUsageRemainingState,
  16. type CodingPlanUsageAvailableProvider,
  17. } from "@/CodingPlanUsageRemainingPanel.js";
  18. import { useProviderSettingsView } from "@/hooks/useProviderSettingsView.js";
  19. import { useUsageEntitlement } from "@/hooks/useUsageEntitlement.js";
  20. import { useZCodeIntl } from "@/i18n/IntlProvider.js";
  21. import { useSettings } from "@/hooks/useSettingService.js";
  22. import {
  23. resolveEntitledAccountProviderAccess,
  24. resolveEntitledAccountProviderAccessFingerprint,
  25. } from "@/lib/accountProviderAccess.js";
  26. import { buildUsageEntitlementCacheKey } from "@/lib/usageEntitlementCache.js";
  27. import {
  28. isMaxCodingPlanSnapshot,
  29. resolveSidebarCodingPlanUpgradeFallbackProviderId,
  30. } from "@/lib/sidebarCodingPlanUpgrade.js";
  31. import {
  32. createCodingPlanFunnelContext,
  33. resolveCodingPlanEntryPlanState,
  34. type CodingPlanFunnelContext,
  35. } from "@/lib/codingPlanFunnelTelemetry.js";
  36. import { type SidebarUsageCodingPlanProviderId } from "@/lib/sidebarUsageCodingPlanProviderPreference.js";
  37. import { useEnterpriseCodingPlanProducts } from "@/settings/model-provider-section/useEnterpriseCodingPlanProducts.js";
  38. import {
  39. buildCodingPlanUsageSources,
  40. resolveSidebarCurrentCodingPlanUsageSource,
  41. } from "@/lib/codingPlanUsageSources.js";
  42. import { selectWorkspaceZCodeState, useZCodeSessionStore } from "@/store/zcodeSessionStore.js";
  43. import { parseCustomProviderIdFromSupplierKey } from "@/lib/modelConfigSync.js";
  44. import { setPendingSettingsUsageIntent } from "@/lib/settingsNavigation.js";
  45. import {
  46. resolveSidebarFooterPlanBadgeLabel,
  47. resolveSidebarFooterProfilePlanBadge,
  48. } from "@/WorkspaceSidebarFooterPlanBadgeHelpers.js";
  49. export {
  50. resolveSidebarFooterPlanBadgeLabel,
  51. resolveSidebarFooterProfilePlanBadge,
  52. } from "@/WorkspaceSidebarFooterPlanBadgeHelpers.js";
  53. const TID_SIDEBAR_CODING_PLAN_UPGRADE_BUTTON = "sidebar-coding-plan-upgrade-button";
  54. export function WorkspaceSidebarFooterUsageSummary({
  55. enabled,
  56. onUsageClick,
  57. onUpgradeClick,
  58. workspaceIdentity,
  59. workspacePath,
  60. }: {
  61. enabled: boolean;
  62. onUsageClick?: () => void;
  63. onUpgradeClick?: (
  64. providerId: SidebarUsageCodingPlanProviderId,
  65. funnelContext: CodingPlanFunnelContext,
  66. ) => void;
  67. workspaceIdentity?: string;
  68. workspacePath?: string;
  69. }) {
  70. const state = useWorkspaceSidebarFooterUsageSummaryState({
  71. enabled,
  72. workspaceIdentity,
  73. workspacePath,
  74. });
  75. return (
  76. <WorkspaceSidebarFooterUsageSummaryContent
  77. state={state}
  78. onUsageClick={onUsageClick}
  79. onUpgradeClick={onUpgradeClick}
  80. />
  81. );
  82. }
  83. export function useWorkspaceSidebarFooterUsageSummaryState({
  84. enabled,
  85. workspaceIdentity,
  86. workspacePath,
  87. }: {
  88. enabled: boolean;
  89. workspaceIdentity?: string;
  90. workspacePath?: string;
  91. }) {
  92. const { settings: sharedSettings } = useSettings();
  93. const providerFamilyDomain = normalizeProviderFamilyDomain(sharedSettings?.providerFamilyDomain);
  94. const providerSettingsRead = useProviderSettingsView();
  95. const providerSettingsView =
  96. providerSettingsRead.state.status === "ready" ? providerSettingsRead.state.view : null;
  97. // 首次读取失败也不能被解释成“已经加载且没有套餐”;只有 Ready 才能消费 Provider 事实。
  98. const providerSourcesLoading = providerSettingsRead.state.status !== "ready";
  99. const selectedSupplierKey = useZCodeSessionStore((state) =>
  100. workspacePath
  101. ? selectWorkspaceZCodeState(state, workspacePath, workspaceIdentity).selectedSupplierKey
  102. : "",
  103. );
  104. const availableCodingPlanProviders = useMemo(
  105. () =>
  106. [
  107. BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  108. BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  109. ].flatMap((providerId): CodingPlanUsageAvailableProvider[] => {
  110. const access = resolveEntitledAccountProviderAccess(providerSettingsView, providerId);
  111. if (!access) return [];
  112. return [
  113. {
  114. providerId,
  115. accountAccess: access.access,
  116. label:
  117. access.label ||
  118. (providerId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan
  119. ? "Z.ai - Coding Plan"
  120. : "BigModel - Coding Plan"),
  121. },
  122. ];
  123. }),
  124. [providerSettingsView],
  125. );
  126. const zaiProvider = availableCodingPlanProviders.find(
  127. (provider) => provider.providerId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  128. );
  129. const bigmodelProvider = availableCodingPlanProviders.find(
  130. (provider) => provider.providerId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  131. );
  132. const zaiProviderFingerprint = resolveEntitledAccountProviderAccessFingerprint(
  133. providerSettingsView,
  134. BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  135. );
  136. const bigmodelProviderFingerprint = resolveEntitledAccountProviderAccessFingerprint(
  137. providerSettingsView,
  138. BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  139. );
  140. const zaiTeamProvider = resolveEntitledAccountProviderAccess(
  141. providerSettingsView,
  142. BUILTIN_MODEL_PROVIDER_IDS.zaiTeamCodingPlan,
  143. );
  144. const bigmodelTeamProvider = resolveEntitledAccountProviderAccess(
  145. providerSettingsView,
  146. BUILTIN_MODEL_PROVIDER_IDS.bigmodelTeamCodingPlan,
  147. );
  148. const selectedProviderIdFromSupplierKey =
  149. parseCustomProviderIdFromSupplierKey(selectedSupplierKey);
  150. const selectedProviderFamilyId = selectedProviderIdFromSupplierKey
  151. ? resolveModelProviderFamilyIdByProviderId(selectedProviderIdFromSupplierKey)
  152. : null;
  153. // providerFamilyDomain 是当前登录/运行 family 边界;BigModel Team selectedKey
  154. // 会在切换到 Z.ai 后保留,footer 若不按当前 domain 过滤会把头像旁徽标误显示成 Team。
  155. const scopedSelectedProviderId =
  156. selectedProviderFamilyId &&
  157. providerFamilyDomain &&
  158. selectedProviderFamilyId !== providerFamilyDomain
  159. ? null
  160. : selectedProviderIdFromSupplierKey;
  161. const bigmodelFamilyAllowed = providerFamilyDomain !== "zai";
  162. // 原只有 bigmodelFamilyAllowed 单变量,zai family 下 enterprise products 完全不拉。
  163. // zai team plan 对称化需要 zai family 也独立拉一份 enterprise pricing。
  164. const zaiFamilyAllowed = providerFamilyDomain !== "bigmodel";
  165. const bigmodelEnterpriseProducts = useEnterpriseCodingPlanProducts({
  166. // footer badge 和升级入口都需要识别 Team Plan。
  167. // Team 项目上下文只在企业 pricing/customerInfo 返回,账号级头像徽标也不能被当前连接方式卡住。
  168. enabled:
  169. enabled && !providerSourcesLoading && bigmodelFamilyAllowed && Boolean(bigmodelTeamProvider),
  170. authenticated: true,
  171. family: "bigmodel",
  172. });
  173. const zaiEnterpriseProducts = useEnterpriseCodingPlanProducts({
  174. enabled: enabled && !providerSourcesLoading && zaiFamilyAllowed && Boolean(zaiTeamProvider),
  175. authenticated: true,
  176. family: "zai",
  177. });
  178. const subscribedTeamProducts = useMemo(
  179. () => [
  180. ...(bigmodelEnterpriseProducts.snapshot?.productList.filter(
  181. (product) => product.subscribed === true,
  182. ) ?? []),
  183. ...(zaiEnterpriseProducts.snapshot?.productList.filter(
  184. (product) => product.subscribed === true,
  185. ) ?? []),
  186. ],
  187. [bigmodelEnterpriseProducts.snapshot?.productList, zaiEnterpriseProducts.snapshot?.productList],
  188. );
  189. const teamSources = useMemo(
  190. () =>
  191. buildCodingPlanUsageSources({
  192. accountAccesses: {
  193. ...(zaiTeamProvider?.access
  194. ? {
  195. zai: zaiTeamProvider.access,
  196. }
  197. : {}),
  198. ...(bigmodelTeamProvider?.access
  199. ? {
  200. bigmodel: bigmodelTeamProvider.access,
  201. }
  202. : {}),
  203. },
  204. subscribedTeamProducts,
  205. }),
  206. [bigmodelTeamProvider?.access, subscribedTeamProducts, zaiTeamProvider?.access],
  207. );
  208. const currentUsageSource = useMemo(
  209. () =>
  210. resolveSidebarCurrentCodingPlanUsageSource({
  211. selections: sharedSettings?.providerFamilyConnectionSelections,
  212. selectedProviderId: scopedSelectedProviderId,
  213. accountAccesses: {
  214. ...(resolveEntitledAccountProviderAccess(
  215. providerSettingsView,
  216. BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  217. )?.access
  218. ? {
  219. zai: resolveEntitledAccountProviderAccess(
  220. providerSettingsView,
  221. BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  222. )!.access,
  223. }
  224. : {}),
  225. ...(resolveEntitledAccountProviderAccess(
  226. providerSettingsView,
  227. BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  228. )?.access
  229. ? {
  230. bigmodel: resolveEntitledAccountProviderAccess(
  231. providerSettingsView,
  232. BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  233. )!.access,
  234. }
  235. : {}),
  236. },
  237. teamSources,
  238. }),
  239. [
  240. scopedSelectedProviderId,
  241. bigmodelProvider?.accountAccess,
  242. sharedSettings?.providerFamilyConnectionSelections,
  243. teamSources,
  244. zaiProvider?.accountAccess,
  245. ],
  246. );
  247. const selectedProviderId = currentUsageSource?.sourceId;
  248. const zaiEntitlement = useUsageEntitlement({
  249. enabled:
  250. enabled &&
  251. !providerSourcesLoading &&
  252. providerFamilyDomain !== "bigmodel" &&
  253. Boolean(zaiProvider),
  254. includeSubscription: true,
  255. preferredProviderId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  256. accountAccess: resolveEntitledAccountProviderAccess(
  257. providerSettingsView,
  258. BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  259. )?.access,
  260. allowDisabledPreferredProvider: true,
  261. requirePreferredProvider: true,
  262. allowEnvApiKey: false,
  263. cacheKey: buildUsageEntitlementCacheKey({
  264. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  265. providerFingerprint: zaiProviderFingerprint,
  266. }),
  267. refreshOnMount: false,
  268. });
  269. const bigmodelEntitlement = useUsageEntitlement({
  270. enabled:
  271. enabled && !providerSourcesLoading && bigmodelFamilyAllowed && Boolean(bigmodelProvider),
  272. includeSubscription: true,
  273. preferredProviderId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  274. accountAccess: resolveEntitledAccountProviderAccess(
  275. providerSettingsView,
  276. BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  277. )?.access,
  278. allowDisabledPreferredProvider: true,
  279. requirePreferredProvider: true,
  280. allowEnvApiKey: false,
  281. cacheKey: buildUsageEntitlementCacheKey({
  282. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  283. providerFingerprint: bigmodelProviderFingerprint,
  284. }),
  285. refreshOnMount: false,
  286. });
  287. const teamEntitlement = useUsageEntitlement({
  288. // 原硬绑 bigmodelCodingPlan providerId 判断,zai team source 的 providerId
  289. // 是 zaiCodingPlan,永远进不到 team 分支,导致 zai team 额度不查询、badge 不显示。
  290. // 改为按 currentUsageSource.audience === "team" 路由,providerId 动态取。
  291. enabled: enabled && !providerSourcesLoading && currentUsageSource?.audience === "team",
  292. includeSubscription: true,
  293. preferredProviderId:
  294. currentUsageSource?.providerId ?? BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  295. accountAccess: currentUsageSource?.teamSource?.accountAccess,
  296. allowDisabledPreferredProvider: true,
  297. requirePreferredProvider: true,
  298. allowEnvApiKey: false,
  299. cacheKey: currentUsageSource?.teamSource?.id,
  300. refreshOnMount: false,
  301. });
  302. // footer 是常驻入口,refreshOnMount: false 后冷启动没有其它
  303. // 入口预热 entitlement,个人计划徽标缺失。可见时触发一次 access 刷新,复用共享
  304. // 1 分钟 freshness window、失败退避和 in-flight 合并;hook disabled 时 refresh 是 no-op。
  305. useEffect(() => {
  306. for (const refresh of [
  307. zaiEntitlement.refresh,
  308. bigmodelEntitlement.refresh,
  309. teamEntitlement.refresh,
  310. ]) {
  311. void refresh({ silent: true, reason: "access" });
  312. }
  313. }, [zaiEntitlement.refresh, bigmodelEntitlement.refresh, teamEntitlement.refresh]);
  314. const profilePlanBadge = resolveSidebarFooterProfilePlanBadge({
  315. individualEntitlements: [
  316. ...(providerFamilyDomain !== "bigmodel"
  317. ? [
  318. {
  319. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  320. snapshot: zaiEntitlement.snapshot,
  321. loading: zaiEntitlement.loading,
  322. },
  323. ]
  324. : []),
  325. ...(bigmodelFamilyAllowed
  326. ? [
  327. {
  328. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  329. snapshot: bigmodelEntitlement.snapshot,
  330. loading: bigmodelEntitlement.loading,
  331. },
  332. ]
  333. : []),
  334. ],
  335. // 头像徽标使用账号的 Team entitlement;pricing 结果只负责额度来源和套餐详情。
  336. hasTeamPlanEntitlement:
  337. providerFamilyDomain === "zai"
  338. ? Boolean(zaiTeamProvider)
  339. : providerFamilyDomain === "bigmodel"
  340. ? Boolean(bigmodelTeamProvider)
  341. : Boolean(zaiTeamProvider || bigmodelTeamProvider),
  342. });
  343. const providerEntitlements = [
  344. ...(currentUsageSource?.providerId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan &&
  345. currentUsageSource.audience === "individual"
  346. ? [
  347. {
  348. sourceId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  349. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  350. accountAccess: currentUsageSource.accountAccess,
  351. ...zaiEntitlement,
  352. },
  353. ]
  354. : []),
  355. ...(currentUsageSource?.providerId ===
  356. BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan &&
  357. currentUsageSource.audience === "individual"
  358. ? [
  359. {
  360. sourceId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  361. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  362. accountAccess: currentUsageSource.accountAccess,
  363. ...bigmodelEntitlement,
  364. },
  365. ]
  366. : []),
  367. // 原 team 分支硬判 bigmodelCodingPlan providerId,zai team source 走不进来。
  368. // 改为统一按 audience === "team" 路由,覆盖 zai/bigmodel 两种 family 的 team source。
  369. ...(currentUsageSource?.audience === "team" && currentUsageSource.teamSource
  370. ? [
  371. {
  372. sourceId: currentUsageSource.teamSource.id,
  373. providerId: currentUsageSource.teamSource.providerId,
  374. accountAccess: currentUsageSource.teamSource.accountAccess,
  375. label: currentUsageSource.teamSource.label,
  376. ...teamEntitlement,
  377. },
  378. ]
  379. : []),
  380. ];
  381. const usageState = resolveCodingPlanUsageRemainingState({
  382. availableProviders: availableCodingPlanProviders,
  383. entitlements: providerEntitlements,
  384. modelProvidersLoading: providerSourcesLoading,
  385. selectedProviderId,
  386. });
  387. const visibleUsageState = usageState?.hasAnyActiveCodingPlan ? usageState : null;
  388. const selectedUpgradeProviderId: SidebarUsageCodingPlanProviderId | undefined =
  389. selectedProviderId === BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan ||
  390. selectedProviderId === BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan
  391. ? selectedProviderId
  392. : undefined;
  393. const upgradeTargetProviderId =
  394. selectedUpgradeProviderId ??
  395. currentUsageSource?.providerId ??
  396. availableCodingPlanProviders[0]?.providerId ??
  397. resolveSidebarCodingPlanUpgradeFallbackProviderId(providerFamilyDomain);
  398. return {
  399. audience: currentUsageSource?.audience,
  400. availableCodingPlanProviders,
  401. providerSourcesLoading,
  402. providerEntitlements,
  403. profilePlanBadge,
  404. selectedProviderId,
  405. upgradeTargetProviderId,
  406. usageState: visibleUsageState,
  407. };
  408. }
  409. export type WorkspaceSidebarFooterUsageSummaryState = ReturnType<
  410. typeof useWorkspaceSidebarFooterUsageSummaryState
  411. >;
  412. export function WorkspaceSidebarFooterUsageSummaryContent({
  413. state,
  414. onUsageClick,
  415. onUpgradeClick,
  416. }: {
  417. state: WorkspaceSidebarFooterUsageSummaryState;
  418. onUsageClick?: () => void;
  419. onUpgradeClick?: (
  420. providerId: SidebarUsageCodingPlanProviderId,
  421. funnelContext: CodingPlanFunnelContext,
  422. ) => void;
  423. }) {
  424. const { intl } = useZCodeIntl();
  425. const entryGate = useCodingPlanEntryGate();
  426. const { providerEntitlements, upgradeTargetProviderId } = state;
  427. const upgradeProviderSnapshot =
  428. providerEntitlements.find((item) => item.providerId === upgradeTargetProviderId)?.snapshot ??
  429. null;
  430. const upgradeActionLabelId = isMaxCodingPlanSnapshot(upgradeProviderSnapshot)
  431. ? "sidebar.usage.plan.renew"
  432. : "sidebar.usage.plan.upgrade";
  433. return (
  434. <>
  435. <DropdownMenuSeparator />
  436. <DropdownMenuItem
  437. data-testid={TID_SIDEBAR_CODING_PLAN_USAGE_BUTTON}
  438. onSelect={() => {
  439. setPendingSettingsUsageIntent();
  440. onUsageClick?.();
  441. }}
  442. >
  443. <BarChart3Icon className="size-4" />
  444. {intl.formatMessage({ id: "sidebar.usage.plan.openStats" })}
  445. </DropdownMenuItem>
  446. {/* 产品要求:升级入口始终显示;未解析出当前套餐时由当前 provider family 决定品牌。 */}
  447. <DropdownMenuItem
  448. data-testid={TID_SIDEBAR_CODING_PLAN_UPGRADE_BUTTON}
  449. disabled={entryGate.status === "loading"}
  450. aria-busy={entryGate.status === "loading"}
  451. onSelect={() => {
  452. if (entryGate.status !== "ready") {
  453. entryGate.retry?.();
  454. return;
  455. }
  456. onUpgradeClick?.(
  457. upgradeTargetProviderId,
  458. createCodingPlanFunnelContext({
  459. providerId: upgradeTargetProviderId,
  460. upgradeSource: "profile_menu",
  461. eventRegion: "app.profile",
  462. eventText: intl.formatMessage({ id: upgradeActionLabelId }),
  463. entryPlanState: resolveCodingPlanEntryPlanState({
  464. snapshot: upgradeProviderSnapshot,
  465. }),
  466. }),
  467. );
  468. }}
  469. >
  470. <RocketIcon className="size-4" />
  471. {entryGate.label ?? intl.formatMessage({ id: upgradeActionLabelId })}
  472. </DropdownMenuItem>
  473. </>
  474. );
  475. }
  476. export function WorkspaceSidebarFooterPlanBadge({
  477. state,
  478. }: {
  479. state: WorkspaceSidebarFooterUsageSummaryState;
  480. }) {
  481. const { intl } = useZCodeIntl();
  482. const label =
  483. state.profilePlanBadge?.audience === "team"
  484. ? intl.formatMessage({ id: "sidebar.usage.plan.audienceTeam" })
  485. : resolveSidebarFooterPlanBadgeLabel(state.profilePlanBadge?.snapshot ?? null);
  486. if (!label) {
  487. return null;
  488. }
  489. return (
  490. <SidebarNativeTooltip>
  491. <span
  492. className="min-w-0 max-w-20 shrink truncate rounded-full border border-border bg-surface px-1 py-px text-ui-xs font-medium leading-normal text-foreground-subtle"
  493. title={label}
  494. >
  495. {label}
  496. </span>
  497. </SidebarNativeTooltip>
  498. );
  499. }