@@ -32,7 +32,7 @@ import { timeZones } from "utils/timeZones";
32
32
import Tooltip from "@mui/material/Tooltip" ;
33
33
import { formatDuration , intervalToDuration } from "date-fns" ;
34
34
import { DisabledBadge } from "components/Badges/Badges" ;
35
- import { TemplateAutostartRequirement } from "api/typesGenerated" ;
35
+ import { Template } from "api/typesGenerated" ;
36
36
37
37
// REMARK: some plugins depend on utc, so it's listed first. Otherwise they're
38
38
// sorted alphabetically.
@@ -71,12 +71,10 @@ export const Language = {
71
71
} ;
72
72
73
73
export interface WorkspaceScheduleFormProps {
74
- submitScheduleError ?: unknown ;
74
+ template : Template ;
75
+ error ?: unknown ;
75
76
initialValues : WorkspaceScheduleFormValues ;
76
77
isLoading : boolean ;
77
- allowedTemplateAutoStartDays : TemplateAutostartRequirement [ "days_of_week" ] ;
78
- allowTemplateAutoStop : boolean ;
79
- allowTemplateAutoStart : boolean ;
80
78
onCancel : ( ) => void ;
81
79
onSubmit : ( values : WorkspaceScheduleFormValues ) => void ;
82
80
// for storybook
@@ -95,7 +93,6 @@ export interface WorkspaceScheduleFormValues {
95
93
saturday : boolean ;
96
94
startTime : string ;
97
95
timezone : string ;
98
-
99
96
autostopEnabled : boolean ;
100
97
ttl : number ;
101
98
}
@@ -184,16 +181,14 @@ export const validationSchema = Yup.object({
184
181
} ) ;
185
182
186
183
export const WorkspaceScheduleForm : FC < WorkspaceScheduleFormProps > = ( {
187
- submitScheduleError ,
184
+ error ,
188
185
initialValues,
189
186
isLoading,
190
187
onCancel,
191
188
onSubmit,
192
189
initialTouched,
193
190
defaultTTL,
194
- allowedTemplateAutoStartDays,
195
- allowTemplateAutoStop,
196
- allowTemplateAutoStart,
191
+ template,
197
192
} ) => {
198
193
const form = useFormik < WorkspaceScheduleFormValues > ( {
199
194
initialValues,
@@ -202,10 +197,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
202
197
initialTouched,
203
198
enableReinitialize : true ,
204
199
} ) ;
205
- const formHelpers = getFormHelpers < WorkspaceScheduleFormValues > (
206
- form ,
207
- submitScheduleError ,
208
- ) ;
200
+ const formHelpers = getFormHelpers < WorkspaceScheduleFormValues > ( form , error ) ;
209
201
210
202
const checkboxes : Array < { value : boolean ; name : string ; label : string } > = [
211
203
{
@@ -289,7 +281,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
289
281
Select the time and days of week on which you want the workspace
290
282
starting automatically.
291
283
</ div >
292
- { ! allowTemplateAutoStart && (
284
+ { ! template . allow_user_autostart && (
293
285
< Tooltip title = "This option can be enabled in the template settings" >
294
286
< DisabledBadge />
295
287
</ Tooltip >
@@ -301,7 +293,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
301
293
< FormControlLabel
302
294
control = {
303
295
< Switch
304
- disabled = { ! allowTemplateAutoStart }
296
+ disabled = { ! template . allow_user_autostart }
305
297
name = "autostartEnabled"
306
298
checked = { form . values . autostartEnabled }
307
299
onChange = { handleToggleAutostart }
@@ -316,7 +308,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
316
308
// or if primary feature is toggled off via the switch above
317
309
disabled = {
318
310
isLoading ||
319
- ! allowTemplateAutoStart ||
311
+ ! template . allow_user_autostart ||
320
312
! form . values . autostartEnabled
321
313
}
322
314
label = { Language . startTimeLabel }
@@ -329,7 +321,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
329
321
// or if primary feature is toggled off via the switch above
330
322
disabled = {
331
323
isLoading ||
332
- ! allowTemplateAutoStart ||
324
+ ! template . allow_user_autostart ||
333
325
! form . values . autostartEnabled
334
326
}
335
327
label = { Language . timezoneLabel }
@@ -367,8 +359,10 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
367
359
// also disabled if primary feature switch (above) is toggled off
368
360
disabled = {
369
361
isLoading ||
370
- ! allowTemplateAutoStart ||
371
- ! allowedTemplateAutoStartDays . includes ( checkbox . name ) ||
362
+ ! template . allow_user_autostart ||
363
+ ! template . autostart_requirement . days_of_week . includes (
364
+ checkbox . name ,
365
+ ) ||
372
366
! form . values . autostartEnabled
373
367
}
374
368
onChange = { form . handleChange }
@@ -396,10 +390,13 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
396
390
< div css = { { marginBottom : 16 } } >
397
391
Set how many hours should elapse after the workspace started
398
392
before the workspace automatically shuts down. This will be
399
- extended by 1 hour after last activity in the workspace was
400
- detected.
393
+ extended by{ " " }
394
+ { dayjs
395
+ . duration ( { milliseconds : template . activity_bump_ms } )
396
+ . humanize ( ) } { " " }
397
+ after last activity in the workspace was detected.
401
398
</ div >
402
- { ! allowTemplateAutoStop && (
399
+ { ! template . allow_user_autostop && (
403
400
< Tooltip title = "This option can be enabled in the template settings" >
404
401
< DisabledBadge />
405
402
</ Tooltip >
@@ -414,7 +411,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
414
411
name = "autostopEnabled"
415
412
checked = { form . values . autostopEnabled }
416
413
onChange = { handleToggleAutostop }
417
- disabled = { ! allowTemplateAutoStop }
414
+ disabled = { ! template . allow_user_autostop }
418
415
/>
419
416
}
420
417
label = { Language . stopSwitch }
@@ -428,7 +425,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
428
425
// if autostop feature is toggled off via the switch above
429
426
disabled = {
430
427
isLoading ||
431
- ! allowTemplateAutoStop ||
428
+ ! template . allow_user_autostop ||
432
429
! form . values . autostopEnabled
433
430
}
434
431
inputProps = { { min : 0 , step : "any" } }
@@ -443,7 +440,9 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
443
440
isLoading = { isLoading }
444
441
// If both options, autostart and autostop, are disabled at the template
445
442
// level, the form is disabled.
446
- submitDisabled = { ! allowTemplateAutoStart && ! allowTemplateAutoStop }
443
+ submitDisabled = {
444
+ ! template . allow_user_autostart && ! template . allow_user_autostop
445
+ }
447
446
/>
448
447
</ HorizontalForm >
449
448
) ;
0 commit comments