Skip to content

Commit 57ec2ca

Browse files
committed
Fix: Update Ui
1 parent ac8f113 commit 57ec2ca

5 files changed

Lines changed: 3060 additions & 3012 deletions

File tree

src/views/analytics/UserAnalytics.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<v-container >
2+
<v-container>
33
<v-row>
44
<!-- Left Column -->
55
<v-col cols="12">
@@ -24,7 +24,7 @@
2424
</v-col>
2525

2626
</v-row>
27-
<v-row>
27+
<v-row>
2828
<v-col cols="12">
2929
<DeviceStats :env="env" />
3030
</v-col>
@@ -41,7 +41,7 @@ export default {
4141
name: "UserAnalytics",
4242
data() {
4343
return {
44-
isProd: false,
44+
isProd: false,
4545
};
4646
},
4747
computed: {

src/views/analytics/components/DemographicStats.vue

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export default {
7979
8080
async refreshData() {
8181
await this.fetchData();
82+
await this.$nextTick();
8283
await this.initChart();
8384
},
8485
@@ -97,11 +98,21 @@ export default {
9798
},
9899
99100
async initChart() {
100-
// 1. Fetch World GeoJSON (ECharts needs this to draw the map)
101-
const worldData = await fetch('https://cdn.jsdelivr.net/npm/echarts@4.9.0/map/json/world.json').then(res => res.json());
102-
echarts.registerMap('world', worldData);
103-
104101
const chartDom = this.$refs.worldMap;
102+
if (!chartDom) return;
103+
104+
if (this.chart) {
105+
this.chart.dispose();
106+
}
107+
108+
try {
109+
const worldData = await fetch('https://cdn.jsdelivr.net/npm/echarts@4.9.0/map/json/world.json').then(res => res.json());
110+
echarts.registerMap('world', worldData);
111+
} catch (error) {
112+
console.error('Error loading world map:', error);
113+
return;
114+
}
115+
105116
this.chart = echarts.init(chartDom);
106117
107118
// 2. Format country data for ECharts (Mapping ISO codes to Map Names if necessary)
@@ -113,7 +124,7 @@ export default {
113124
// value: value
114125
// }));
115126
116-
const mapData = Object.entries(this.demographics.countries).map(([code, value]) => ({
127+
const mapData = Object.entries(this.demographics.countries || {}).map(([code, value]) => ({
117128
name: countries.getName(code, "en") || code, // Dynamically gets "India" from "IN"
118129
value: value
119130
}));

src/views/analytics/components/DeviceStats.vue

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export default {
6464
},
6565
async mounted() {
6666
await this.fetchDevices();
67+
await this.$nextTick();
6768
this.initChart();
6869
window.addEventListener('resize', this.handleResize);
6970
},
@@ -72,19 +73,27 @@ export default {
7273
if (this.chart) this.chart.dispose();
7374
},
7475
watch: {
75-
env() {
76-
this.fetchDevices();
76+
async env() {
77+
await this.refreshData();
7778
}
7879
},
7980
methods: {
8081
...mapActions('mainStore', ['fetchAnalyticsDeviceStats']),
8182
83+
async refreshData() {
84+
await this.fetchDevices();
85+
await this.$nextTick();
86+
this.initChart();
87+
},
88+
8289
async fetchDevices() {
8390
this.loading = true;
8491
try {
8592
const response = await this.fetchAnalyticsDeviceStats({ env: this.env });
86-
if (response && response.data) {
93+
if (response && Array.isArray(response.data)) {
8794
this.deviceData = response.data;
95+
} else {
96+
this.deviceData = [];
8897
}
8998
} catch (err) {
9099
console.error("API Error:", err);
@@ -101,6 +110,11 @@ export default {
101110
102111
initChart() {
103112
if (!this.$refs.deviceChart) return;
113+
114+
if (this.chart) {
115+
this.chart.dispose();
116+
}
117+
104118
this.chart = echarts.init(this.$refs.deviceChart);
105119
106120
const chartData = this.deviceData.map(item => ({

src/views/analytics/components/Overview.vue

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div class="stat-card border-blue">
2020
<div class="card-content">
2121
<p class="label">Total Verifications</p>
22-
<h3 class="value">{{ metrics.totalVerifications.toLocaleString() }}</h3>
22+
<h3 class="value">{{ formatNumber(metrics.totalVerifications) }}</h3>
2323
</div>
2424
<p class="subtext text-muted italic">Across all channels</p>
2525
</div>
@@ -59,6 +59,13 @@
5959
<script>
6060
import { mapActions } from 'vuex/dist/vuex.common.js';
6161
62+
const getDefaultMetrics = () => ({
63+
totalVerifications: 0,
64+
completionRate: 0,
65+
successRate: 0,
66+
dropOffRate: 0
67+
});
68+
6269
export default {
6370
name: 'AnalyticsOverview',
6471
props: {
@@ -71,12 +78,7 @@ export default {
7178
return {
7279
loading: true,
7380
error: null,
74-
metrics: {
75-
totalVerifications: 0,
76-
completionRate: 0,
77-
successRate: 0,
78-
dropOffRate: 0
79-
}
81+
metrics: getDefaultMetrics()
8082
};
8183
},
8284
mounted() {
@@ -89,17 +91,28 @@ export default {
8991
},
9092
methods: {
9193
...mapActions('mainStore', ['fetchAnalyticsOverview']),
94+
formatNumber(value) {
95+
return Number(value || 0).toLocaleString();
96+
},
9297
async fetchOverviewData() {
9398
this.loading = true;
9499
this.error = null;
95100
try {
96101
const response = await this.fetchAnalyticsOverview({ env: this.env });
97102
if (response && response.data) {
98-
this.metrics = response.data;
103+
this.metrics = {
104+
...getDefaultMetrics(),
105+
totalVerifications: Number(response.data.totalVerifications) || 0,
106+
completionRate: Number(response.data.completionRate) || 0,
107+
successRate: Number(response.data.successRate) || 0,
108+
dropOffRate: Number(response.data.dropOffRate) || 0
109+
};
99110
} else {
111+
this.metrics = getDefaultMetrics();
100112
this.error = "Data format mismatch from server.";
101113
}
102114
} catch (err) {
115+
this.metrics = getDefaultMetrics();
103116
this.error = "Unable to load dashboard data.";
104117
} finally {
105118
this.loading = false;

0 commit comments

Comments
 (0)