diff --git a/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx b/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx index da351340..8466085e 100644 --- a/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx +++ b/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx @@ -12,8 +12,12 @@ import { useMediaQuery, useTheme, } from "@mui/material"; -import { addQuestionVariant, deleteQuestionVariant, setQuestionVariantField } from "@root/questions/actions"; -import type { KeyboardEvent, ReactNode } from "react"; +import { + addQuestionVariant, + deleteQuestionVariant, + setQuestionVariantField, +} from "@root/questions/actions"; +import type { ChangeEvent, KeyboardEvent, ReactNode } from "react"; import { useState } from "react"; import { Draggable } from "react-beautiful-dnd"; import type { QuestionVariant } from "../../../model/questionTypes/shared"; @@ -78,28 +82,37 @@ export const AnswerItem = ({ focused={false} placeholder={"Добавьте ответ"} multiline={largeCheck} - onChange={({ target }) => { + onChange={({ target }: ChangeEvent) => { setQuestionVariantAnswer(target.value || " "); }} onKeyDown={(event: KeyboardEvent) => { - // if (disableKeyDown) { - // enqueueSnackbar("100 максимальное количество вопросов"); - // } else if (event.code === "Enter" && !largeCheck) { + if (disableKeyDown) { + enqueueSnackbar("100 максимальное количество вопросов"); + } else if (event.code === "Enter" && !largeCheck) { addQuestionVariant(questionId); - // } + } }} InputProps={{ startAdornment: ( <> - - + + {additionalContent} ), endAdornment: ( - + setQuestionVariantAnswer(e.target.value || " ")} - onKeyDown={(event: KeyboardEvent) => event.stopPropagation()} + onChange={(e) => + setQuestionVariantAnswer(e.target.value || " ") + } + onKeyDown={( + event: KeyboardEvent + ) => event.stopPropagation()} /> - deleteQuestionVariant(questionId, variant.id)}> + + deleteQuestionVariant(questionId, variant.id) + } + > (q.type === "result" && q.content.includes(':"line"')) || q.content.includes(":'line'") + (q) => + (q.type === "result" && q.content.includes(':"line"')) || + q.content.includes(":'line'") ) ) { createResult(quiz?.backendId, "line"); @@ -93,7 +105,12 @@ export default function EditPage() { getData(); }, []); - const { openBranchingPanel, whyCantCreatePublic, canCreatePublic, showConfirmLeaveModal } = useUiTools(); + const { + openBranchingPanel, + whyCantCreatePublic, + canCreatePublic, + showConfirmLeaveModal, + } = useUiTools(); const theme = useTheme(); const navigate = useNavigate(); const currentStep = useQuizStore((state) => state.currentStep); @@ -107,7 +124,6 @@ export default function EditPage() { const [openBranchingPage, setOpenBranchingPage] = useState(false); const [buttonText, setButtonText] = useState("Опубликовать"); - const openBranchingPageHC = () => { if (!openBranchingPage) { deleteTimeoutedQuestions(questions, quiz); @@ -124,23 +140,26 @@ export default function EditPage() { resetEditConfig(); cleanQuestions(); updateModalInfoWhyCantCreate(false); - updateSomeWorkBackend(false) + updateSomeWorkBackend(false); }, [] ); - const updateQuestionHint = useDebouncedCallback((questions: AnyTypedQuizQuestion[]) => { - const problems = checkQuestionHint(questions, quiz); - useUiTools.setState({ whyCantCreatePublic: problems }); - if (Object.keys(problems).length > 0) { - updateQuiz(quiz?.id, (state) => { - state.status = "stop"; - }); - updateCanCreatePublic(false); - } else { - updateCanCreatePublic(true); - } - }, 600); + const updateQuestionHint = useDebouncedCallback( + (questions: AnyTypedQuizQuestion[]) => { + const problems = checkQuestionHint(questions, quiz); + useUiTools.setState({ whyCantCreatePublic: problems }); + if (Object.keys(problems).length > 0) { + updateQuiz(quiz?.id, (state) => { + state.status = "stop"; + }); + updateCanCreatePublic(false); + } else { + updateCanCreatePublic(true); + } + }, + 600 + ); useEffect(() => { updateQuestionHint(questions); @@ -165,9 +184,11 @@ export default function EditPage() { if (!quizConfig) return <>; - const isConditionMet = [1].includes(currentStep) && !openBranchingPanel && quizConfig.type !== "form"; + const isConditionMet = + [1].includes(currentStep) && + !openBranchingPanel && + quizConfig.type !== "form"; - const handleClickStatusQuiz = () => { if (Object.keys(whyCantCreatePublic).length === 0) { if (buttonText === "Опубликовать") { @@ -187,6 +208,17 @@ export default function EditPage() { } }; + const changePage = (index: number) => { + if (currentStep === 2) { + setNextStep(index); + setShowConfirmLeaveModal(true); + + return; + } + + setCurrentStep(index); + }; + return ( <> {/*хедер*/} @@ -221,12 +253,12 @@ export default function EditPage() { - updateQuiz(quiz.id, (quiz) => { - quiz.name = e.target.value; - }) - } + value={quiz.name} + onChange={(e) => + updateQuiz(quiz.id, (quiz) => { + quiz.name = e.target.value; + }) + } fullWidth id="project-name" placeholder="Название проекта окно" @@ -321,7 +353,11 @@ export default function EditPage() { display: isMobile ? "block" : "flex", }} > - {isMobile ? : } + {isMobile ? ( + + ) : ( + + )} @@ -357,7 +395,11 @@ export default function EditPage() { width: "100%", padding: isMobile ? "20px 16px" : "20px 20px", display: "flex", - justifyContent: isMobile ? (isMobileSm ? "center" : "flex-end") : "flex-start", + justifyContent: isMobile + ? isMobileSm + ? "center" + : "flex-end" + : "flex-start", flexDirection: isMobile ? "row-reverse" : "-moz-initial", alignItems: "center", gap: "15px", @@ -398,7 +440,10 @@ export default function EditPage() { "&.Mui-disabled + .MuiSwitch-track": { opacity: 0.5 }, }, "&.Mui-disabled .MuiSwitch-thumb": { - color: theme.palette.mode === "light" ? theme.palette.grey[100] : theme.palette.grey[600], + color: + theme.palette.mode === "light" + ? theme.palette.grey[100] + : theme.palette.grey[600], }, "&.Mui-disabled + .MuiSwitch-track": { opacity: theme.palette.mode === "light" ? 0.7 : 0.3, @@ -411,16 +456,22 @@ export default function EditPage() { }, "& .MuiSwitch-track": { borderRadius: 13, - backgroundColor: theme.palette.mode === "light" ? "#E9E9EA" : "#39393D", + backgroundColor: + theme.palette.mode === "light" ? "#E9E9EA" : "#39393D", opacity: 1, - transition: theme.transitions.create(["background-color"], { - duration: 500, - }), + transition: theme.transitions.create( + ["background-color"], + { + duration: 500, + } + ), }, }} /> - Логика ветвления + + Логика ветвления + )} @@ -437,13 +488,20 @@ export default function EditPage() { minWidth: "130px", }} onClick={() => - Object.keys(whyCantCreatePublic).length === 0 ? () => {} : updateModalInfoWhyCantCreate(true) + Object.keys(whyCantCreatePublic).length === 0 + ? () => {} + : updateModalInfoWhyCantCreate(true) } > Тестовый просмотр ) : ( - +