@@ -12,7 +12,7 @@ export const Language = {
1212 descriptionLabel : "Description" ,
1313 maxTtlLabel : "Max TTL" ,
1414 // 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 " ,
1616 formAriaLabel : "Template settings form" ,
1717}
1818
@@ -21,6 +21,11 @@ export const validationSchema = Yup.object({
2121 description : Yup . string ( ) ,
2222 max_ttl_ms : Yup . number ( ) ,
2323} )
24+ export interface UpdateTemplateFormMeta {
25+ readonly name ?: string
26+ readonly description ?: string
27+ readonly max_ttl ?: number
28+ }
2429
2530export interface TemplateSettingsForm {
2631 template : Template
@@ -29,7 +34,7 @@ export interface TemplateSettingsForm {
2934 isSubmitting : boolean
3035 error ?: unknown
3136 // Helpful to show field errors on Storybook
32- initialTouched ?: FormikTouched < UpdateTemplateMeta >
37+ initialTouched ?: FormikTouched < UpdateTemplateFormMeta >
3338}
3439
3540export const TemplateSettingsForm : FC < TemplateSettingsForm > = ( {
@@ -40,19 +45,22 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
4045 isSubmitting,
4146 initialTouched,
4247} ) => {
43- const form : FormikContextType < UpdateTemplateMeta > = useFormik < UpdateTemplateMeta > ( {
48+ const form : FormikContextType < UpdateTemplateFormMeta > = useFormik < UpdateTemplateFormMeta > ( {
4449 initialValues : {
4550 name : template . name ,
4651 description : template . description ,
47- max_ttl_ms : template . max_ttl_ms ,
52+ max_ttl : template . max_ttl_ms / 1000 ,
4853 } ,
4954 validationSchema,
5055 onSubmit : ( data ) => {
51- onSubmit ( data )
56+ onSubmit ( {
57+ ...data ,
58+ max_ttl_ms : data . max_ttl !== undefined ? data . max_ttl * 1000 : undefined ,
59+ } )
5260 } ,
5361 initialTouched,
5462 } )
55- const getFieldHelpers = getFormHelpersWithError < UpdateTemplateMeta > ( form , error )
63+ const getFieldHelpers = getFormHelpersWithError < UpdateTemplateFormMeta > ( form , error )
5664
5765 return (
5866 < form onSubmit = { form . handleSubmit } aria-label = { Language . formAriaLabel } >
@@ -78,7 +86,7 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
7886 />
7987
8088 < TextField
81- { ...getFieldHelpers ( "max_ttl_ms " ) }
89+ { ...getFieldHelpers ( "max_ttl " ) }
8290 helperText = { Language . maxTtlHelperText }
8391 disabled = { isSubmitting }
8492 fullWidth
0 commit comments