анкета не сбивает 1 вопрос
This commit is contained in:
parent
b32f771390
commit
9cebb17a07
@ -11,6 +11,7 @@ import { FormDraggableList } from "./FormDraggableList";
|
|||||||
import {
|
import {
|
||||||
collapseAllQuestions,
|
collapseAllQuestions,
|
||||||
createUntypedQuestion,
|
createUntypedQuestion,
|
||||||
|
createUntypedQuestionForm,
|
||||||
} from "@root/questions/actions";
|
} from "@root/questions/actions";
|
||||||
import { useCurrentQuiz } from "@root/quizes/hooks";
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ export default function FormQuestionsPage() {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
createUntypedQuestion(quiz.backendId);
|
createUntypedQuestionForm(quiz.backendId);
|
||||||
}}
|
}}
|
||||||
data-cy="create-question"
|
data-cy="create-question"
|
||||||
>
|
>
|
||||||
|
@ -29,6 +29,7 @@ export const setQuestions = (questions: RawQuestion[] | null | undefined) =>
|
|||||||
|
|
||||||
export const createUntypedQuestion = (quizId: number, insertAfterQuestionId?: string) => {
|
export const createUntypedQuestion = (quizId: number, insertAfterQuestionId?: string) => {
|
||||||
const { questions } = useQuestionsStore.getState();
|
const { questions } = useQuestionsStore.getState();
|
||||||
|
console.log("insertAfterQuestionId ", insertAfterQuestionId)
|
||||||
|
|
||||||
const questionsAmount = questions.filter(({ type }) => type !== "result").length;
|
const questionsAmount = questions.filter(({ type }) => type !== "result").length;
|
||||||
|
|
||||||
@ -65,6 +66,44 @@ export const createUntypedQuestion = (quizId: number, insertAfterQuestionId?: st
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const createUntypedQuestionForm = (quizId: number, insertAfterQuestionId?: string) => {
|
||||||
|
const { questions } = useQuestionsStore.getState();
|
||||||
|
console.log("insertAfterQuestionId ", insertAfterQuestionId)
|
||||||
|
|
||||||
|
const questionsAmount = questions.filter(({ type }) => type !== "result").length;
|
||||||
|
|
||||||
|
if (questionsAmount >= 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setProducedState(
|
||||||
|
(state) => {
|
||||||
|
const newUntypedQuestion = {
|
||||||
|
id: nanoid(),
|
||||||
|
quizId,
|
||||||
|
type: null,
|
||||||
|
title: "",
|
||||||
|
description: "",
|
||||||
|
deleted: false,
|
||||||
|
expanded: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (insertAfterQuestionId) {
|
||||||
|
const index = state.questions.findIndex((q) => q.id === insertAfterQuestionId);
|
||||||
|
if (index === -1) return;
|
||||||
|
state.questions.splice(index + 1, 0, newUntypedQuestion);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
state.questions.push(newUntypedQuestion);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "createUntypedQuestion",
|
||||||
|
quizId,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const removeQuestion = (questionId: string) =>
|
const removeQuestion = (questionId: string) =>
|
||||||
setProducedState(
|
setProducedState(
|
||||||
(state) => {
|
(state) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user