@@ -12,7 +12,7 @@ export const Language = {
12
12
descriptionLabel : "Description" ,
13
13
maxTtlLabel : "Max TTL" ,
14
14
// This is the same from the CLI on https://github.com/coder/coder/blob/546157b63ef9204658acf58cb653aa9936b70c49/cli/templateedit.go#L59
15
- maxTtlHelperText : "Edit the template maximum time before shutdown in milliseconds " ,
15
+ maxTtlHelperText : "Edit the template maximum time before shutdown in seconds " ,
16
16
formAriaLabel : "Template settings form" ,
17
17
}
18
18
@@ -21,6 +21,11 @@ export const validationSchema = Yup.object({
21
21
description : Yup . string ( ) ,
22
22
max_ttl_ms : Yup . number ( ) ,
23
23
} )
24
+ export interface UpdateTemplateFormMeta {
25
+ readonly name ?: string
26
+ readonly description ?: string
27
+ readonly max_ttl ?: number
28
+ }
24
29
25
30
export interface TemplateSettingsForm {
26
31
template : Template
@@ -29,7 +34,7 @@ export interface TemplateSettingsForm {
29
34
isSubmitting : boolean
30
35
error ?: unknown
31
36
// Helpful to show field errors on Storybook
32
- initialTouched ?: FormikTouched < UpdateTemplateMeta >
37
+ initialTouched ?: FormikTouched < UpdateTemplateFormMeta >
33
38
}
34
39
35
40
export const TemplateSettingsForm : FC < TemplateSettingsForm > = ( {
@@ -40,19 +45,22 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
40
45
isSubmitting,
41
46
initialTouched,
42
47
} ) => {
43
- const form : FormikContextType < UpdateTemplateMeta > = useFormik < UpdateTemplateMeta > ( {
48
+ const form : FormikContextType < UpdateTemplateFormMeta > = useFormik < UpdateTemplateFormMeta > ( {
44
49
initialValues : {
45
50
name : template . name ,
46
51
description : template . description ,
47
- max_ttl_ms : template . max_ttl_ms ,
52
+ max_ttl : template . max_ttl_ms / 1000 ,
48
53
} ,
49
54
validationSchema,
50
55
onSubmit : ( data ) => {
51
- onSubmit ( data )
56
+ onSubmit ( {
57
+ ...data ,
58
+ max_ttl_ms : data . max_ttl !== undefined ? data . max_ttl * 1000 : undefined ,
59
+ } )
52
60
} ,
53
61
initialTouched,
54
62
} )
55
- const getFieldHelpers = getFormHelpersWithError < UpdateTemplateMeta > ( form , error )
63
+ const getFieldHelpers = getFormHelpersWithError < UpdateTemplateFormMeta > ( form , error )
56
64
57
65
return (
58
66
< form onSubmit = { form . handleSubmit } aria-label = { Language . formAriaLabel } >
@@ -78,7 +86,7 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
78
86
/>
79
87
80
88
< TextField
81
- { ...getFieldHelpers ( "max_ttl_ms " ) }
89
+ { ...getFieldHelpers ( "max_ttl " ) }
82
90
helperText = { Language . maxTtlHelperText }
83
91
disabled = { isSubmitting }
84
92
fullWidth
0 commit comments