generated from VeeamCommunity/veeamcommunity-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBillingDashboardScreen.js
382 lines (357 loc) · 13.5 KB
/
BillingDashboardScreen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
import React, { useEffect, useState } from 'react';
import { SafeAreaView, StyleSheet, Text, View, ScrollView, Alert, TouchableOpacity, Dimensions } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import axios from 'axios';
import { BarChart, PieChart } from 'react-native-gifted-charts';
import Icon from 'react-native-vector-icons/MaterialIcons';
const { width } = Dimensions.get('window');
const BillingDashboardScreen = () => {
const [usageData, setUsageData] = useState(null);
const [expandedCards, setExpandedCards] = useState({});
useEffect(() => {
fetchUsageData();
}, []);
const fetchUsageData = async () => {
try {
const baseUrl = await AsyncStorage.getItem('baseUrl');
const accessToken = await AsyncStorage.getItem('accessToken');
const headers = { Authorization: `Bearer ${accessToken}` };
const usageResponse = await axios.get(`${baseUrl}/organizations/companies/usage`, { headers });
setUsageData(processUsageData(usageResponse.data.data[0].counters));
} catch (error) {
console.error('Error fetching usage data:', error);
Alert.alert('Error', 'Failed to fetch usage data. Please try again later.');
}
};
const processUsageData = (counters) => {
return {
backups: {
vm: findCounterValue(counters, 'VmCloudBackups'),
server: findCounterValue(counters, 'ServerCloudBackups'),
workstation: findCounterValue(counters, 'WorkstationCloudBackups'),
},
dataTransfer: {
agentIn: findCounterValue(counters, 'AgentCloudBackupDataTransferIn'),
agentOut: findCounterValue(counters, 'AgentCloudBackupDataTransferOut'),
vbrIn: findCounterValue(counters, 'VbrCloudBackupsDataTransferIn'),
vbrOut: findCounterValue(counters, 'VbrCloudBackupsDataTransferOut'),
},
cloudReplicas: {
count: findCounterValue(counters, 'VmCloudReplicas'),
computeTime: findCounterValue(counters, 'VmCloudReplicaComputeTime'),
storageUsage: findCounterValue(counters, 'VmCloudReplicaStorageUsage'),
dataIn: findCounterValue(counters, 'VbrCloudReplicaDataTransferIn'),
dataOut: findCounterValue(counters, 'VbrCloudReplicaDataTransferOut'),
},
cloudRepositoryUsage: {
vm: findCounterValue(counters, 'CloudRepositoryUsageByVm'),
serverAgent: findCounterValue(counters, 'CloudRepositoryUsageByServerAgent'),
workstationAgent: findCounterValue(counters, 'CloudRepositoryUsageByWorkstationAgent'),
},
managedResources: {
serverAgents: findCounterValue(counters, 'ManagedServerAgents'),
workstationAgents: findCounterValue(counters, 'ManagedWorkstationAgents'),
vms: findCounterValue(counters, 'ManagedVms'),
cloudVms: findCounterValue(counters, 'ManagedCloudVms'),
},
fileShares: {
archiveSize: findCounterValue(counters, 'FileShareArchiveSize'),
backupSize: findCounterValue(counters, 'FileShareBackupSize'),
sourceSize: findCounterValue(counters, 'FileShareSourceSize'),
protected: findCounterValue(counters, 'ProtectedFileShares'),
},
objectStorage: {
archiveSize: findCounterValue(counters, 'ObjectStorageArchiveSize'),
backupSize: findCounterValue(counters, 'ObjectStorageBackupSize'),
sourceSize: findCounterValue(counters, 'ObjectStorageSourceSize'),
protected: findCounterValue(counters, 'ProtectedObjectStorages'),
},
cloudStorage: {
total: findCounterValue(counters, 'CloudTotalUsage'),
regular: findCounterValue(counters, 'CloudRegularStorageUsage'),
object: findCounterValue(counters, 'CloudObjectStorageUsage'),
},
vms: {
replicated: findCounterValue(counters, 'ReplicatedVms'),
backedUp: findCounterValue(counters, 'BackedupVms'),
},
o365: {
archiveSize: findCounterValue(counters, 'Vb365ArchiveSize'),
backupSize: findCounterValue(counters, 'Vb365BackupSize'),
protectedGroups: findCounterValue(counters, 'Vb365ProtectedGroups'),
protectedSites: findCounterValue(counters, 'Vb365ProtectedSites'),
protectedTeams: findCounterValue(counters, 'Vb365ProtectedTeams'),
protectedUsers: findCounterValue(counters, 'Vb365ProtectedUsers'),
},
};
};
const findCounterValue = (counters, type) => {
const counter = counters.find(c => c.type === type);
return counter ? counter.value : 0;
};
const bytesToSize = (bytes) => {
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes === 0) return '0 Bytes';
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
};
const toggleCard = (cardName) => {
setExpandedCards(prev => ({ ...prev, [cardName]: !prev[cardName] }));
};
const renderCard = (title, content, cardName) => {
const isExpanded = expandedCards[cardName];
return (
<TouchableOpacity style={styles.card} onPress={() => toggleCard(cardName)}>
<View style={styles.cardHeader}>
<Text style={styles.cardTitle}>{title}</Text>
<Icon name={isExpanded ? 'expand-less' : 'expand-more'} size={24} color="#004D40" />
</View>
{isExpanded && content}
</TouchableOpacity>
);
};
const renderBackupsChart = () => {
if (!usageData) return null;
const data = [
{ value: usageData.backups.vm, label: 'VM', frontColor: '#177AD5' },
{ value: usageData.backups.server, label: 'Server', frontColor: '#79D2DE' },
{ value: usageData.backups.workstation, label: 'Workstation', frontColor: '#F5A623' },
];
return (
<View>
<Text style={styles.chartTitle}>Cloud Backups</Text>
<BarChart
data={data}
width={width - 64}
height={200}
barWidth={40}
spacing={20}
roundedTop
roundedBottom
hideRules
xAxisThickness={0}
yAxisThickness={0}
yAxisTextStyle={{ color: '#333' }}
noOfSections={3}
maxValue={Math.max(...data.map(item => item.value), 10)}
labelWidth={40}
backgroundColor="#fff"
/>
</View>
);
};
const renderCloudStorageUsageChart = () => {
if (!usageData) return null;
const data = [
{ value: usageData.cloudStorage.regular, label: 'Regular', color: '#177AD5' },
{ value: usageData.cloudStorage.object, label: 'Object', color: '#79D2DE' },
];
return (
<View>
<Text style={styles.chartTitle}>Cloud Storage Usage</Text>
<PieChart
data={data}
width={width - 64}
height={200}
innerRadius={60}
centerLabelComponent={() => (
<View style={styles.centerLabel}>
<Text style={styles.centerLabelText}>{bytesToSize(usageData.cloudStorage.total)}</Text>
<Text style={styles.centerLabelSubtext}>Total</Text>
</View>
)}
/>
<View style={styles.legendContainer}>
{data.map((item, index) => (
<View key={index} style={styles.legendItem}>
<View style={[styles.legendColor, { backgroundColor: item.color }]} />
<Text style={styles.legendText}>{`${item.label}: ${bytesToSize(item.value)}`}</Text>
</View>
))}
</View>
</View>
);
};
const renderDataTransferInfo = () => {
if (!usageData) return null;
return (
<View>
<Text style={styles.infoText}>Agent Inbound: {bytesToSize(usageData.dataTransfer.agentIn)}</Text>
<Text style={styles.infoText}>Agent Outbound: {bytesToSize(usageData.dataTransfer.agentOut)}</Text>
<Text style={styles.infoText}>VBR Inbound: {bytesToSize(usageData.dataTransfer.vbrIn)}</Text>
<Text style={styles.infoText}>VBR Outbound: {bytesToSize(usageData.dataTransfer.vbrOut)}</Text>
</View>
);
};
const renderCloudReplicasInfo = () => {
if (!usageData) return null;
return (
<View>
<Text style={styles.infoText}>Number of Replicas: {usageData.cloudReplicas.count}</Text>
<Text style={styles.infoText}>Compute Time: {usageData.cloudReplicas.computeTime} seconds</Text>
<Text style={styles.infoText}>Storage Used: {bytesToSize(usageData.cloudReplicas.storageUsage)}</Text>
<Text style={styles.infoText}>Data Inbound: {bytesToSize(usageData.cloudReplicas.dataIn)}</Text>
<Text style={styles.infoText}>Data Outbound: {bytesToSize(usageData.cloudReplicas.dataOut)}</Text>
</View>
);
};
const renderManagedResourcesInfo = () => {
if (!usageData) return null;
return (
<View>
<Text style={styles.infoText}>Server Agents: {usageData.managedResources.serverAgents}</Text>
<Text style={styles.infoText}>Workstation Agents: {usageData.managedResources.workstationAgents}</Text>
<Text style={styles.infoText}>Virtual Machines: {usageData.managedResources.vms}</Text>
<Text style={styles.infoText}>Cloud VMs: {usageData.managedResources.cloudVms}</Text>
</View>
);
};
const renderFileSharesInfo = () => {
if (!usageData) return null;
return (
<View>
<Text style={styles.infoText}>Archive Size: {bytesToSize(usageData.fileShares.archiveSize)}</Text>
<Text style={styles.infoText}>Backup Size: {bytesToSize(usageData.fileShares.backupSize)}</Text>
<Text style={styles.infoText}>Source Size: {bytesToSize(usageData.fileShares.sourceSize)}</Text>
<Text style={styles.infoText}>Protected Shares: {usageData.fileShares.protected}</Text>
</View>
);
};
const renderO365Info = () => {
if (!usageData) return null;
return (
<View>
<Text style={styles.infoText}>Archive Size: {bytesToSize(usageData.o365.archiveSize)}</Text>
<Text style={styles.infoText}>Backup Size: {bytesToSize(usageData.o365.backupSize)}</Text>
<Text style={styles.infoText}>Protected Groups: {usageData.o365.protectedGroups}</Text>
<Text style={styles.infoText}>Protected Sites: {usageData.o365.protectedSites}</Text>
<Text style={styles.infoText}>Protected Teams: {usageData.o365.protectedTeams}</Text>
<Text style={styles.infoText}>Protected Users: {usageData.o365.protectedUsers}</Text>
</View>
);
};
const renderO365ProtectedItemsChart = () => {
if (!usageData) return null;
const data = [
{ value: usageData.o365.protectedGroups, label: 'Groups', frontColor: '#177AD5' },
{ value: usageData.o365.protectedSites, label: 'Sites', frontColor: '#79D2DE' },
{ value: usageData.o365.protectedTeams, label: 'Teams', frontColor: '#F5A623' },
{ value: usageData.o365.protectedUsers, label: 'Users', frontColor: '#FD6585' },
];
return (
<View>
<Text style={styles.chartTitle}>O365 Protected Items</Text>
<BarChart
data={data}
width={width - 64}
height={200}
barWidth={40}
spacing={20}
roundedTop
roundedBottom
hideRules
xAxisThickness={0}
yAxisThickness={0}
yAxisTextStyle={{ color: '#333' }}
noOfSections={5}
maxValue={Math.max(...data.map(item => item.value), 10)}
labelWidth={40}
backgroundColor="#fff"
/>
</View>
);
};
return (
<SafeAreaView style={styles.container}>
<ScrollView contentContainerStyle={styles.scrollContent}>
<Text style={styles.title}>Billing Dashboard</Text>
{renderCard('Cloud Backups', renderBackupsChart(), 'backups')}
{renderCard('Cloud Storage Usage', renderCloudStorageUsageChart(), 'cloudStorage')}
{renderCard('Data Transfer', renderDataTransferInfo(), 'dataTransfer')}
{renderCard('Cloud Replicas', renderCloudReplicasInfo(), 'cloudReplicas')}
{renderCard('Managed Resources', renderManagedResourcesInfo(), 'managedResources')}
{renderCard('File Shares', renderFileSharesInfo(), 'fileShares')}
{renderCard('Office 365 Backup', renderO365Info(), 'o365')}
{renderCard('O365 Protected Items', renderO365ProtectedItemsChart(), 'o365Chart')}
</ScrollView>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5F5F5',
},
scrollContent: {
padding: 16,
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 16,
color: '#333',
},
card: {
backgroundColor: '#FFFFFF',
borderRadius: 12,
padding: 16,
marginBottom: 16,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.1,
shadowRadius: 4,
elevation: 3,
},
cardHeader: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: 8,
},
cardTitle: {
fontSize: 18,
fontWeight: 'bold',
color: '#004D40',
},
chartTitle: {
fontSize: 16,
fontWeight: 'bold',
marginBottom: 8,
color: '#004D40',
},
infoText: {
fontSize: 14,
marginBottom: 5,
color: '#333',
},
centerLabel: {
justifyContent: 'center',
alignItems: 'center',
},
centerLabelText: {
fontSize: 18,
fontWeight: 'bold',
},
centerLabelSubtext: {
fontSize: 12,
},
legendContainer: {
flexDirection: 'row',
justifyContent: 'space-around',
marginTop: 20,
},
legendItem: {
flexDirection: 'row',
alignItems: 'center',
},
legendColor: {
width: 10,
height: 10,
borderRadius: 5,
marginRight: 5,
},
legendText: {
fontSize: 12,
},
});
export default BillingDashboardScreen;