diff --git a/src/pages/Questions/BranchingModal/Settings.tsx b/src/pages/Questions/BranchingModal/Settings.tsx index a5db68d4..dbd37f91 100644 --- a/src/pages/Questions/BranchingModal/Settings.tsx +++ b/src/pages/Questions/BranchingModal/Settings.tsx @@ -6,7 +6,6 @@ import { useState, useRef, useEffect } from "react"; import { useParams } from "react-router-dom"; import { useQuestionsStore } from "@root/questions/store"; import { updateQuestion, getQuestionById } from "@root/questions/actions"; -import { AnyTypedQuizQuestion } from "../../../model/questionTypes/shared" import { SelectChangeEvent } from '@mui/material/Select'; import CalendarIcon from "@icons/CalendarIcon"; import { DatePicker } from "@mui/x-date-pickers"; @@ -15,6 +14,9 @@ import { TimePicker } from '@mui/x-date-pickers/TimePicker'; import InfoIcon from "@icons/Info"; import { DeleteIcon } from "@icons/questionsPage/deleteIcon"; +import type { AnyTypedQuizQuestion } from "../../../model/questionTypes/shared" +import type { QuizQuestionNumber } from "../../../model/questionTypes/number" + const CONDITIONS = [ "Все условия обязательны", "Обязательно хотя бы одно условие", @@ -514,47 +516,34 @@ const NumberInputsType = ({ parentQuestion, targetQuestion, ruleIndex, setParent (Укажите один или несколько вариантов) - ) => { - - let newParentQuestion = JSON.parse(JSON.stringify(parentQuestion)) - newParentQuestion.content.rule.main[ruleIndex].rules[0].answers[0] = Number((event.target as HTMLInputElement).value.replace(/[^0-9,\s]/g, "")) - if (newParentQuestion.content.rule.main[ruleIndex].rules[0].answers[1] === undefined) newParentQuestion.content.rule.main[ruleIndex].rules[0].answers[1] = 0 - setParentQuestion(newParentQuestion) - - }} - /> - {parentQuestion.content.chooseRange && + ) => { - - let newParentQuestion = JSON.parse(JSON.stringify(parentQuestion)) - newParentQuestion.content.rule.main[ruleIndex].rules[0].answers[1] = Number((event.target as HTMLInputElement).value.replace(/[^0-9,\s]/g, "")) - if (newParentQuestion.content.rule.main[ruleIndex].rules[0].answers[0] === undefined) newParentQuestion.content.rule.main[ruleIndex].rules[0].answers[0] = 0 + sx={{ marginTop: "20px", width: "100%" }} + placeholder="от" + value={parentQuestion.content.rule.main[ruleIndex].rules[0].answers[0]?.split("—")[0]} + onChange={({ target }: React.ChangeEvent) => { + const newParentQuestion = JSON.parse(JSON.stringify(parentQuestion)) + const previousValue = newParentQuestion.content.rule.main[ruleIndex].rules[0].answers[0]; + newParentQuestion.content.rule.main[ruleIndex].rules[0].answers[0] =(parentQuestion as QuizQuestionNumber).content.chooseRange ? previousValue ? `${target.value}—${previousValue.split("—")[1] || 0}` : `${target.value}—0` : target.value; setParentQuestion(newParentQuestion) - }} /> + {(parentQuestion as QuizQuestionNumber).content.chooseRange && + ) => { + const newParentQuestion = JSON.parse(JSON.stringify(parentQuestion)) + const previousValue = newParentQuestion.content.rule.main[ruleIndex].rules[0].answers[0]; + newParentQuestion.content.rule.main[ruleIndex].rules[0].answers[0] = previousValue ? `${previousValue.split("—")[0] || 0}—${target.value}` : `0—${target.value}` + setParentQuestion(newParentQuestion) - } - - - + }} + /> + } + ) } diff --git a/src/pages/Questions/ButtonsOptions.tsx b/src/pages/Questions/ButtonsOptions.tsx index 63698876..b9b61960 100644 --- a/src/pages/Questions/ButtonsOptions.tsx +++ b/src/pages/Questions/ButtonsOptions.tsx @@ -22,7 +22,7 @@ import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared"; import { useCurrentQuiz } from "@root/quizes/hooks"; import { enqueueSnackbar } from "notistack"; import { useQuestionsStore } from "@root/questions/store"; - +import { updateOpenedModalSettingsId } from "@root/questions/actions"; interface Props { switchState: string; @@ -175,8 +175,9 @@ export default function ButtonsOptions({ { - SSHC(value); - myFunc(question); + openedModal() + // SSHC(value); + // myFunc(question); }} sx={{ backgroundColor: diff --git a/src/pages/ViewPublicationPage/questions/Number.tsx b/src/pages/ViewPublicationPage/questions/Number.tsx index 780c308b..073b1102 100644 --- a/src/pages/ViewPublicationPage/questions/Number.tsx +++ b/src/pages/ViewPublicationPage/questions/Number.tsx @@ -27,7 +27,7 @@ export const Number = ({ currentQuestion }: NumberProps) => { updateAnswer( currentQuestion.content.id, currentQuestion.content.chooseRange - ? `${currentQuestion.content.start},${max}` + ? `${currentQuestion.content.start}—${max}` : String(currentQuestion.content.start), false ); @@ -50,7 +50,7 @@ export const Number = ({ currentQuestion }: NumberProps) => { placeholder="0" value={ currentQuestion.content.chooseRange - ? answer?.split(",")[0] + ? answer?.split("—")[0] : answer } onChange={({ target }) => { @@ -81,18 +81,18 @@ export const Number = ({ currentQuestion }: NumberProps) => { placeholder="0" value={ currentQuestion.content.chooseRange - ? answer?.split(",")[0] + ? answer?.split("—")[0] : answer } onChange={({ target }) => { updateAnswer( currentQuestion.content.id, window.Number(target.value) > - window.Number(answer?.split(",")[1]) - ? `${answer?.split(",")[1]},${answer?.split(",")[1]}` + window.Number(answer?.split("—")[1]) + ? `${answer?.split("—")[1]}—${answer?.split("—")[1]}` : window.Number(target.value) < min - ? `${min},${answer?.split(",")[1]}` - : `${target.value},${answer?.split(",")[1]}` + ? `${min}—${answer?.split("—")[1]}` + : `${target.value}—${answer?.split("—")[1]}` ); }} sx={{ @@ -102,16 +102,16 @@ export const Number = ({ currentQuestion }: NumberProps) => { /> { updateAnswer( currentQuestion.content.id, window.Number(target.value) > max - ? `${answer?.split(",")[0]},${max}` + ? `${answer?.split("—")[0]}—${max}` : window.Number(target.value) < - window.Number(answer?.split(",")[0]) - ? `${answer?.split(",")[0]},${answer?.split(",")[0]}` - : `${answer?.split(",")[0]},${target.value}` + window.Number(answer?.split("—")[0]) + ? `${answer?.split("—")[0]}—${answer?.split("—")[0]}` + : `${answer?.split("—")[0]}—${target.value}` ); }} sx={{ @@ -124,8 +124,8 @@ export const Number = ({ currentQuestion }: NumberProps) => { 1 - ? answer?.split(",").map((item) => window.Number(item)) + ? answer?.split("—").length || 0 > 1 + ? answer?.split("—").map((item) => window.Number(item)) : [min, min + 1] : window.Number(answer || 1) } @@ -138,7 +138,10 @@ export const Number = ({ currentQuestion }: NumberProps) => { marginTop: "25px", }} onChange={(_, value) => { - updateAnswer(currentQuestion.content.id, String(value)); + updateAnswer( + currentQuestion.content.id, + String(value).replace(",", "—") + ); }} /> diff --git a/src/stores/questions/actions.ts b/src/stores/questions/actions.ts index dc29751d..fed3d67e 100644 --- a/src/stores/questions/actions.ts +++ b/src/stores/questions/actions.ts @@ -288,7 +288,7 @@ export const createTypedQuestion = async ( title: question.title, description: question.description, page: 0, - required: true, + required: false, content: JSON.stringify(defaultQuestionByType[type].content), });