Skip to content

Commit

Permalink
Update attendance form validation logic for registration dates
Browse files Browse the repository at this point in the history
  • Loading branch information
brage-andreas committed Jan 15, 2025
1 parent faf5c4b commit e9dd457
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import { createDateTimeInput, useFormBuilder } from "../../../../app/form"
const AttendanceFormSchema = AttendanceSchema.omit({
id: true,
}).superRefine((val, ctx) => {
// Check that the registerStart is before the registerEnd
if (!(val.registerStart <= val.deregisterDeadline && val.deregisterDeadline <= val.registerEnd)) {
const message = "Påmeldingsstart < Frist avmelding < Påmeldingsslutt"
if (val.registerStart > val.registerEnd) {
const message = "Påmeldingsstart må være før påmeldingsslutt"
const code = "custom"
ctx.addIssue({ message, code, path: ["registerStart"] })
ctx.addIssue({ message, code, path: ["registerEnd"] })
}

if (val.registerStart > val.deregisterDeadline) {
const message = "Påmeldingsstart må være før frist avmelding"
const code = "custom"
ctx.addIssue({ message, code, path: ["deregisterDeadline"] })
}

Expand Down

0 comments on commit e9dd457

Please sign in to comment.