|
1 | 1 | <template> |
2 | 2 | <div> |
3 | | - <h1>Dashboard Overview {{ isLoading }}</h1> |
4 | | - |
5 | | - <pre> |
6 | | - {{ balance }} |
7 | | - </pre> |
8 | | - |
9 | | - <p> |
10 | | - spent balance: |
11 | | - {{ spent }} |
12 | | - </p> |
| 3 | + <div class="mb-8"> |
| 4 | + <h1 class="text-h5 font-weight-bold"> |
| 5 | + Dashboard Overview |
| 6 | + </h1> |
| 7 | + <p class="text-body-2 mt-1 opacity-70"> |
| 8 | + Your Mycelium Cloud platform at a glance |
| 9 | + </p> |
13 | 10 |
|
14 | | - <p> |
15 | | - clusters Count: |
16 | | - {{ deploymentsCount }} |
17 | | - </p> |
| 11 | + <v-row class="mt-4"> |
| 12 | + <v-col |
| 13 | + v-for="stat in stats" |
| 14 | + :key="stat.id" |
| 15 | + cols="12" |
| 16 | + md="6" |
| 17 | + lg="4" |
| 18 | + > |
| 19 | + <StatsCard v-bind="stat" /> |
| 20 | + </v-col> |
| 21 | + </v-row> |
| 22 | + </div> |
18 | 23 |
|
19 | 24 | <div> |
20 | 25 | <p class="text-h6 font-weight-bold mb-4"> |
@@ -71,20 +76,46 @@ import type { ModelsInvoice } from "~/generated/api" |
71 | 76 |
|
72 | 77 | const api = useApi() |
73 | 78 |
|
74 | | -const { state: balance, isLoading } = useAsyncState(async () => { |
| 79 | +const { state: balance } = useAsyncState(async () => { |
75 | 80 | const { data } = await api.users.getUserBalance() |
76 | | - return data |
77 | | -}, null) |
| 81 | + return toPrecision(data.data?.balance_usd ?? 0, 2) |
| 82 | +}, 0) |
78 | 83 |
|
79 | 84 | const { state: spent } = useAsyncState(async () => { |
80 | 85 | const { data } = await api.invoices.getInvoices() |
81 | 86 | const { invoices } = data.data as unknown as { invoices: ModelsInvoice[] } |
82 | 87 | const total = invoices.reduce((a, b) => a + (b.total ?? 0) * 1000, 0) ?? 0 |
83 | 88 | return toPrecision(total / 1000, 2) |
84 | | -}, null) |
| 89 | +}, 0) |
85 | 90 |
|
86 | 91 | const { state: deploymentsCount } = useAsyncState(async () => { |
87 | 92 | const { data } = await api.deployments.deploymentsGet() |
88 | 93 | return data.data?.count ?? 0 |
89 | 94 | }, 0) |
| 95 | +
|
| 96 | +const stats = computed<StatsResource[]>(() => { |
| 97 | + return [ |
| 98 | + { |
| 99 | + id: "clusters", |
| 100 | + title: "Active Clusters", |
| 101 | + icon: "mdi-server", |
| 102 | + color: "#359EFF", |
| 103 | + value: deploymentsCount.value, |
| 104 | + }, |
| 105 | + { |
| 106 | + id: "balance", |
| 107 | + title: "Balance", |
| 108 | + icon: "mdi-wallet-bifold", |
| 109 | + color: "#607AFB", |
| 110 | + value: `$${balance.value}`, |
| 111 | + }, |
| 112 | + { |
| 113 | + id: "spent", |
| 114 | + title: "Total Spent", |
| 115 | + icon: "mdi-currency-usd", |
| 116 | + color: "#39E079", |
| 117 | + value: `$${spent.value}`, |
| 118 | + }, |
| 119 | + ] |
| 120 | +}) |
90 | 121 | </script> |
0 commit comments