@@ -17,12 +17,12 @@ import { Alert } from "components/Alert/Alert";
17
17
import { timeToCron , quietHoursDisplay } from "utils/schedule" ;
18
18
19
19
export interface ScheduleFormValues {
20
- startTime : string ;
20
+ time : string ;
21
21
timezone : string ;
22
22
}
23
23
24
24
const validationSchema = Yup . object ( {
25
- startTime : Yup . string ( )
25
+ time : Yup . string ( )
26
26
. ensure ( )
27
27
. test ( "is-time-string" , "Time must be in HH:mm format." , ( value ) => {
28
28
if ( value === "" ) {
@@ -64,17 +64,11 @@ export const ScheduleForm: FC<React.PropsWithChildren<ScheduleFormProps>> = ({
64
64
} ;
65
65
} , [ ] ) ;
66
66
67
- const preferredTimezone = getPreferredTimezone ( ) ;
68
-
69
67
// If the user has a custom schedule, use that as the initial values.
70
- // Otherwise, use midnight in their preferred timezone.
71
- const formInitialValues = {
72
- startTime : "00:00" ,
73
- timezone : preferredTimezone ,
74
- } ;
75
- if ( initialValues . user_set ) {
76
- formInitialValues . startTime = initialValues . time ;
77
- formInitialValues . timezone = initialValues . timezone ;
68
+ // Otherwise, use the default time, with their local timezone.
69
+ const formInitialValues = { ...initialValues } ;
70
+ if ( ! initialValues . user_set ) {
71
+ formInitialValues . timezone = getPreferredTimezone ( ) ;
78
72
}
79
73
80
74
const form : FormikContextType < ScheduleFormValues > =
@@ -83,7 +77,7 @@ export const ScheduleForm: FC<React.PropsWithChildren<ScheduleFormProps>> = ({
83
77
validationSchema,
84
78
onSubmit : async ( values ) => {
85
79
onSubmit ( {
86
- schedule : timeToCron ( values . startTime , values . timezone ) ,
80
+ schedule : timeToCron ( values . time , values . timezone ) ,
87
81
} ) ;
88
82
} ,
89
83
} ) ;
@@ -107,7 +101,7 @@ export const ScheduleForm: FC<React.PropsWithChildren<ScheduleFormProps>> = ({
107
101
108
102
< Stack direction = "row" >
109
103
< TextField
110
- { ...getFieldHelpers ( "startTime " ) }
104
+ { ...getFieldHelpers ( "time " ) }
111
105
disabled = { isLoading }
112
106
label = "Start time"
113
107
type = "time"
@@ -132,18 +126,14 @@ export const ScheduleForm: FC<React.PropsWithChildren<ScheduleFormProps>> = ({
132
126
disabled
133
127
fullWidth
134
128
label = "Cron schedule"
135
- value = { timeToCron ( form . values . startTime , form . values . timezone ) }
129
+ value = { timeToCron ( form . values . time , form . values . timezone ) }
136
130
/>
137
131
138
132
< TextField
139
133
disabled
140
134
fullWidth
141
135
label = "Next occurrence"
142
- value = { quietHoursDisplay (
143
- form . values . startTime ,
144
- form . values . timezone ,
145
- now ,
146
- ) }
136
+ value = { quietHoursDisplay ( form . values . time , form . values . timezone , now ) }
147
137
/>
148
138
149
139
< div >
0 commit comments