@@ -2,13 +2,14 @@ import TextField from "@mui/material/TextField"
2
2
import { FormikContextType , useFormik } from "formik"
3
3
import { FC , useEffect , useState } from "react"
4
4
import * as Yup from "yup"
5
- import {
6
- getFormHelpers ,
7
- } from "utils/formUtils"
5
+ import { getFormHelpers } from "utils/formUtils"
8
6
import { LoadingButton } from "components/LoadingButton/LoadingButton"
9
7
import { ErrorAlert } from "components/Alert/ErrorAlert"
10
8
import { Form , FormFields } from "components/Form/Form"
11
- import { UpdateUserQuietHoursScheduleRequest , UserQuietHoursScheduleResponse } from "api/typesGenerated"
9
+ import {
10
+ UpdateUserQuietHoursScheduleRequest ,
11
+ UserQuietHoursScheduleResponse ,
12
+ } from "api/typesGenerated"
12
13
import cronParser from "cron-parser"
13
14
import MenuItem from "@mui/material/MenuItem"
14
15
import Stack from "@mui/material/Stack"
@@ -50,13 +51,13 @@ export const ScheduleForm: FC<React.PropsWithChildren<ScheduleFormProps>> = ({
50
51
now,
51
52
} ) => {
52
53
// Force a re-render every 15 seconds to update the "Next occurrence" field.
53
- const [ _ , setTime ] = useState < number > ( Date . now ( ) ) ;
54
+ const [ _ , setTime ] = useState < number > ( Date . now ( ) )
54
55
useEffect ( ( ) => {
55
- const interval = setInterval ( ( ) => setTime ( Date . now ( ) ) , 15000 ) ;
56
+ const interval = setInterval ( ( ) => setTime ( Date . now ( ) ) , 15000 )
56
57
return ( ) => {
57
- clearInterval ( interval ) ;
58
- } ;
59
- } , [ ] ) ;
58
+ clearInterval ( interval )
59
+ }
60
+ } , [ ] )
60
61
61
62
const formInitialValues = {
62
63
hours : 0 ,
@@ -79,32 +80,27 @@ export const ScheduleForm: FC<React.PropsWithChildren<ScheduleFormProps>> = ({
79
80
} )
80
81
} ,
81
82
} )
82
- const getFieldHelpers = getFormHelpers < ScheduleFormValues > (
83
- form ,
84
- updateErr ,
85
- )
83
+ const getFieldHelpers = getFormHelpers < ScheduleFormValues > ( form , updateErr )
86
84
87
85
return (
88
86
< >
89
87
< Form onSubmit = { form . handleSubmit } >
90
88
< FormFields >
91
- { Boolean ( updateErr ) && (
92
- < ErrorAlert error = { updateErr } />
93
- ) }
89
+ { Boolean ( updateErr ) && < ErrorAlert error = { updateErr } /> }
94
90
95
91
< p >
96
92
Workspaces will only be turned off for updates (due to settings{ " " }
97
93
configured by template admins) when your configured quiet hours{ " " }
98
- start. Workspaces may still be automatically stopped at any{ " " }
99
- other time due to inactivity.
94
+ start. Workspaces may still be automatically stopped at any other
95
+ time due to inactivity.
100
96
</ p >
101
97
102
98
{ ! initialValues . user_set && (
103
99
< p >
104
- You are currently using the default quiet hours schedule,{ " " }
105
- which is every day at < code > { initialValues . time } </ code > in{ " " }
106
- < code > { initialValues . timezone } </ code > . You can set a custom{ " " }
107
- quiet hours schedule below.
100
+ You are currently using the default quiet hours schedule, which is
101
+ every day at < code > { initialValues . time } </ code > in{ " " }
102
+ < code > { initialValues . timezone } </ code > . You can set a custom quiet
103
+ hours schedule below.
108
104
</ p >
109
105
) }
110
106
@@ -148,14 +144,23 @@ export const ScheduleForm: FC<React.PropsWithChildren<ScheduleFormProps>> = ({
148
144
disabled
149
145
fullWidth
150
146
label = "Cron schedule"
151
- value = { timeToCron ( form . values . hours , form . values . minutes , form . values . timezone ) }
147
+ value = { timeToCron (
148
+ form . values . hours ,
149
+ form . values . minutes ,
150
+ form . values . timezone ,
151
+ ) }
152
152
/>
153
153
154
154
< TextField
155
155
disabled
156
156
fullWidth
157
157
label = "Next occurrence"
158
- value = { formatNextRun ( form . values . hours , form . values . minutes , form . values . timezone , now ) }
158
+ value = { formatNextRun (
159
+ form . values . hours ,
160
+ form . values . minutes ,
161
+ form . values . timezone ,
162
+ now ,
163
+ ) }
159
164
/>
160
165
161
166
< div >
@@ -551,7 +556,12 @@ const timeToCron = (hours: number, minutes: number, tz: string) => {
551
556
}
552
557
553
558
// evaluateNextRun returns a Date object of the next cron run time.
554
- const evaluateNextRun = ( hours : number , minutes : number , tz : string , now : Date | undefined ) : Date => {
559
+ const evaluateNextRun = (
560
+ hours : number ,
561
+ minutes : number ,
562
+ tz : string ,
563
+ now : Date | undefined ,
564
+ ) : Date => {
555
565
// The cron-parser package doesn't accept a timezone in the cron string, but
556
566
// accepts it as an option.
557
567
const cron = timeToCron ( hours , minutes , "" )
@@ -565,7 +575,12 @@ const evaluateNextRun = (hours: number, minutes: number, tz: string, now: Date |
565
575
return parsed . next ( ) . toDate ( )
566
576
}
567
577
568
- const formatNextRun = ( hours : number , minutes : number , tz : string , now : Date | undefined ) : string => {
578
+ const formatNextRun = (
579
+ hours : number ,
580
+ minutes : number ,
581
+ tz : string ,
582
+ now : Date | undefined ,
583
+ ) : string => {
569
584
const nowDjs = dayjs ( now ) . tz ( tz )
570
585
const djs = dayjs ( evaluateNextRun ( hours , minutes , tz , now ) ) . tz ( tz )
571
586
let str = djs . format ( "h:mm A" )
0 commit comments