Skip to content

Commit ab69c22

Browse files
authored
fix: missing FE ttl constraint validation (#1952)
Resolves: #1908
1 parent b9983e4 commit ab69c22

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

site/src/components/WorkspaceScheduleForm/WorkspaceScheduleForm.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,22 @@ describe("validationSchema", () => {
110110
const validate = () => validationSchema.validateSync(values)
111111
expect(validate).toThrowError(Language.errorTimezone)
112112
})
113+
114+
it("allows a ttl of 7 days", () => {
115+
const values: WorkspaceScheduleFormValues = {
116+
...valid,
117+
ttl: 24 * 7,
118+
}
119+
const validate = () => validationSchema.validateSync(values)
120+
expect(validate).not.toThrowError()
121+
})
122+
123+
it("disallows a ttl of 7 days + 1 hour", () => {
124+
const values: WorkspaceScheduleFormValues = {
125+
...valid,
126+
ttl: 24 * 7 + 1,
127+
}
128+
const validate = () => validationSchema.validateSync(values)
129+
expect(validate).toThrowError("ttl must be less than or equal to 168")
130+
})
113131
})

site/src/components/WorkspaceScheduleForm/WorkspaceScheduleForm.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ export const validationSchema = Yup.object({
124124
}
125125
}
126126
}),
127-
ttl: Yup.number().min(0).integer(),
127+
ttl: Yup.number()
128+
.integer()
129+
.min(0)
130+
.max(24 * 7 /* 7 days */),
128131
})
129132

130133
export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
@@ -171,7 +174,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
171174
<Stack>
172175
<TextField
173176
{...formHelpers("startTime", Language.startTimeHelperText)}
174-
disabled={form.isSubmitting || isLoading}
177+
disabled={isLoading}
175178
InputLabelProps={{
176179
shrink: true,
177180
}}
@@ -189,7 +192,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
189192
</Link>
190193
</>,
191194
)}
192-
disabled={form.isSubmitting || isLoading || !form.values.startTime}
195+
disabled={isLoading || !form.values.startTime}
193196
InputLabelProps={{
194197
shrink: true,
195198
}}
@@ -207,7 +210,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
207210
control={
208211
<Checkbox
209212
checked={checkbox.value}
210-
disabled={!form.values.startTime || form.isSubmitting || isLoading}
213+
disabled={!form.values.startTime || isLoading}
211214
onChange={form.handleChange}
212215
name={checkbox.name}
213216
color="primary"
@@ -226,13 +229,13 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
226229

227230
<TextField
228231
{...formHelpers("ttl", Language.ttlHelperText)}
229-
disabled={form.isSubmitting || isLoading}
232+
disabled={isLoading}
230233
inputProps={{ min: 0, step: 1 }}
231234
label={Language.ttlLabel}
232235
type="number"
233236
/>
234237

235-
<FormFooter onCancel={onCancel} isLoading={form.isSubmitting || isLoading} />
238+
<FormFooter onCancel={onCancel} isLoading={isLoading} />
236239
</Stack>
237240
</form>
238241
</FullPageForm>

0 commit comments

Comments
 (0)