@@ -21,7 +21,6 @@ import { AutoStart } from "pages/WorkspaceSchedulePage/schedule"
21
21
import { AutoStop } from "pages/WorkspaceSchedulePage/ttl"
22
22
import { FC } from "react"
23
23
import * as Yup from "yup"
24
- import { OptionalObjectSchema } from "yup/lib/object"
25
24
import { getFormHelpersWithError } from "../../util/formUtils"
26
25
import { FormFooter } from "../FormFooter/FormFooter"
27
26
import { FullPageForm } from "../FullPageForm/FullPageForm"
@@ -92,83 +91,84 @@ export interface WorkspaceScheduleFormValues {
92
91
}
93
92
94
93
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
95
- export const getValidationSchema = ( autoStartEnabled :boolean , autoStopEnabled :boolean ) => ( Yup . object ( {
96
- sunday :Yup . boolean ( ) ,
97
- monday :Yup . boolean ( ) . test ( "at-least-one-day" , Language . errorNoDayOfWeek , function ( value ) {
98
- const parent = this . parent as WorkspaceScheduleFormValues
99
-
100
- if ( ! autoStartEnabled ) {
101
- return true
102
- } else {
103
- return ! [
104
- parent . sunday ,
105
- value ,
106
- parent . tuesday ,
107
- parent . wednesday ,
108
- parent . thursday ,
109
- parent . friday ,
110
- parent . saturday ,
111
- ] . every ( ( day ) => day === false )
112
- }
113
- } ) ,
114
- tuesday :Yup . boolean ( ) ,
115
- wednesday :Yup . boolean ( ) ,
116
- thursday :Yup . boolean ( ) ,
117
- friday :Yup . boolean ( ) ,
118
- saturday :Yup . boolean ( ) ,
94
+ export const getValidationSchema = ( autoStartEnabled :boolean , autoStopEnabled :boolean ) =>
95
+ Yup . object ( {
96
+ sunday :Yup . boolean ( ) ,
97
+ monday :Yup . boolean ( ) . test ( "at-least-one-day" , Language . errorNoDayOfWeek , function ( value ) {
98
+ const parent = this . parent as WorkspaceScheduleFormValues
119
99
120
- startTime :Yup . string ( )
121
- . ensure ( )
122
- . test ( "required-if-auto-start" , Language . errorNoTime , function ( value ) {
123
- if ( autoStartEnabled ) {
124
- return value !== ""
125
- } else {
100
+ if ( ! autoStartEnabled ) {
126
101
return true
127
- }
128
- } )
129
- . test ( "is-time-string" , Language . errorTime , ( value ) => {
130
- if ( value === "" ) {
131
- return true
132
- } else if ( ! / ^ [ 0 - 9 ] [ 0 - 9 ] : [ 0 - 9 ] [ 0 - 9 ] $ / . test ( value ) ) {
133
- return false
134
102
} else {
135
- const parts = value . split ( ":" )
136
- const HH = Number ( parts [ 0 ] )
137
- const mm = Number ( parts [ 1 ] )
138
- return HH >= 0 && HH <= 23 && mm >= 0 && mm <= 59
103
+ return ! [
104
+ parent . sunday ,
105
+ value ,
106
+ parent . tuesday ,
107
+ parent . wednesday ,
108
+ parent . thursday ,
109
+ parent . friday ,
110
+ parent . saturday ,
111
+ ] . every ( ( day ) => day === false )
139
112
}
140
113
} ) ,
141
- timezone :Yup . string ( )
142
- . ensure ( )
143
- . test ( "is-timezone" , Language . errorTimezone , function ( value ) {
144
- const parent = this . parent as WorkspaceScheduleFormValues
114
+ tuesday :Yup . boolean ( ) ,
115
+ wednesday :Yup . boolean ( ) ,
116
+ thursday :Yup . boolean ( ) ,
117
+ friday :Yup . boolean ( ) ,
118
+ saturday :Yup . boolean ( ) ,
145
119
146
- if ( ! parent . startTime ) {
147
- return true
148
- } else {
149
- // Unfortunately, there's not a good API on dayjs at this time for
150
- // evaluating a timezone. Attempt to parse today in the supplied timezone
151
- // and return as valid if the function doesn't throw.
152
- try {
153
- dayjs . tz ( dayjs ( ) , value )
120
+ startTime :Yup . string ( )
121
+ . ensure ( )
122
+ . test ( "required-if-auto-start" , Language . errorNoTime , function ( value ) {
123
+ if ( autoStartEnabled ) {
124
+ return value !== ""
125
+ } else {
154
126
return true
155
- } catch ( e ) {
127
+ }
128
+ } )
129
+ . test ( "is-time-string" , Language . errorTime , ( value ) => {
130
+ if ( value === "" ) {
131
+ return true
132
+ } else if ( ! / ^ [ 0 - 9 ] [ 0 - 9 ] : [ 0 - 9 ] [ 0 - 9 ] $ / . test ( value ) ) {
156
133
return false
134
+ } else {
135
+ const parts = value . split ( ":" )
136
+ const HH = Number ( parts [ 0 ] )
137
+ const mm = Number ( parts [ 1 ] )
138
+ return HH >= 0 && HH <= 23 && mm >= 0 && mm <= 59
157
139
}
158
- }
159
- } ) ,
160
- ttl :Yup . number ( )
161
- . integer ( )
162
- . min ( 0 )
163
- . max ( 24 * 7 /* 7 days */ )
164
- . test ( "positive-if-auto-stop" , Language . errorNoStop , ( value ) => {
165
- if ( autoStopEnabled ) {
166
- return ! ! value
167
- } else {
168
- return true
169
- }
170
- } ) ,
171
- } ) )
140
+ } ) ,
141
+ timezone :Yup . string ( )
142
+ . ensure ( )
143
+ . test ( "is-timezone" , Language . errorTimezone , function ( value ) {
144
+ const parent = this . parent as WorkspaceScheduleFormValues
145
+
146
+ if ( ! parent . startTime ) {
147
+ return true
148
+ } else {
149
+ // Unfortunately, there's not a good API on dayjs at this time for
150
+ // evaluating a timezone. Attempt to parse today in the supplied timezone
151
+ // and return as valid if the function doesn't throw.
152
+ try {
153
+ dayjs . tz ( dayjs ( ) , value )
154
+ return true
155
+ } catch ( e ) {
156
+ return false
157
+ }
158
+ }
159
+ } ) ,
160
+ ttl :Yup . number ( )
161
+ . integer ( )
162
+ . min ( 0 )
163
+ . max ( 24 * 7 /* 7 days */ )
164
+ . test ( "positive-if-auto-stop" , Language . errorNoStop , ( value ) => {
165
+ if ( autoStopEnabled ) {
166
+ return ! ! value
167
+ } else {
168
+ return true
169
+ }
170
+ } ) ,
171
+ } )
172
172
173
173
export const WorkspaceScheduleForm :FC < WorkspaceScheduleFormProps > = ( {
174
174
submitScheduleError,