анкета не сбивает 1 вопрос

This commit is contained in:
Nastya 2024-08-11 08:37:33 +03:00
parent b32f771390
commit 9cebb17a07
2 changed files with 41 additions and 1 deletions

@ -11,6 +11,7 @@ import { FormDraggableList } from "./FormDraggableList";
import {
collapseAllQuestions,
createUntypedQuestion,
createUntypedQuestionForm,
} from "@root/questions/actions";
import { useCurrentQuiz } from "@root/quizes/hooks";
@ -76,7 +77,7 @@ export default function FormQuestionsPage() {
},
}}
onClick={() => {
createUntypedQuestion(quiz.backendId);
createUntypedQuestionForm(quiz.backendId);
}}
data-cy="create-question"
>

@ -29,6 +29,7 @@ export const setQuestions = (questions: RawQuestion[] | null | undefined) =>
export const createUntypedQuestion = (quizId: number, insertAfterQuestionId?: string) => {
const { questions } = useQuestionsStore.getState();
console.log("insertAfterQuestionId ", insertAfterQuestionId)
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) =>
setProducedState(
(state) => {