diff --git a/src/model/questionTypes/shared.ts b/src/model/questionTypes/shared.ts index fb1ed933..2d95ac3b 100644 --- a/src/model/questionTypes/shared.ts +++ b/src/model/questionTypes/shared.ts @@ -60,7 +60,6 @@ export interface QuizQuestionBase { type?: QuestionType | null; expanded: boolean; openedModalSettings: boolean; - required: boolean; deleted: boolean; deleteTimeoutId: number; content: { diff --git a/src/pages/Questions/DataOptions/settingData.tsx b/src/pages/Questions/DataOptions/settingData.tsx index ebd53df8..59d9d20b 100644 --- a/src/pages/Questions/DataOptions/settingData.tsx +++ b/src/pages/Questions/DataOptions/settingData.tsx @@ -86,10 +86,10 @@ export default function SettingsData({ question }: SettingsDataProps) { { - updateQuestion(question.id, question => { - question.required = !target.checked; + updateQuestion(question.id, question => { + question.content.required = !target.checked; }); }} /> @@ -109,7 +109,7 @@ export default function SettingsData({ question }: SettingsDataProps) { label={"Внутреннее название вопроса"} checked={question.content.innerNameCheck} handleChange={({ target }) => { - updateQuestion(question.id, question => { + updateQuestion(question.id, question => { question.content.innerNameCheck = target.checked; question.content.innerName = target.checked ? question.content.innerName : ""; }); diff --git a/src/pages/Questions/DropDown/settingDropDown.tsx b/src/pages/Questions/DropDown/settingDropDown.tsx index 895a27f1..1cffb25e 100644 --- a/src/pages/Questions/DropDown/settingDropDown.tsx +++ b/src/pages/Questions/DropDown/settingDropDown.tsx @@ -128,10 +128,10 @@ export default function SettingDropDown({ question }: SettingDropDownProps) { { - updateQuestion(question.id, question => { - question.required = !e.target.checked; + updateQuestion(question.id, question => { + question.content.required = !e.target.checked; }); }} /> @@ -141,7 +141,7 @@ export default function SettingDropDown({ question }: SettingDropDownProps) { label={"Внутреннее название вопроса"} checked={question.content.innerNameCheck} handleChange={({ target }) => { - updateQuestion(question.id, question => { + updateQuestion(question.id, question => { question.content.innerNameCheck = target.checked; question.content.innerName = target.checked ? question.content.innerName : ""; }); diff --git a/src/pages/Questions/Emoji/settingEmoji.tsx b/src/pages/Questions/Emoji/settingEmoji.tsx index da007509..ffc3cb22 100644 --- a/src/pages/Questions/Emoji/settingEmoji.tsx +++ b/src/pages/Questions/Emoji/settingEmoji.tsx @@ -85,12 +85,11 @@ export default function SettingEmoji({ question }: SettingEmojiProps) { updateQuestion(question.id, question => { + checked={!question.content.required} + handleChange={({ target }) => updateQuestion(question.id, question => { if (question.type !== "emoji") return; - console.log(target.checked) - question.content.required = target.checked; + question.content.required = !target.checked; })} /> updateQuestion(question.id, question => { + handleChange={({ target }) => updateQuestion(question.id, question => { question.content.innerNameCheck = target.checked; question.content.innerName = target.checked ? question.content.innerName : ""; })} diff --git a/src/pages/Questions/OptionsAndPicture/SettingOptionsAndPict.tsx b/src/pages/Questions/OptionsAndPicture/SettingOptionsAndPict.tsx index 4f1bbe2b..76c4993d 100644 --- a/src/pages/Questions/OptionsAndPicture/SettingOptionsAndPict.tsx +++ b/src/pages/Questions/OptionsAndPicture/SettingOptionsAndPict.tsx @@ -111,11 +111,11 @@ export default function SettingOptionsAndPict({ question }: SettingOptionsAndPic updateQuestion(question.id, question => { + checked={!question.content.required} + handleChange={({ target }) => updateQuestion(question.id, question => { if (question.type !== "varimg") return; - question.content.required = target.checked; + question.content.required = !target.checked; })} /> @@ -126,7 +126,7 @@ export default function SettingOptionsAndPict({ question }: SettingOptionsAndPic }} label={"Внутреннее название вопроса"} checked={question.content.innerNameCheck} - handleChange={({ target }) => updateQuestion(question.id, question => { + handleChange={({ target }) => updateQuestion(question.id, question => { question.content.innerNameCheck = target.checked; question.content.innerName = ""; })} diff --git a/src/pages/Questions/OptionsPicture/settingOpytionsPict.tsx b/src/pages/Questions/OptionsPicture/settingOpytionsPict.tsx index f47b281b..40ae6b7d 100644 --- a/src/pages/Questions/OptionsPicture/settingOpytionsPict.tsx +++ b/src/pages/Questions/OptionsPicture/settingOpytionsPict.tsx @@ -211,11 +211,11 @@ export default function SettingOpytionsPict({ question }: SettingOpytionsPictPro updateQuestion(question.id, question => { + checked={!question.content.required} + handleChange={({ target }) => updateQuestion(question.id, question => { if (question.type !== "images") return; - question.content.required = target.checked; + question.content.required = !target.checked; }) } /> diff --git a/src/pages/Questions/OwnTextField/settingTextField.tsx b/src/pages/Questions/OwnTextField/settingTextField.tsx index ad74ac37..4bc77e3c 100644 --- a/src/pages/Questions/OwnTextField/settingTextField.tsx +++ b/src/pages/Questions/OwnTextField/settingTextField.tsx @@ -169,10 +169,10 @@ export default function SettingTextField({ alignItems: isMobile ? "flex-end" : "center", }} label={"Необязательный вопрос"} - checked={!question.required} + checked={!question.content.required} handleChange={(e) => { - updateQuestion(question.id, question => { - question.required = !e.target.checked; + updateQuestion(question.id, question => { + question.content.required = !e.target.checked; }); }} /> @@ -193,7 +193,7 @@ export default function SettingTextField({ label={"Внутреннее название вопроса"} checked={question.content.innerNameCheck} handleChange={({ target }) => { - updateQuestion(question.id, question => { + updateQuestion(question.id, question => { question.content.innerNameCheck = target.checked; question.content.innerName = target.checked ? question.content.innerName diff --git a/src/pages/Questions/RatingOptions/settingRating.tsx b/src/pages/Questions/RatingOptions/settingRating.tsx index e42b0294..4c54921e 100644 --- a/src/pages/Questions/RatingOptions/settingRating.tsx +++ b/src/pages/Questions/RatingOptions/settingRating.tsx @@ -148,12 +148,12 @@ export default function SettingSlider({ question }: SettingSliderProps) { { - updateQuestion(question.id, question => { + updateQuestion(question.id, question => { if (question.type !== "rating") return; - question.required = !e.target.checked; + question.content.required = !e.target.checked; }); }} /> diff --git a/src/pages/Questions/SliderOptions/settingSlider.tsx b/src/pages/Questions/SliderOptions/settingSlider.tsx index c6aef2d1..4677c8fb 100644 --- a/src/pages/Questions/SliderOptions/settingSlider.tsx +++ b/src/pages/Questions/SliderOptions/settingSlider.tsx @@ -78,12 +78,12 @@ export default function SettingSlider({ question }: SettingSliderProps) { { - updateQuestion(question.id, question => { + updateQuestion(question.id, question => { if (question.type !== "number") return; - question.required = !e.target.checked; + question.content.required = !e.target.checked; }); }} /> diff --git a/src/pages/Questions/UploadFile/settingUpload.tsx b/src/pages/Questions/UploadFile/settingUpload.tsx index a7e4cdc2..8968ac4a 100644 --- a/src/pages/Questions/UploadFile/settingUpload.tsx +++ b/src/pages/Questions/UploadFile/settingUpload.tsx @@ -59,10 +59,10 @@ export default function SettingsUpload({ question }: SettingsUploadProps) { mr: isMobile ? "0px" : "16px", }} label={"Необязательный вопрос"} - checked={!question.required} + checked={!question.content.required} handleChange={(e) => { - updateQuestion(question.id, question => { - question.required = !e.target.checked; + updateQuestion(question.id, question => { + question.content.required = !e.target.checked; }); }} /> @@ -82,7 +82,7 @@ export default function SettingsUpload({ question }: SettingsUploadProps) { label={"Внутреннее название вопроса"} checked={question.content.innerNameCheck} handleChange={({ target }) => { - updateQuestion(question.id, question => { + updateQuestion(question.id, question => { question.content.innerNameCheck = target.checked; question.content.innerName = target.checked ? question.content.innerName : ""; }); diff --git a/src/pages/Questions/answerOptions/responseSettings.tsx b/src/pages/Questions/answerOptions/responseSettings.tsx index 8ed5dd2e..8f4f50fe 100644 --- a/src/pages/Questions/answerOptions/responseSettings.tsx +++ b/src/pages/Questions/answerOptions/responseSettings.tsx @@ -1,9 +1,9 @@ import { - Box, - Tooltip, - Typography, - useMediaQuery, - useTheme, + Box, + Tooltip, + Typography, + useMediaQuery, + useTheme, } from "@mui/material"; import { setQuestionInnerName, updateQuestion } from "@root/questions/actions"; import CustomCheckbox from "@ui_kit/CustomCheckbox"; @@ -12,165 +12,166 @@ import { useDebouncedCallback } from "use-debounce"; import InfoIcon from "../../../assets/icons/InfoIcon"; import type { QuizQuestionVariant } from "../../../model/questionTypes/variant"; - interface Props { - question: QuizQuestionVariant; + question: QuizQuestionVariant; } export default function ResponseSettings({ question }: Props) { - const theme = useTheme(); - const isTablet = useMediaQuery(theme.breakpoints.down(900)); + const theme = useTheme(); + const isTablet = useMediaQuery(theme.breakpoints.down(900)); - const isFigmaTablte = useMediaQuery(theme.breakpoints.down(990)); - const isMobile = useMediaQuery(theme.breakpoints.down(790)); + const isFigmaTablte = useMediaQuery(theme.breakpoints.down(990)); + const isMobile = useMediaQuery(theme.breakpoints.down(790)); - const updateQuestionInnerName = useDebouncedCallback((value) => { - setQuestionInnerName(question.id, value); - }, 200); + const updateQuestionInnerName = useDebouncedCallback((value) => { + setQuestionInnerName(question.id, value); + }, 200); - return ( - + + - + { + updateQuestion(question.id, (question) => { + if (!("largeCheck" in question.content)) return; + + question.content.largeCheck = target.checked; + }); + }} + /> + { + updateQuestion(question.id, (question) => { + if (!("multi" in question.content)) return; + + question.content.multi = target.checked; + }); + }} + /> + { + updateQuestion(question.id, (question) => { + if (!("own" in question.content)) return; + + question.content.own = target.checked; + }); + }} + /> + + + + Настройки вопросов + + { + updateQuestion(question.id, (question) => { + question.content.required = !target.checked; + }); + }} + /> + + { + updateQuestion(question.id, (question) => { + question.content.innerNameCheck = target.checked; + question.content.innerName = target.checked + ? question.content.innerName + : ""; + }); + }} + /> + {isMobile && ( + - - Настройки ответов - - { - updateQuestion(question.id, question => { - if (!("largeCheck" in question.content)) return; - - question.content.largeCheck = target.checked; - }); - }} - /> - { - updateQuestion(question.id, question => { - if (!("multi" in question.content)) return; - - question.content.multi = target.checked; - }); - }} - /> - { - updateQuestion(question.id, question => { - if (!("own" in question.content)) return; - - question.content.own = target.checked; - }); - }} - /> - - - - Настройки вопросов - - { - updateQuestion(question.id, question => { - question.required = !target.checked; - }); - }} - /> - - { - updateQuestion(question.id, question => { - question.content.innerNameCheck = target.checked; - question.content.innerName = target.checked ? question.content.innerName : ""; - }); - }} - /> - {isMobile && ( - - - - - - )} - - {question.content.innerNameCheck && ( - updateQuestionInnerName(target.value)} - /> - )} - + + + + + )} - ); + {question.content.innerNameCheck && ( + updateQuestionInnerName(target.value)} + /> + )} + + + ); } diff --git a/src/pages/ViewPublicationPage/Footer.tsx b/src/pages/ViewPublicationPage/Footer.tsx index f54e530e..8e473c18 100644 --- a/src/pages/ViewPublicationPage/Footer.tsx +++ b/src/pages/ViewPublicationPage/Footer.tsx @@ -3,17 +3,14 @@ import { Box, Button, useTheme } from "@mui/material"; import { useQuizViewStore } from "@root/quizView"; -import type { - AnyTypedQuizQuestion, - QuizQuestionBase, -} from "../../model/questionTypes/shared"; +import type { AnyTypedQuizQuestion, QuizQuestionBase } from "../../model/questionTypes/shared"; import { getQuestionByContentId } from "@root/questions/actions"; import { enqueueSnackbar } from "notistack"; type FooterProps = { questions: AnyTypedQuizQuestion[]; setCurrentQuestion: (step: AnyTypedQuizQuestion) => void; - question: QuizQuestionBase; + question: AnyTypedQuizQuestion; }; export const Footer = ({ @@ -21,9 +18,6 @@ export const Footer = ({ questions, question, }: FooterProps) => { - const [disabledQuestionsId, setDisabledQuestionsId] = useState>( - new Set() - ); const [disablePreviousButton, setDisablePreviousButton] = useState(false); const [disableNextButton, setDisableNextButton] = useState(false); @@ -58,16 +52,18 @@ export const Footer = ({ ({ questionId }) => questionId === question.content.id ); - debugger; - - if (question.required && answer) { - setDisableNextButton(true); + if ("required" in question.content && question.content.required && answer) { + setDisableNextButton(false); return; } - if (question.required && !answer) { - setDisableNextButton(false); + if ( + "required" in question.content && + question.content.required && + !answer + ) { + setDisableNextButton(true); return; } @@ -107,7 +103,7 @@ export const Footer = ({ let readyBeNextQuestion = ""; - question.content.rule.main.forEach(({ next, rules }) => { + (question as QuizQuestionBase).content.rule.main.forEach(({ next, rules }) => { let longerArray = Math.max( rules[0].answers.length, [answer?.answer].length diff --git a/src/pages/ViewPublicationPage/questions/Number.tsx b/src/pages/ViewPublicationPage/questions/Number.tsx index c5a39293..590da466 100644 --- a/src/pages/ViewPublicationPage/questions/Number.tsx +++ b/src/pages/ViewPublicationPage/questions/Number.tsx @@ -57,8 +57,7 @@ export const Number = ({ currentQuestion }: NumberProps) => { currentQuestion.content.id, currentQuestion.content.chooseRange ? `${currentQuestion.content.start}—${max}` - : String(currentQuestion.content.start), - false + : String(currentQuestion.content.start) ); setMinRange(String(currentQuestion.content.start)); diff --git a/src/stores/questions/actions.ts b/src/stores/questions/actions.ts index c920d781..10dc38a2 100644 --- a/src/stores/questions/actions.ts +++ b/src/stores/questions/actions.ts @@ -176,9 +176,9 @@ const REQUEST_DEBOUNCE = 200; const requestQueue = new RequestQueue(); let requestTimeoutId: ReturnType; -export const updateQuestion = ( +export const updateQuestion = ( questionId: string, - updateFn: (question: AnyTypedQuizQuestion) => void, + updateFn: (question: T) => void, skipQueue = false, ) => { setProducedState(state => { @@ -186,7 +186,7 @@ export const updateQuestion = ( if (!question) return; if (question.type === null) throw new Error("Cannot update untyped question, use 'updateUntypedQuestion' instead"); - updateFn(question); + updateFn(question as T); }, { type: "updateQuestion", questionId,