✨ Implemented in Editor
This commit is contained in:
@@ -17,6 +17,17 @@ export const ABCDQuestionSchema = yup
|
||||
.min(2, 'You need at least 2 answers')
|
||||
.max(16, "You can't have more than 16 answers");
|
||||
|
||||
export const VotingQuestionSchema = yup
|
||||
.array()
|
||||
.of(
|
||||
yup.object({
|
||||
answer: yup.string().required('You need an answer'),
|
||||
image: yup.string().optional().nullable()
|
||||
})
|
||||
)
|
||||
.min(2, 'You need at least 2 answers')
|
||||
.max(16, "You can't have more than 16 answers");
|
||||
|
||||
export const RangeQuestionSchema = yup.object({
|
||||
min: yup.number(),
|
||||
max: yup.number(),
|
||||
@@ -50,9 +61,17 @@ export const dataSchema = yup.object({
|
||||
"The image-url isn't valid"
|
||||
)
|
||||
.lowercase(),
|
||||
answers: yup.lazy((v) =>
|
||||
Array.isArray(v) ? ABCDQuestionSchema : RangeQuestionSchema
|
||||
)
|
||||
answers: yup.lazy((v) => {
|
||||
if (Array.isArray(v)) {
|
||||
if (typeof v[0].right === 'boolean') {
|
||||
return ABCDQuestionSchema;
|
||||
} else {
|
||||
return VotingQuestionSchema;
|
||||
}
|
||||
} else {
|
||||
return RangeQuestionSchema;
|
||||
}
|
||||
})
|
||||
})
|
||||
)
|
||||
.min(1, 'You need at least one question')
|
||||
|
||||
Reference in New Issue
Block a user