feat: View require
This commit is contained in:
parent
c86e5344ab
commit
16ea7baed3
@ -54,6 +54,20 @@ export const Footer = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Логика для аргумента disabled у кнопки "Далее"
|
// Логика для аргумента 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) {
|
if (linear) {
|
||||||
const questionIndex = questions.findIndex(({ id }) => id === question.id);
|
const questionIndex = questions.findIndex(({ id }) => id === question.id);
|
||||||
|
|
||||||
@ -79,7 +93,7 @@ export const Footer = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [question]);
|
}, [question, answers]);
|
||||||
|
|
||||||
const getNextQuestionId = () => {
|
const getNextQuestionId = () => {
|
||||||
if (answers.length) {
|
if (answers.length) {
|
||||||
|
|||||||
@ -28,7 +28,8 @@ export const Number = ({ currentQuestion }: NumberProps) => {
|
|||||||
currentQuestion.content.id,
|
currentQuestion.content.id,
|
||||||
currentQuestion.content.chooseRange
|
currentQuestion.content.chooseRange
|
||||||
? `${currentQuestion.content.start},${max}`
|
? `${currentQuestion.content.start},${max}`
|
||||||
: String(currentQuestion.content.start)
|
: String(currentQuestion.content.start),
|
||||||
|
false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, [answer]);
|
}, [answer]);
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import { devtools } from "zustand/middleware";
|
|||||||
type Answer = {
|
type Answer = {
|
||||||
questionId: string;
|
questionId: string;
|
||||||
answer: string;
|
answer: string;
|
||||||
|
// Поле отвечающее за первое изменение ответа, нужно для галочки "Необязательный вопрос"
|
||||||
|
changed: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface QuizViewStore {
|
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 answers = [...useQuizViewStore.getState().answers];
|
||||||
const answerIndex = answers.findIndex((answer) => questionId === answer.questionId);
|
const answerIndex = answers.findIndex(
|
||||||
|
(answer) => questionId === answer.questionId
|
||||||
|
);
|
||||||
|
|
||||||
if (answerIndex < 0) {
|
if (answerIndex < 0) {
|
||||||
answers.push({ questionId, answer });
|
answers.push({ questionId, answer, changed });
|
||||||
} else {
|
} else {
|
||||||
answers[answerIndex] = { questionId, answer };
|
answers[answerIndex] = { questionId, answer, changed };
|
||||||
}
|
}
|
||||||
|
|
||||||
useQuizViewStore.setState({ answers });
|
useQuizViewStore.setState({ answers });
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user