Skip to content

Commit

Permalink
remove validation from class batch for quiz
Browse files Browse the repository at this point in the history
  • Loading branch information
Drish-xD committed Jul 27, 2024
1 parent 8ea5722 commit f0e481c
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/types/form.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const basicSchema = z
.object({
group: z.string({ required_error: 'This field is required' }).min(1, 'This field is required'),
parentBatch: z.string().optional(),
subBatch: z.array(z.string()).min(1, 'This field is required'),
subBatch: z.array(z.string()).optional(),
grade: z.coerce
.number({
required_error: 'This field is required',
Expand Down Expand Up @@ -87,12 +87,24 @@ export const basicSchema = z
}
}

if (data.platform === Platform.Quiz && !data.parentBatch) {
context.addIssue({
code: z.ZodIssueCode.custom,
message: 'This field is required',
path: ['parentBatch'],
});
if (data.platform === Platform.Quiz) {
// Quiz platform validation
if (!data.parentBatch) {
context.addIssue({
code: z.ZodIssueCode.custom,
message: 'This field is required',
path: ['parentBatch'],
});
}
} else {
// Live platform validation
if (!data.subBatch?.length) {
context.addIssue({
code: z.ZodIssueCode.custom,
message: 'This field is required',
path: ['subBatch'],
});
}
}
});

Expand Down Expand Up @@ -203,7 +215,7 @@ export const timelineSchema = z
export const liveSchema = z
.object({
platformLink: z
.string()
.string({ required_error: 'This field is required' })
.transform((value) => (value.trim() ? absoluteLink(value) : ''))
.pipe(z.string().url('This is not a valid url')),
platformId: z.string({ required_error: 'This field is required' }),
Expand Down

0 comments on commit f0e481c

Please sign in to comment.