Skip to content

Commit

Permalink
fix: ws schedule top-down restriction (#2008)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
greyscaled committed Jun 3, 2022
1 parent 88e8c96 commit c272057
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ describe("validationSchema", () => {
expect(validate).toThrowError(Language.errorNoDayOfWeek)
})

it("disallows empty startTime when at least one day is set", () => {
const values: WorkspaceScheduleFormValues = {
...valid,
sunday: false,
monday: true,
tuesday: false,
wednesday: false,
thursday: false,
friday: false,
saturday: false,
startTime: "",
}
const validate = () => validationSchema.validateSync(values)
expect(validate).toThrowError(Language.errorNoTime)
})

it("allows startTime 16:20", () => {
const values: WorkspaceScheduleFormValues = {
...valid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dayjs.extend(timezone)

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

startTime: Yup.string()
.ensure()
.test("required-if-day-selected", Language.errorNoTime, function (value) {
const parent = this.parent as WorkspaceScheduleFormValues

const isDaySelected = [
parent.sunday,
parent.monday,
parent.tuesday,
parent.wednesday,
parent.thursday,
parent.friday,
parent.saturday,
].some((day) => day)

if (isDaySelected) {
return value !== ""
} else {
return true
}
})
.test("is-time-string", Language.errorTime, (value) => {
if (value === "") {
return true
Expand Down Expand Up @@ -192,7 +212,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
</Link>
</>,
)}
disabled={isLoading || !form.values.startTime}
disabled={isLoading}
InputLabelProps={{
shrink: true,
}}
Expand All @@ -210,7 +230,7 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
control={
<Checkbox
checked={checkbox.value}
disabled={!form.values.startTime || isLoading}
disabled={isLoading}
onChange={form.handleChange}
name={checkbox.name}
color="primary"
Expand Down

0 comments on commit c272057

Please sign in to comment.