11import { socketUrl } from "@/shared/api/baseApi" ;
2- import { useEffect , useMemo } from "react" ;
2+ import { useEffect } from "react" ;
33import useWebSocket from "react-use-websocket" ;
44import { useShallow } from "zustand/react/shallow" ;
55import { useServiceTableStore } from "@/pages/service/store/useServiceTableStore" ;
@@ -18,7 +18,7 @@ export const useDashboardLogic = () => {
1818 setUpdateService : s . setUpdateService ,
1919 setUpdateAllServices : s . setUpdateAllServices ,
2020 addServiceInData : s . addServiceInData ,
21- } ) ) ,
21+ } ) )
2222 ) ;
2323
2424 const { getDashboardStats } = getDashboard ( ) ;
@@ -27,13 +27,23 @@ export const useDashboardLogic = () => {
2727 useShallow ( ( s ) => ( {
2828 dashboardInfo : s . dashboardInfo ,
2929 setDashboardInfo : s . setDashboardInfo ,
30- } ) ) ,
30+ } ) )
3131 ) ;
3232
3333 const onRefreshDashboard = async ( ) => {
3434 await getDashboardStats ( ) ;
3535 } ;
3636
37+ useEffect ( ( ) => {
38+ getDashboardStats ( ) . then ( ( res ) => {
39+ setDashboardInfo ( res ) ;
40+ } ) ;
41+
42+ return ( ) => {
43+ setDashboardInfo ( null ) ;
44+ } ;
45+ } , [ ] ) ;
46+
3747 const { lastMessage } = useWebSocket ( socketUrl , {
3848 shouldReconnect : ( ) => true ,
3949 } ) ;
@@ -60,23 +70,8 @@ export const useDashboardLogic = () => {
6070 }
6171 } , [ lastMessage ] ) ;
6272
63- const infoKeysDashboard = useMemo (
64- ( ) => [
65- { key : "total_services" , label : "Total services" } ,
66- { key : "services_up" , label : "Services up" } ,
67- { key : "services_down" , label : "Services down" } ,
68- { key : "active_incidents" , label : "Active incidents" } ,
69- { key : "avg_response_time" , label : "Average response time (ms)" } ,
70- { key : "total_checks" , label : "Total checks" } ,
71- { key : "uptime_percentage" , label : "Uptime" } ,
72- { key : "checks_per_minute" , label : "Checks per minute" } ,
73- ] ,
74- [ ] ,
75- ) ;
76-
7773 return {
7874 dashboardInfo,
79- infoKeysDashboard,
8075 onRefreshDashboard,
8176 } ;
8277} ;
0 commit comments