Line data Source code
1 5 : <template>
2 0 : <div
3 : :class="
4 : cn(
5 : 'flex flex-1 flex-col gap-2 border-r border-border px-5 py-4',
6 : classes?.root
7 : )
8 : "
9 : >
10 : <span class="flex items-center gap-1 text-sm text-muted-foreground">
11 : {{ copy.plan }}
12 : <BillingInfoTip :text="copy.planTooltip" />
13 : </span>
14 : <span
15 : v-if="planOfPool"
16 : class="text-sm text-muted-foreground"
17 : data-testid="billing-credits-plan"
18 : >
19 : {{ planOfPool.before
20 : }}<span class="font-semibold text-foreground">{{ remaining }}</span
21 : >{{ planOfPool.after }}
22 : </span>
23 : <span
24 : v-else
25 : class="text-sm font-semibold text-foreground"
26 : data-testid="billing-credits-plan"
27 : >
28 : {{ remaining }}
29 : </span>
30 : <div
31 : v-if="dateLine || usedPercent !== null"
32 : class="flex flex-col gap-2 pt-2"
33 : >
34 : <div
35 : class="flex items-center justify-between gap-2 text-sm text-muted-foreground"
36 : >
37 : <span data-testid="billing-credits-plan-date">{{ dateLine }}</span>
38 : <span
39 : v-if="usedPercent !== null"
40 : data-testid="billing-credits-plan-used"
41 : >
42 : {{ copy.planUsed(usedPercent) }}
43 : </span>
44 : </div>
45 : <div
46 : v-if="usedPercent !== null"
47 : role="meter"
48 : :aria-label="copy.plan"
49 : aria-valuemin="0"
50 : aria-valuemax="100"
51 : :aria-valuenow="usedPercent"
52 : :class="
53 : cn('h-1 overflow-hidden rounded-full bg-accent', classes?.meter)
54 : "
55 : >
56 : <div
57 : class="h-full rounded-full bg-foreground"
58 : :style="{ width: `${usedPercent}%` }"
59 : />
60 : </div>
61 : </div>
62 : </div>
63 : </template>
64 :
65 : <script setup lang="ts">
66 : import { computed } from 'vue'
67 :
68 : import type { PlanCreditsState } from '@comfyorg/account-core/billing'
69 : import { cn } from '@comfyorg/tailwind-utils'
70 :
71 : import {
72 : centsToCredits,
73 : formatWholeCredits,
74 : planDateLine,
75 : planUsedPercent,
76 : splitPlanOfPool
77 : } from './creditsCardCopy'
78 : import BillingInfoTip from './BillingInfoTip.vue'
79 : import type { CreditsCardCopy } from './creditsCardCopy'
80 :
81 : const { plan, copy, locale, classes } = defineProps<{
82 : plan: PlanCreditsState
83 : copy: CreditsCardCopy
84 : locale: string
85 : classes?: Partial<Record<'root' | 'meter', string>>
86 : }>()
87 :
88 0 : const remaining = computed(() =>
89 : formatWholeCredits(centsToCredits(plan.planCents), locale)
90 : )
91 :
92 0 : const planOfPool = computed(() =>
93 : plan.planPoolCredits
94 : ? splitPlanOfPool(
95 : copy.planOfPool,
96 : formatWholeCredits(plan.planPoolCredits, locale)
97 : )
98 : : null
99 : )
100 :
101 0 : const usedPercent = computed(() => planUsedPercent(plan))
102 :
103 0 : const dateLine = computed(() => planDateLine(plan, copy, locale))
104 : </script>
|