Skip to content

Commit c272057

Browse files
authored
fix: ws schedule top-down restriction (#2008)
Resolves: #1958 Summary: The workspace schedule form no longer disables certain fields based on whether or not a start time is filled out. Instead, we validate that a start time is provided if any of the days are checked.
1 parent 88e8c96 commit c272057

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ describe("validationSchema", () => {
5757
expect(validate).toThrowError(Language.errorNoDayOfWeek)
5858
})
5959

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+
6076
it("allows startTime 16:20", () => {
6177
const values: WorkspaceScheduleFormValues = {
6278
...valid,

site/src/components/WorkspaceScheduleForm/WorkspaceScheduleForm.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dayjs.extend(timezone)
2727

2828
export const Language = {
2929
errorNoDayOfWeek: "Must set at least one day of week",
30+
errorNoTime: "Start time is required",
3031
errorTime: "Time must be in HH:mm format (24 hours)",
3132
errorTimezone: "Invalid timezone",
3233
daysOfWeekLabel: "Days of Week",
@@ -93,6 +94,25 @@ export const validationSchema = Yup.object({
9394

9495
startTime: Yup.string()
9596
.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+
})
96116
.test("is-time-string", Language.errorTime, (value) => {
97117
if (value === "") {
98118
return true
@@ -192,7 +212,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
192212
</Link>
193213
</>,
194214
)}
195-
disabled={isLoading || !form.values.startTime}
215+
disabled={isLoading}
196216
InputLabelProps={{
197217
shrink: true,
198218
}}
@@ -210,7 +230,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
210230
control={
211231
<Checkbox
212232
checked={checkbox.value}
213-
disabled={!form.values.startTime || isLoading}
233+
disabled={isLoading}
214234
onChange={form.handleChange}
215235
name={checkbox.name}
216236
color="primary"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy