2121 flat
2222 data-test =" devices-card"
2323 >
24- <v-card-title class =" text-h6 py-3" >
25- Device Management
26- </v-card-title >
24+ <v-card-title class =" text-h6 py-3" >Device Management</v-card-title >
2725 <v-card-text class =" pa-4 pt-0" >
2826 <v-row
2927 dense
4139 <div class =" text-h4 font-weight-bold" >
4240 {{ stats.registered_devices }}
4341 </div >
44- <div class =" text-caption text-medium-emphasis" >
45- Total
46- </div >
42+ <div class =" text-caption text-medium-emphasis" >Total</div >
4743 </v-card >
4844 </v-col >
4945 <v-col
5854 <div class =" text-h4 font-weight-bold" >
5955 {{ stats.online_devices }}
6056 </div >
61- <div class =" text-caption text-medium-emphasis" >
62- Online
63- </div >
57+ <div class =" text-caption text-medium-emphasis" >Online</div >
6458 </v-card >
6559 </v-col >
6660 <v-col
7569 <div class =" text-h4 font-weight-bold" >
7670 {{ stats.pending_devices }}
7771 </div >
78- <div class =" text-caption text-medium-emphasis" >
79- Pending
80- </div >
72+ <div class =" text-caption text-medium-emphasis" >Pending</div >
8173 </v-card >
8274 </v-col >
8375 <v-col
9284 <div class =" text-h4 font-weight-bold" >
9385 {{ offlineDevices }}
9486 </div >
95- <div class =" text-caption text-medium-emphasis" >
96- Offline
97- </div >
87+ <div class =" text-caption text-medium-emphasis" >Offline</div >
9888 </v-card >
9989 </v-col >
10090 </v-row >
188178 </span >
189179 </template >
190180 <div class =" d-flex align-center ga-2 mt-1" >
191- <v-btn
181+ <DeviceActionButton
182+ :uid =" device.uid"
183+ :name =" device.name"
184+ action =" accept"
185+ variant =" device"
186+ is-in-devices-dropdown
192187 color =" success"
193- variant =" flat"
194- size =" small"
195188 prepend-icon =" mdi-check-circle"
196189 :data-test =" `accept-${device.uid}`"
197- @click =" handleAccept(device.uid)"
198- >
199- Accept
200- </v-btn >
201- <v-btn
190+ @update =" handleUpdate"
191+ />
192+ <DeviceActionButton
193+ :uid =" device.uid"
194+ :name =" device.name"
195+ action =" reject"
196+ variant =" device"
197+ is-in-devices-dropdown
202198 color =" error"
203- variant =" tonal"
204- size =" small"
205199 prepend-icon =" mdi-cancel"
206200 :data-test =" `reject-${device.uid}`"
207- @click =" handleReject(device.uid)"
208- >
209- Reject
210- </v-btn >
201+ @update =" handleUpdate"
202+ />
211203 <v-btn
212204 icon =" mdi-dots-vertical"
213205 variant =" text"
273265 </v-list-item-subtitle >
274266 <template #append >
275267 <span class =" text-caption text-medium-emphasis" >
276- {{ device.online ? ' Active now' : formatTimeAgo(device.last_seen) }}
268+ {{ device.online ? " Active now" : formatTimeAgo(device.last_seen) }}
277269 </span >
278270 </template >
279271 </v-list-item >
@@ -325,6 +317,7 @@ import handleError from "@/utils/handleError";
325317import useSnackbar from " @/helpers/snackbar" ;
326318import moment from " moment" ;
327319import { IDevice } from " @/interfaces/IDevice" ;
320+ import DeviceActionButton from " @/components/Devices/DeviceActionButton.vue" ;
328321
329322const { smAndUp, thresholds } = useDisplay ();
330323const statsStore = useStatsStore ();
@@ -336,36 +329,22 @@ const activeTab = ref<"pending" | "recent">("pending");
336329const pendingDevicesList = ref <IDevice []>([]);
337330const recentDevicesList = ref <IDevice []>([]);
338331const stats = computed (() => statsStore .stats );
339- const offlineDevices = computed (() => stats .value .registered_devices - stats .value .online_devices );
340- const toggleDrawer = () => { isDrawerOpen .value = ! isDrawerOpen .value ; };
332+ const offlineDevices = computed (
333+ () => stats .value .registered_devices - stats .value .online_devices ,
334+ );
335+ const toggleDrawer = () => {
336+ isDrawerOpen .value = ! isDrawerOpen .value ;
337+ };
341338
342339const formatTimeAgo = (date : string | Date ) => {
343340 if (! date ) return " Unknown" ;
344341 return moment (date ).fromNow ();
345342};
346343
347- const handleAccept = async (uid : string ) => {
348- try {
349- await devicesStore .acceptDevice (uid );
350- await fetchStats ();
351- await fetchPendingDevices ();
352- snackbar .showSuccess (" Device accepted successfully" );
353- } catch (error : unknown ) {
354- snackbar .showError (" Failed to accept device" );
355- handleError (error );
356- }
357- };
358-
359- const handleReject = async (uid : string ) => {
360- try {
361- await devicesStore .rejectDevice (uid );
362- await fetchStats ();
363- await fetchPendingDevices ();
364- snackbar .showSuccess (" Device rejected successfully" );
365- } catch (error : unknown ) {
366- snackbar .showError (" Failed to reject device" );
367- handleError (error );
368- }
344+ const handleUpdate = async () => {
345+ await fetchStats ();
346+ await fetchPendingDevices ();
347+ await fetchRecentDevices ();
369348};
370349
371350const fetchStats = async () => {
@@ -389,8 +368,10 @@ const fetchPendingDevices = async () => {
389368const fetchRecentDevices = async () => {
390369 try {
391370 await devicesStore .fetchDeviceList ({ status: " accepted" });
392- recentDevicesList .value = [... devicesStore .devices ]
393- .sort ((a , b ) => new Date (b .last_seen ).getTime () - new Date (a .last_seen ).getTime ());
371+ recentDevicesList .value = [... devicesStore .devices ].sort (
372+ (a , b ) =>
373+ new Date (b .last_seen ).getTime () - new Date (a .last_seen ).getTime (),
374+ );
394375 } catch (error : unknown ) {
395376 handleError (error );
396377 }
@@ -406,8 +387,7 @@ defineExpose({
406387 toggleDrawer ,
407388 formatTimeAgo ,
408389 isDrawerOpen ,
409- handleAccept ,
410- handleReject ,
390+ handleUpdate ,
411391 activeTab ,
412392 pendingDevicesList ,
413393 recentDevicesList ,
0 commit comments