Line data Source code
1 5 : <template>
2 : <div v-if="banner" class="@container">
3 : <div
4 : role="status"
5 : class="flex flex-col gap-3 rounded-xl border border-border bg-background p-4 @2xl:flex-row @2xl:items-center @2xl:gap-2"
6 : >
7 : <div class="flex min-w-0 flex-1 flex-col gap-1">
8 : <div class="flex items-center gap-2">
9 : <i
10 : :class="
11 : banner.muted
12 : ? 'icon-[lucide--circle-alert] text-muted-foreground'
13 : : 'icon-[lucide--triangle-alert] text-warning'
14 : "
15 : />
16 : <span class="text-sm text-foreground">{{ banner.title }}</span>
17 : </div>
18 : <p class="m-0 pl-6 text-sm text-muted-foreground">{{ banner.body }}</p>
19 : </div>
20 : <div
21 : v-if="banner.dismissible || banner.action"
22 : class="flex shrink-0 flex-wrap items-center gap-2 pl-6 @2xl:pl-0"
23 : >
24 : <Button
25 : v-if="banner.dismissible"
26 : variant="textonly"
27 : size="lg"
28 : @click="dismiss"
29 : >
30 : {{ $t('workspacePanel.billingStatus.outOfCredits.dismiss') }}
31 : </Button>
32 : <Button
33 : v-if="banner.action === 'addCredits'"
34 : variant="secondary"
35 : size="lg"
36 : :data-dd-action-name="BILLING_ACTION_NAME.addCreditsStatusBanner"
37 : @click="handleAddCredits"
38 : >
39 : {{ $t('workspacePanel.billingStatus.outOfCredits.addCredits') }}
40 : </Button>
41 : <Button
42 : v-else-if="banner.action === 'reactivate'"
43 : variant="secondary"
44 : size="lg"
45 : :loading="isResubscribing"
46 : @click="handleResubscribe"
47 : >
48 : {{ $t('workspacePanel.billingStatus.ending.reactivate') }}
49 : </Button>
50 : <Button
51 : v-else-if="banner.action === 'choosePlan'"
52 : v-bind="plansButton"
53 : variant="inverted"
54 : size="lg"
55 : class="no-underline"
56 : @click="openPlans"
57 : >
58 : {{ $t('workspacePanel.billingTab.plan.actions.choosePlan') }}
59 : <i class="icon-[lucide--arrow-up-right]" aria-hidden="true" />
60 : </Button>
61 : <Button
62 : v-else-if="banner.action === 'contactSales'"
63 : variant="secondary"
64 : size="lg"
65 : @click="handleContactSales"
66 : >
67 : {{ $t('workspacePanel.billingStatus.ending.contactSales') }}
68 : </Button>
69 : <Button
70 : v-else-if="banner.action === 'updatePayment'"
71 : variant="inverted"
72 : size="lg"
73 : :loading="isUpdatingPayment"
74 : @click="updatePayment"
75 : >
76 : {{ $t('workspacePanel.billingStatus.updatePayment') }}
77 : </Button>
78 : </div>
79 : </div>
80 : </div>
81 : </template>
82 :
83 : <script setup lang="ts">
84 : import { BILLING_ACTION_NAME } from '@/platform/telemetry/billingActionNames'
85 : import { computed } from 'vue'
86 : import { useI18n } from 'vue-i18n'
87 : import { useLongDate } from '@/platform/billing/composables/useLongDate'
88 :
89 : import Button from '@comfyorg/design-system/button/Button'
90 : import { useBillingContext } from '@/platform/billing/composables/useBillingContext'
91 : import { ENTERPRISE_URL } from '@/platform/billing/subscription/constants/tierPricing'
92 : import { useBillingBanner } from '@/platform/billing/composables/useBillingBanner'
93 : import type {
94 : BillingStatusBannerAudience,
95 : BillingStatusBannerKind
96 : } from '@comfyorg/account-core/billing'
97 : import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities'
98 : import {
99 : isTopUpDeniedPastDue,
100 : usePaymentRecoveryDialog
101 : } from '@/platform/billing/composables/usePaymentRecoveryDialog'
102 : import { isMemberTopUpDenial } from '@comfyorg/account-core/billing'
103 : import { pausedBannerCopy } from '@/platform/billing/composables/usePausedBanner'
104 : import { usePlanEnded } from '@/platform/billing/composables/usePlanEnded'
105 : import { useResubscribe } from '@/platform/billing/composables/useResubscribe'
106 : import { useScheduledPlanChange } from '@/platform/billing/composables/useScheduledPlanChange'
107 : import { useWorkspaceTierLabel } from '@/platform/billing/composables/useWorkspaceTierLabel'
108 : import { useBillingUI } from '@/platform/billing/composables/useBillingUI'
109 : import { useBillingDialogs } from '@/platform/billing/composables/useBillingDialogs'
110 : import { usePlatformPlansLink } from '@/platform/billing/composables/usePlatformHandoff'
111 :
112 : type BannerAction =
113 : | 'addCredits'
114 : | 'reactivate'
115 : | 'choosePlan'
116 : | 'contactSales'
117 : | 'updatePayment'
118 :
119 : const { section } = defineProps<{
120 : section?: 'planCredits' | 'members' | 'allowlist' | 'billing'
121 : }>()
122 :
123 5 : const { t } = useI18n()
124 5 : const { longDate } = useLongDate()
125 5 : const { nextCreditRefillAt, subscription } = useBillingContext()
126 5 : const { permissions, canReactivatePlan, workspaceType } = useBillingUI()
127 5 : const {
128 : canTopUp,
129 : topUpDenial,
130 : hasResolvedCapabilities,
131 : canManageBilling,
132 : canOpenPlans,
133 : planKind,
134 : runDeniedPaymentPastDue
135 : } = useBillingCapabilities()
136 5 : const {
137 : kind: overallKind,
138 : lifecycleKind,
139 : audience,
140 : dismiss
141 : } = useBillingBanner()
142 5 : const kind = computed(() =>
143 : section === 'billing' ? lifecycleKind.value : overallKind.value
144 : )
145 5 : const { formatTierName } = useWorkspaceTierLabel()
146 5 : const { isResubscribing, handleResubscribe } = useResubscribe()
147 5 : const {
148 : scheduledChange,
149 : planName: scheduledPlanName,
150 : isDisplayable: canShowScheduledChange
151 : } = useScheduledPlanChange()
152 5 : const { showTopUpCreditsDialog } = useBillingDialogs()
153 5 : const { updatePayment, isUpdatingPayment } = usePaymentRecoveryDialog()
154 5 : const { button: plansButton, open: openPlans } = usePlatformPlansLink()
155 5 : const { isSalesManagedPlan, isEnterprisePlan: isEndedEnterprisePlan } =
156 : usePlanEnded()
157 :
158 5 : const canManage = computed(() => permissions.value.canManageSubscription)
159 : // Strictly ENTERPRISE: an unrecognized tier must not borrow Enterprise copy
160 : // (isUnknownTier's contract) nor lose its Reactivate path.
161 5 : const isEnterprisePlan = computed(
162 : () => subscription.value?.tier === 'ENTERPRISE'
163 : )
164 5 : const refillDate = computed(() => longDate(nextCreditRefillAt.value))
165 5 : const planEndDate = computed(() => longDate(subscription.value?.endDate))
166 5 : const planEndedDate = computed(() => {
167 0 : const current = subscription.value
168 0 : return longDate(
169 : current?.endedAt === undefined ? current?.endDate : current.endedAt
170 : )
171 : })
172 5 : const planName = computed(() => formatTierName(subscription.value?.tier, false))
173 :
174 : interface BannerView {
175 : muted: boolean
176 : title: string
177 : body: string
178 : action: BannerAction | null
179 : dismissible: boolean
180 : }
181 :
182 5 : const bs = 'workspacePanel.billingStatus'
183 :
184 5 : const audienceCopy = {
185 : team: {
186 : outOfCreditsBody: `${bs}.outOfCredits.body`,
187 : outOfCreditsBodyNoDate: `${bs}.outOfCredits.bodyNoDate`,
188 : outOfCreditsRefusedBody: `${bs}.outOfCredits.refusedBody`,
189 : outOfCreditsPausedBody: `${bs}.outOfCredits.pausedBody`,
190 : outOfCreditsPausedBodyNoDate: `${bs}.outOfCredits.pausedBodyNoDate`,
191 : endingTitle: `${bs}.ending.title`,
192 : endingBody: `${bs}.ending.body`
193 : },
194 : personal: {
195 : outOfCreditsBody: `${bs}.outOfCredits.personalBody`,
196 : outOfCreditsBodyNoDate: `${bs}.outOfCredits.personalBodyNoDate`,
197 : outOfCreditsRefusedBody: `${bs}.outOfCredits.refusedPersonalBody`,
198 : outOfCreditsPausedBody: `${bs}.outOfCredits.pausedPersonalBody`,
199 : outOfCreditsPausedBodyNoDate: `${bs}.outOfCredits.pausedPersonalBodyNoDate`,
200 : endingTitle: `${bs}.ending.personalTitle`,
201 : endingBody: `${bs}.ending.personalBody`
202 : }
203 : } satisfies Record<BillingStatusBannerAudience, Record<string, string>>
204 :
205 5 : const copy = computed(() => audienceCopy[audience.value ?? 'team'])
206 :
207 5 : const PLAN_LIFECYCLE_KINDS: ReadonlySet<BillingStatusBannerKind> = new Set([
208 : 'planEnded',
209 : 'ending',
210 : 'planChange'
211 : ])
212 :
213 5 : const isLifecycleKind = computed(
214 : () => kind.value !== null && PLAN_LIFECYCLE_KINDS.has(kind.value)
215 : )
216 :
217 5 : const isHiddenOnSection = computed(() => {
218 0 : if (section === 'billing') return !isLifecycleKind.value
219 0 : return (
220 : section === 'members' &&
221 : workspaceType.value === 'personal' &&
222 : isLifecycleKind.value
223 : )
224 : })
225 :
226 : // Sales-managed plans (Enterprise, and unrecognized tiers, which fail closed
227 : // to sales) return through sales; only a strict ENTERPRISE tier is named.
228 0 : function planEndedCopy(): {
229 : title: string
230 : ownerBody: string
231 : memberBody: string
232 : } {
233 0 : const date = planEndedDate.value
234 0 : if (audience.value === 'personal') {
235 0 : const plan = planName.value
236 0 : const body = t(`${bs}.planEnded.personalBody`)
237 0 : return {
238 : title: date
239 : ? t(`${bs}.planEnded.personalTitle`, { plan, date })
240 : : t(`${bs}.planEnded.personalTitleNoDate`, { plan }),
241 : ownerBody: body,
242 : memberBody: body
243 : }
244 : }
245 0 : if (!isSalesManagedPlan.value) {
246 0 : return {
247 : title: date
248 : ? t(`${bs}.planEnded.teamTitle`, { date })
249 : : t('workspacePanel.members.endedTeamTitle'),
250 : ownerBody: t(`${bs}.planEnded.teamBody`),
251 : memberBody: t(`${bs}.planEnded.teamMemberBody`)
252 : }
253 : }
254 0 : const named = isEndedEnterprisePlan.value
255 0 : return {
256 : title: date
257 : ? t(`${bs}.planEnded.${named ? 'enterpriseTitle' : 'planTitle'}`, {
258 : date
259 : })
260 : : t(
261 : `workspacePanel.members.${named ? 'endedEnterpriseTitle' : 'endedPlanTitle'}`
262 : ),
263 : ownerBody: t(`${bs}.planEnded.${named ? 'enterpriseBody' : 'salesBody'}`),
264 : memberBody: t(`${bs}.planEnded.salesMemberBody`)
265 : }
266 : }
267 :
268 0 : function planEndedAction(): BannerAction | null {
269 0 : if (planKind.value === 'sales_managed')
270 0 : return canManage.value ? 'contactSales' : null
271 0 : return canOpenPlans.value ? 'choosePlan' : null
272 : }
273 :
274 5 : const planEndedView = (): BannerView => {
275 0 : const copy = planEndedCopy()
276 0 : return {
277 : muted: true,
278 : title: copy.title,
279 : body: canManage.value ? copy.ownerBody : copy.memberBody,
280 : action: planEndedAction(),
281 : dismissible: true
282 : }
283 : }
284 :
285 5 : const outOfCreditsBody = (key: string, noDateKey: string): string =>
286 : refillDate.value ? t(key, { date: refillDate.value }) : t(noDateKey)
287 :
288 5 : const pausedView = (): BannerView => {
289 0 : const paused = pausedBannerCopy(canManageBilling.value)
290 0 : return {
291 : muted: paused.muted,
292 : title: t(paused.titleKey),
293 : body: t(paused.bodyKey),
294 : action: paused.action,
295 : dismissible: false
296 : }
297 : }
298 :
299 0 : function pastDueBodyKey(): string {
300 0 : if (audience.value === 'personal')
301 0 : return `${bs}.outOfCredits.pastDuePersonalBody`
302 0 : return canManageBilling.value
303 : ? `${bs}.outOfCredits.pastDueBody`
304 : : `${bs}.outOfCredits.pastDueMemberBody`
305 : }
306 :
307 5 : const pastDueView = (): BannerView => ({
308 : muted: false,
309 : title: t(`${bs}.outOfCredits.title`),
310 : body: t(pastDueBodyKey()),
311 : action: canManageBilling.value ? 'updatePayment' : null,
312 : dismissible: true
313 : })
314 :
315 0 : function refusedOutOfCreditsBody(): string {
316 0 : const denial = topUpDenial.value
317 0 : if (isMemberTopUpDenial(denial)) {
318 0 : return outOfCreditsBody(
319 : `${bs}.outOfCredits.memberBody`,
320 : `${bs}.outOfCredits.memberBodyNoDate`
321 : )
322 : }
323 0 : if (denial === 'topup_purchases_paused') {
324 0 : return outOfCreditsBody(
325 : copy.value.outOfCreditsPausedBody,
326 : copy.value.outOfCreditsPausedBodyNoDate
327 : )
328 : }
329 0 : return t(copy.value.outOfCreditsRefusedBody)
330 : }
331 :
332 5 : const outOfCreditsView = (): BannerView | null => {
333 0 : if (runDeniedPaymentPastDue.value) return pastDueView()
334 0 : if (isTopUpDeniedPastDue(topUpDenial.value)) return pastDueView()
335 0 : if (canTopUp.value) {
336 0 : return {
337 : muted: false,
338 : title: t(`${bs}.outOfCredits.title`),
339 : body: outOfCreditsBody(
340 : copy.value.outOfCreditsBody,
341 : copy.value.outOfCreditsBodyNoDate
342 : ),
343 : action: 'addCredits',
344 : dismissible: true
345 : }
346 : }
347 0 : if (!hasResolvedCapabilities.value) return null
348 0 : return {
349 : muted: false,
350 : title: t(`${bs}.outOfCredits.title`),
351 : body: refusedOutOfCreditsBody(),
352 : action: null,
353 : dismissible: true
354 : }
355 : }
356 :
357 : // An Enterprise contract renews through sales, not self-serve reactivation,
358 : // so it gets its own copy and never a Reactivate action — even where the
359 : // legacy rail would resolve canReactivatePlan true.
360 5 : const enterpriseEndingView = (): BannerView => ({
361 : muted: true,
362 : title: t(`${bs}.ending.enterpriseTitle`, { date: planEndDate.value }),
363 : body: canManage.value
364 : ? t(`${bs}.ending.enterpriseBody`)
365 : : t(`${bs}.ending.memberBody`),
366 : action: canManage.value ? 'contactSales' : null,
367 : dismissible: false
368 : })
369 :
370 5 : const selfServeEndingView = (): BannerView => ({
371 : muted: true,
372 : title: t(copy.value.endingTitle, {
373 : plan: planName.value,
374 : date: planEndDate.value
375 : }),
376 : body: canManage.value
377 : ? t(copy.value.endingBody)
378 : : t(`${bs}.ending.memberBody`),
379 : action: canManage.value && canReactivatePlan.value ? 'reactivate' : null,
380 : dismissible: false
381 : })
382 :
383 5 : const endingView = (): BannerView =>
384 : isEnterprisePlan.value ? enterpriseEndingView() : selfServeEndingView()
385 :
386 5 : const planChangeView = (): BannerView | null =>
387 : canShowScheduledChange.value
388 : ? {
389 : muted: true,
390 : title: t(`${bs}.planChange.title`, {
391 : plan: scheduledPlanName.value,
392 : date: longDate(scheduledChange.value?.effective_at)
393 : }),
394 : body: t(`${bs}.planChange.body`),
395 : action: null,
396 : dismissible: true
397 : }
398 : : null
399 :
400 5 : const bannerViews: Record<BillingStatusBannerKind, () => BannerView | null> = {
401 : paused: pausedView,
402 : planEnded: planEndedView,
403 : outOfCredits: outOfCreditsView,
404 : ending: endingView,
405 : planChange: planChangeView
406 : }
407 :
408 0 : function forBillingTab(view: BannerView): BannerView {
409 0 : return { ...view, dismissible: false }
410 : }
411 :
412 5 : const banner = computed<BannerView | null>(() => {
413 5 : if (!kind.value || isHiddenOnSection.value) return null
414 0 : const view = bannerViews[kind.value]()
415 5 : return view && section === 'billing' ? forBillingTab(view) : view
416 : })
417 :
418 0 : function handleAddCredits() {
419 0 : void showTopUpCreditsDialog()
420 : }
421 0 : function handleContactSales() {
422 0 : window.open(ENTERPRISE_URL, '_blank', 'noopener,noreferrer')
423 : }
424 : </script>
|