File tree 2 files changed +38
-2
lines changed
site/src/components/WorkspaceScheduleForm
2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,22 @@ describe("validationSchema", () => {
57
57
expect ( validate ) . toThrowError ( Language . errorNoDayOfWeek )
58
58
} )
59
59
60
+ it ( "disallows empty startTime when at least one day is set" , ( ) => {
61
+ const values : WorkspaceScheduleFormValues = {
62
+ ...valid ,
63
+ sunday : false ,
64
+ monday : true ,
65
+ tuesday : false ,
66
+ wednesday : false ,
67
+ thursday : false ,
68
+ friday : false ,
69
+ saturday : false ,
70
+ startTime : "" ,
71
+ }
72
+ const validate = ( ) => validationSchema . validateSync ( values )
73
+ expect ( validate ) . toThrowError ( Language . errorNoTime )
74
+ } )
75
+
60
76
it ( "allows startTime 16:20" , ( ) => {
61
77
const values : WorkspaceScheduleFormValues = {
62
78
...valid ,
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ dayjs.extend(timezone)
27
27
28
28
export const Language = {
29
29
errorNoDayOfWeek : "Must set at least one day of week" ,
30
+ errorNoTime : "Start time is required" ,
30
31
errorTime : "Time must be in HH:mm format (24 hours)" ,
31
32
errorTimezone : "Invalid timezone" ,
32
33
daysOfWeekLabel : "Days of Week" ,
@@ -93,6 +94,25 @@ export const validationSchema = Yup.object({
93
94
94
95
startTime : Yup . string ( )
95
96
. ensure ( )
97
+ . test ( "required-if-day-selected" , Language . errorNoTime , function ( value ) {
98
+ const parent = this . parent as WorkspaceScheduleFormValues
99
+
100
+ const isDaySelected = [
101
+ parent . sunday ,
102
+ parent . monday ,
103
+ parent . tuesday ,
104
+ parent . wednesday ,
105
+ parent . thursday ,
106
+ parent . friday ,
107
+ parent . saturday ,
108
+ ] . some ( ( day ) => day )
109
+
110
+ if ( isDaySelected ) {
111
+ return value !== ""
112
+ } else {
113
+ return true
114
+ }
115
+ } )
96
116
. test ( "is-time-string" , Language . errorTime , ( value ) => {
97
117
if ( value === "" ) {
98
118
return true
@@ -192,7 +212,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
192
212
</ Link >
193
213
</ > ,
194
214
) }
195
- disabled = { isLoading || ! form . values . startTime }
215
+ disabled = { isLoading }
196
216
InputLabelProps = { {
197
217
shrink : true ,
198
218
} }
@@ -210,7 +230,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
210
230
control = {
211
231
< Checkbox
212
232
checked = { checkbox . value }
213
- disabled = { ! form . values . startTime || isLoading }
233
+ disabled = { isLoading }
214
234
onChange = { form . handleChange }
215
235
name = { checkbox . name }
216
236
color = "primary"
You can’t perform that action at this time.
0 commit comments