Line data Source code
1 : import { useI18n } from 'vue-i18n'
2 :
3 : import type { SubscriptionTier } from '@comfyorg/billing-core'
4 :
5 2355 : const tierKeyMap: Record<string, string> = {
6 : FREE: 'free',
7 : STANDARD: 'standard',
8 : CREATOR: 'creator',
9 : PRO: 'pro',
10 : FOUNDER: 'founder',
11 : FOUNDERS_EDITION: 'founder',
12 : ENTERPRISE: 'enterprise'
13 : }
14 :
15 : interface WorkspaceSubscriptionInfo {
16 : isSubscribed: boolean
17 : subscriptionPlan: string | null
18 : subscriptionTier: SubscriptionTier | null
19 : }
20 :
21 10 : export function useWorkspaceTierLabel() {
22 10 : const { t } = useI18n()
23 :
24 4 : function formatTierName(
25 : tier: string | null | undefined,
26 : isYearly: boolean
27 : ): string {
28 4 : if (!tier) return ''
29 : // TEAM has no `tiers.*` catalog entry (it isn't a self-serve personal
30 : // plan); reuse the existing team-plan copy instead of adding one.
31 0 : if (tier === 'TEAM') return t('subscription.teamPlanName')
32 0 : const key = tierKeyMap[tier]
33 0 : if (!key) return ''
34 0 : const baseName = t(`subscription.tiers.${key}.name`)
35 4 : return isYearly
36 : ? t('subscription.tierNameYearly', { name: baseName })
37 : : baseName
38 : }
39 :
40 0 : function getTierLabel(workspace: WorkspaceSubscriptionInfo): string | null {
41 0 : if (!workspace.isSubscribed) return null
42 :
43 0 : if (workspace.subscriptionTier) {
44 0 : return formatTierName(workspace.subscriptionTier, false)
45 : }
46 :
47 0 : if (!workspace.subscriptionPlan) return null
48 :
49 : // Plan identifiers arrive in both cases: comfy-api sends uppercase slugs,
50 : // cloud sends lowercase ones (e.g. enterprise plan rows).
51 0 : const planSlug = workspace.subscriptionPlan.toUpperCase()
52 0 : const tierMatch = Object.keys(tierKeyMap)
53 : .sort((a, b) => b.length - a.length)
54 : .find((tier) => planSlug === tier || planSlug.startsWith(`${tier}_`))
55 0 : if (!tierMatch) return null
56 :
57 : const isYearly = planSlug.includes('YEARLY') || planSlug.includes('ANNUAL')
58 0 : return formatTierName(tierMatch, isYearly)
59 : }
60 :
61 10 : return { formatTierName, getTierLabel }
62 : }
|