Skip to content

Commit 2535957

Browse files
authored
[Refactor] Extract user credit component (#3630)
1 parent d0b99b9 commit 2535957

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<template>
2+
<div v-if="balanceLoading" class="flex items-center gap-1">
3+
<div class="flex items-center gap-2">
4+
<Skeleton shape="circle" width="1.5rem" height="1.5rem" />
5+
</div>
6+
<div class="flex-1"></div>
7+
<Skeleton width="8rem" height="2rem" />
8+
</div>
9+
<div v-else class="flex items-center gap-1">
10+
<Tag
11+
severity="secondary"
12+
icon="pi pi-dollar"
13+
rounded
14+
class="text-amber-400 p-1"
15+
/>
16+
<div :class="textClass">{{ formattedBalance }}</div>
17+
</div>
18+
</template>
19+
20+
<script setup lang="ts">
21+
import Skeleton from 'primevue/skeleton'
22+
import Tag from 'primevue/tag'
23+
import { computed } from 'vue'
24+
25+
import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'
26+
import { formatMetronomeCurrency } from '@/utils/formatUtil'
27+
28+
const { textClass } = defineProps<{
29+
textClass?: string
30+
}>()
31+
32+
const authStore = useFirebaseAuthStore()
33+
const balanceLoading = computed(() => authStore.isFetchingBalance)
34+
35+
const formattedBalance = computed(() => {
36+
if (!authStore.balance) return '0.00'
37+
return formatMetronomeCurrency(authStore.balance.amount_micros, 'usd')
38+
})
39+
</script>

src/components/dialog/content/TopUpCreditsDialogContent.vue

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,7 @@
1616
{{ $t('credits.yourCreditBalance') }}
1717
</div>
1818
<div class="flex items-center justify-between w-full">
19-
<div class="flex items-center gap-2">
20-
<Tag
21-
severity="secondary"
22-
icon="pi pi-dollar"
23-
rounded
24-
class="text-amber-400 p-1"
25-
/>
26-
<span class="text-2xl">{{ formattedBalance }}</span>
27-
</div>
19+
<UserCredit text-class="text-2xl" />
2820
<Button
2921
outlined
3022
severity="secondary"
@@ -109,9 +101,9 @@ import ProgressSpinner from 'primevue/progressspinner'
109101
import Tag from 'primevue/tag'
110102
import { computed, onBeforeUnmount, ref } from 'vue'
111103
104+
import UserCredit from '@/components/common/UserCredit.vue'
112105
import { useFirebaseAuthService } from '@/services/firebaseAuthService'
113106
import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'
114-
import { formatMetronomeCurrency } from '@/utils/formatUtil'
115107
116108
const {
117109
isInsufficientCredits = false,
@@ -129,11 +121,6 @@ const customAmount = ref<number>(100)
129121
const didClickBuyNow = ref(false)
130122
const loading = computed(() => authStore.loading)
131123
132-
const formattedBalance = computed(() => {
133-
if (!authStore.balance) return '0.000'
134-
return formatMetronomeCurrency(authStore.balance.amount_micros, 'usd')
135-
})
136-
137124
const handleSeeDetails = async () => {
138125
await authService.accessBillingPortal()
139126
}

src/components/dialog/content/setting/CreditsPanel.vue

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,7 @@
1212
{{ $t('credits.yourCreditBalance') }}
1313
</h3>
1414
<div class="flex justify-between items-center">
15-
<div v-if="balanceLoading" class="flex items-center gap-1">
16-
<div class="flex items-center gap-2">
17-
<Skeleton shape="circle" width="1.5rem" height="1.5rem" />
18-
</div>
19-
<div class="flex-1"></div>
20-
<Skeleton width="8rem" height="2rem" />
21-
</div>
22-
<div v-else class="flex items-center gap-1">
23-
<Tag
24-
severity="secondary"
25-
icon="pi pi-dollar"
26-
rounded
27-
class="text-amber-400 p-1"
28-
/>
29-
<div class="text-3xl font-bold">{{ formattedBalance }}</div>
30-
</div>
15+
<UserCredit text-class="text-3xl font-bold" />
3116
<Skeleton v-if="loading" width="2rem" height="2rem" />
3217
<Button
3318
v-else
@@ -123,10 +108,10 @@ import DataTable from 'primevue/datatable'
123108
import Divider from 'primevue/divider'
124109
import Skeleton from 'primevue/skeleton'
125110
import TabPanel from 'primevue/tabpanel'
126-
import Tag from 'primevue/tag'
127111
import { computed, ref } from 'vue'
128112
import { useI18n } from 'vue-i18n'
129113
114+
import UserCredit from '@/components/common/UserCredit.vue'
130115
import { useDialogService } from '@/services/dialogService'
131116
import { useFirebaseAuthService } from '@/services/firebaseAuthService'
132117
import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'
@@ -145,10 +130,6 @@ const authStore = useFirebaseAuthStore()
145130
const authService = useFirebaseAuthService()
146131
const loading = computed(() => authStore.loading)
147132
const balanceLoading = computed(() => authStore.isFetchingBalance)
148-
const formattedBalance = computed(() => {
149-
if (!authStore.balance) return '0.00'
150-
return formatMetronomeCurrency(authStore.balance.amount_micros, 'usd')
151-
})
152133
153134
const formattedLastUpdateTime = computed(() =>
154135
authStore.lastBalanceUpdateTime

0 commit comments

Comments
 (0)