diff --git a/src/pages/ViewPublicationPage/Footer.tsx b/src/pages/ViewPublicationPage/Footer.tsx index 4bfc019a..ef121c43 100644 --- a/src/pages/ViewPublicationPage/Footer.tsx +++ b/src/pages/ViewPublicationPage/Footer.tsx @@ -54,6 +54,20 @@ export const Footer = ({ } // Логика для аргумента disabled у кнопки "Далее" + const answer = answers.find( + ({ questionId }) => questionId === question.content.id + ); + + if (question.required && answer?.changed) { + setDisableNextButton(false); + } + + if (question.required && !answer?.changed) { + setDisableNextButton(true); + + return; + } + if (linear) { const questionIndex = questions.findIndex(({ id }) => id === question.id); @@ -79,7 +93,7 @@ export const Footer = ({ } } } - }, [question]); + }, [question, answers]); const getNextQuestionId = () => { if (answers.length) { diff --git a/src/pages/ViewPublicationPage/questions/Number.tsx b/src/pages/ViewPublicationPage/questions/Number.tsx index 9cdec8b8..780c308b 100644 --- a/src/pages/ViewPublicationPage/questions/Number.tsx +++ b/src/pages/ViewPublicationPage/questions/Number.tsx @@ -28,7 +28,8 @@ export const Number = ({ currentQuestion }: NumberProps) => { currentQuestion.content.id, currentQuestion.content.chooseRange ? `${currentQuestion.content.start},${max}` - : String(currentQuestion.content.start) + : String(currentQuestion.content.start), + false ); } }, [answer]); diff --git a/src/stores/quizView.ts b/src/stores/quizView.ts index 0f515b32..e8a1b8ba 100644 --- a/src/stores/quizView.ts +++ b/src/stores/quizView.ts @@ -4,6 +4,8 @@ import { devtools } from "zustand/middleware"; type Answer = { questionId: string; answer: string; + // Поле отвечающее за первое изменение ответа, нужно для галочки "Необязательный вопрос" + changed: boolean; }; interface QuizViewStore { @@ -21,14 +23,20 @@ export const useQuizViewStore = create()( ) ); -export const updateAnswer = (questionId: string, answer: string) => { +export const updateAnswer = ( + questionId: string, + answer: string, + changed = true +) => { const answers = [...useQuizViewStore.getState().answers]; - const answerIndex = answers.findIndex((answer) => questionId === answer.questionId); + const answerIndex = answers.findIndex( + (answer) => questionId === answer.questionId + ); if (answerIndex < 0) { - answers.push({ questionId, answer }); + answers.push({ questionId, answer, changed }); } else { - answers[answerIndex] = { questionId, answer }; + answers[answerIndex] = { questionId, answer, changed }; } useQuizViewStore.setState({ answers });