1
- import { useTheme } from "@emotion/react" ;
2
- import { Box , Stack , Typography , Button } from "@mui/material" ;
1
+ // Components
2
+ import { Box , Stack , Typography , Button , Switch } from "@mui/material" ;
3
3
import TextInput from "../../Components/Inputs/TextInput" ;
4
4
import Link from "../../Components/Link" ;
5
5
import Select from "../../Components/Inputs/Select" ;
6
+ import LoadingButton from "@mui/lab/LoadingButton" ;
7
+ import { useIsAdmin } from "../../Hooks/useIsAdmin" ;
8
+ import Dialog from "../../Components/Dialog" ;
9
+ import ConfigBox from "../../Components/ConfigBox" ;
10
+
11
+ //Utils
12
+ import { useTheme } from "@emotion/react" ;
6
13
import { logger } from "../../Utils/Logger" ;
7
- import "./index.css" ;
8
14
import { useDispatch , useSelector } from "react-redux" ;
9
15
import { createToast } from "../../Utils/toastUtils" ;
10
16
import {
@@ -14,15 +20,17 @@ import {
14
20
} from "../../Features/UptimeMonitors/uptimeMonitorsSlice" ;
15
21
import { update } from "../../Features/Auth/authSlice" ;
16
22
import PropTypes from "prop-types" ;
17
- import LoadingButton from "@mui/lab/LoadingButton" ;
18
- import { setTimezone , setMode } from "../../Features/UI/uiSlice" ;
23
+ import {
24
+ setTimezone ,
25
+ setMode ,
26
+ setDistributedUptimeEnabled ,
27
+ } from "../../Features/UI/uiSlice" ;
19
28
import timezones from "../../Utils/timezones.json" ;
20
29
import { useState , useEffect } from "react" ;
21
30
import { networkService } from "../../main" ;
22
31
import { settingsValidation } from "../../Validation/validation" ;
23
- import Dialog from "../../Components/Dialog" ;
24
- import { useIsAdmin } from "../../Hooks/useIsAdmin" ;
25
- import ConfigBox from "../../Components/ConfigBox" ;
32
+
33
+ // Constants
26
34
const SECONDS_PER_DAY = 86400 ;
27
35
28
36
const Settings = ( ) => {
@@ -32,10 +40,11 @@ const Settings = () => {
32
40
const { checkTTL } = user ;
33
41
const { isLoading } = useSelector ( ( state ) => state . uptimeMonitors ) ;
34
42
const { isLoading : authIsLoading } = useSelector ( ( state ) => state . auth ) ;
35
- const { timezone } = useSelector ( ( state ) => state . ui ) ;
43
+ const { timezone, distributedUptimeEnabled } = useSelector ( ( state ) => state . ui ) ;
36
44
const { mode } = useSelector ( ( state ) => state . ui ) ;
37
45
const [ checksIsLoading , setChecksIsLoading ] = useState ( false ) ;
38
46
const [ form , setForm ] = useState ( {
47
+ enableDistributedUptime : distributedUptimeEnabled ,
39
48
ttl : checkTTL ? ( checkTTL / SECONDS_PER_DAY ) . toString ( ) : 0 ,
40
49
} ) ;
41
50
const [ version , setVersion ] = useState ( "unknown" ) ;
@@ -64,7 +73,16 @@ const Settings = () => {
64
73
} , [ ] ) ;
65
74
66
75
const handleChange = ( event ) => {
67
- const { value, id } = event . target ;
76
+ const { type, checked, value, id } = event . target ;
77
+
78
+ if ( type === "checkbox" ) {
79
+ setForm ( ( prev ) => ( {
80
+ ...prev ,
81
+ [ id ] : checked ,
82
+ } ) ) ;
83
+ return ;
84
+ }
85
+
68
86
const { error } = settingsValidation . validate (
69
87
{ [ id ] : value } ,
70
88
{
@@ -79,7 +97,6 @@ const Settings = () => {
79
97
newErrors [ err . path [ 0 ] ] = err . message ;
80
98
} ) ;
81
99
setErrors ( newErrors ) ;
82
- console . log ( newErrors ) ;
83
100
logger . error ( "Validation errors:" , error . details ) ;
84
101
}
85
102
let inputValue = value ;
@@ -100,6 +117,7 @@ const Settings = () => {
100
117
} ) ;
101
118
const updatedUser = { ...user , checkTTL : form . ttl } ;
102
119
const action = await dispatch ( update ( { authToken, localData : updatedUser } ) ) ;
120
+
103
121
if ( action . payload . success ) {
104
122
createToast ( {
105
123
body : "Settings saved successfully" ,
@@ -197,7 +215,7 @@ const Settings = () => {
197
215
</ Box >
198
216
< Stack gap = { theme . spacing ( 20 ) } >
199
217
< Select
200
- id = "display-timezone "
218
+ id = "display-timezones "
201
219
label = "Display timezone"
202
220
value = { timezone }
203
221
onChange = { ( e ) => {
@@ -229,6 +247,27 @@ const Settings = () => {
229
247
> </ Select >
230
248
</ Stack >
231
249
</ ConfigBox >
250
+ { isAdmin && (
251
+ < ConfigBox >
252
+ < Box >
253
+ < Typography component = "h1" > Distributed uptime</ Typography >
254
+ < Typography sx = { { mt : theme . spacing ( 2 ) , mb : theme . spacing ( 2 ) } } >
255
+ Enable/disable distributed uptime monitoring.
256
+ </ Typography >
257
+ </ Box >
258
+ < Box >
259
+ < Switch
260
+ id = "enableDistributedUptime"
261
+ color = "accent"
262
+ checked = { distributedUptimeEnabled }
263
+ onChange = { ( e ) => {
264
+ dispatch ( setDistributedUptimeEnabled ( e . target . checked ) ) ;
265
+ } }
266
+ />
267
+ { distributedUptimeEnabled === true ? "Enabled" : "Disabled" }
268
+ </ Box >
269
+ </ ConfigBox >
270
+ ) }
232
271
{ isAdmin && (
233
272
< ConfigBox >
234
273
< Box >
0 commit comments