Implemented in Editor

This commit is contained in:
Mawoka
2022-10-04 12:38:04 +02:00
parent 4a54ed5bf8
commit 99bd6cc329
8 changed files with 162 additions and 14 deletions
+22 -3
View File
@@ -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')