feat: View require
This commit is contained in:
parent
c86e5344ab
commit
16ea7baed3
@ -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) {
|
||||
|
||||
@ -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]);
|
||||
|
||||
@ -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<QuizViewStore>()(
|
||||
)
|
||||
);
|
||||
|
||||
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 });
|
||||
|
||||
Loading…
Reference in New Issue
Block a user