1
- import { FunctionComponent , useMemo , useState } from "react" ;
2
- import Container from "../../../../components/Container" ;
1
+ import { LoadingButton } from "@mui/lab" ;
3
2
import {
4
- alpha ,
5
3
Button ,
6
4
Card ,
7
5
CardContent ,
@@ -12,27 +10,32 @@ import {
12
10
ToggleButton ,
13
11
ToggleButtonGroup ,
14
12
Typography ,
13
+ alpha ,
15
14
useTheme ,
16
15
} from "@mui/material" ;
16
+ import { enqueueSnackbar } from "notistack" ;
17
+ import { FunctionComponent , useMemo , useState } from "react" ;
18
+ import { Helmet } from "react-helmet" ;
17
19
import { IoPause , IoPlay , IoSettings } from "react-icons/io5" ;
18
- import ResponseTimeGraph from "./components/ResponseTimesGraph" ;
19
- import { Link , NavLink , useNavigate , useParams } from "react-router-dom" ;
20
- import { ChecksDataGrid } from "./components/ChecksDataGrid" ;
21
- import { useMonitor , useUpdateMonitor } from "../../../../hooks/monitors.query" ;
20
+ import { Link , NavLink , useParams } from "react-router-dom" ;
21
+ import Conditional from "../../../../components/Conditional" ;
22
+ import Container from "../../../../components/Container" ;
23
+ import PulseDot from "../../../../components/PulseDot" ;
24
+ import { Role } from "../../../../components/Restrict" ;
22
25
import useAuthenticationStore from "../../../../hooks/authentication.store" ;
26
+ import {
27
+ useMonitor ,
28
+ useUpdateMonitorState ,
29
+ } from "../../../../hooks/monitors.query" ;
23
30
import { useCurrentUserRole } from "../../../../hooks/user.query" ;
24
- import { Role } from "../../../../components/Restrict" ;
25
- import { enqueueSnackbar } from "notistack" ;
26
- import { LoadingButton } from "@mui/lab" ;
27
- import { stripProtocolAndPath } from "../../../../utilities/url" ;
28
- import PulseDot from "../../../../components/PulseDot" ;
29
- import TLSCard from "./components/TLSCard" ;
30
- import LastCheckCard from "./components/LastCheckCard" ;
31
- import Conditional from "../../../../components/Conditional" ;
32
31
import { secondsHumanize } from "../../../../utilities/time" ;
32
+ import { stripProtocolAndPath } from "../../../../utilities/url" ;
33
33
import AverageResponseTimeCard from "./components/AverageResponseTimeCard" ;
34
+ import { ChecksDataGrid } from "./components/ChecksDataGrid" ;
35
+ import LastCheckCard from "./components/LastCheckCard" ;
36
+ import ResponseTimeGraph from "./components/ResponseTimesGraph" ;
37
+ import TLSCard from "./components/TLSCard" ;
34
38
import UptimeCard from "./components/UptimeCard" ;
35
- import { Helmet } from "react-helmet" ;
36
39
37
40
const MonitorDetailView : FunctionComponent = ( ) => {
38
41
let params = useParams ( ) ;
@@ -46,20 +49,18 @@ const MonitorDetailView: FunctionComponent = () => {
46
49
const currentRole = useCurrentUserRole ( ) ;
47
50
48
51
const { data, error, isLoading } = useMonitor ( monitorId ) ;
49
- const { mutate : update , isLoading : isUpdating } = useUpdateMonitor ( monitorId ) ;
52
+ const { mutate : updateState , isLoading : isUpdatingState } =
53
+ useUpdateMonitorState ( monitorId ) ;
50
54
51
55
const isActive = useMemo ( ( ) => data ?. state === "ACTIVE" , [ data ?. state ] ) ;
52
56
53
57
const setMonitorState = ( state : "ACTIVE" | "INACTIVE" ) => {
54
- if ( ! data || isUpdating ) {
58
+ if ( isLoading ) {
55
59
return ;
56
60
}
57
61
58
62
try {
59
- update ( {
60
- ...data ,
61
- state : state ,
62
- } ) ;
63
+ updateState ( state ) ;
63
64
} catch ( e ) {
64
65
enqueueSnackbar ( "Failed to update monitor state" , { variant : "error" } ) ;
65
66
}
@@ -84,7 +85,7 @@ const MonitorDetailView: FunctionComponent = () => {
84
85
isActive ? t . palette . info . main : t . palette . success . main ,
85
86
} ,
86
87
} }
87
- loading = { isUpdating }
88
+ loading = { isUpdatingState }
88
89
onClick = { ( ) => setMonitorState ( isActive ? "INACTIVE" : "ACTIVE" ) }
89
90
>
90
91
{ isActive ? "Pause monitor" : "Resume monitor" }
@@ -100,10 +101,10 @@ const MonitorDetailView: FunctionComponent = () => {
100
101
component = { NavLink }
101
102
to = { `/monitors/${ params . id } /settings` }
102
103
>
103
- Edit
104
+ Settings
104
105
</ Button > ,
105
106
] ;
106
- } , [ currentRole , data , params , isUpdating ] ) ;
107
+ } , [ currentRole , data , params , isUpdatingState ] ) ;
107
108
108
109
return (
109
110
< >
0 commit comments