numbered the questions in the Questionnaire type

This commit is contained in:
ArtChaos189 2023-12-16 15:17:07 +03:00
parent 194c3aade5
commit 5fb444e7bc
8 changed files with 947 additions and 960 deletions

@ -29,7 +29,17 @@ import {
useMediaQuery, useMediaQuery,
useTheme, useTheme,
} from "@mui/material"; } from "@mui/material";
import { copyQuestion, createUntypedQuestion, deleteQuestion, clearRuleForAll, toggleExpandQuestion, updateQuestion, updateUntypedQuestion, getQuestionByContentId, deleteQuestionWithTimeout } from "@root/questions/actions"; import {
copyQuestion,
createUntypedQuestion,
deleteQuestion,
clearRuleForAll,
toggleExpandQuestion,
updateQuestion,
updateUntypedQuestion,
getQuestionByContentId,
deleteQuestionWithTimeout,
} from "@root/questions/actions";
import { updateRootContentId } from "@root/quizes/actions"; import { updateRootContentId } from "@root/quizes/actions";
import { useRef, useState } from "react"; import { useRef, useState } from "react";
import type { DraggableProvidedDragHandleProps } from "react-beautiful-dnd"; import type { DraggableProvidedDragHandleProps } from "react-beautiful-dnd";
@ -63,7 +73,7 @@ export default function QuestionsPageCard({ question, draggableProps, isDragging
const setTitle = useDebouncedCallback((title) => { const setTitle = useDebouncedCallback((title) => {
const updateQuestionFn = question.type === null ? updateUntypedQuestion : updateQuestion; const updateQuestionFn = question.type === null ? updateUntypedQuestion : updateQuestion;
updateQuestionFn(question.id, question => { updateQuestionFn(question.id, (question) => {
question.title = title; question.title = title;
}); });
}, 200); }, 200);
@ -102,7 +112,7 @@ export default function QuestionsPageCard({ question, draggableProps, isDragging
<TextField <TextField
defaultValue={question.title} defaultValue={question.title}
placeholder={"Заголовок вопроса"} placeholder={"Заголовок вопроса"}
onChange={({ target }: { target: HTMLInputElement; }) => setTitle(target.value || " ")} onChange={({ target }: { target: HTMLInputElement }) => setTitle(target.value || " ")}
InputProps={{ InputProps={{
startAdornment: ( startAdornment: (
<Box> <Box>
@ -128,9 +138,7 @@ export default function QuestionsPageCard({ question, draggableProps, isDragging
margin: isMobile ? "10px 0" : 0, margin: isMobile ? "10px 0" : 0,
"& .MuiInputBase-root": { "& .MuiInputBase-root": {
color: "#000000", color: "#000000",
backgroundColor: question.expanded backgroundColor: question.expanded ? theme.palette.background.default : "transparent",
? theme.palette.background.default
: "transparent",
height: "48px", height: "48px",
borderRadius: "10px", borderRadius: "10px",
".MuiOutlinedInput-notchedOutline": { ".MuiOutlinedInput-notchedOutline": {
@ -226,13 +234,8 @@ export default function QuestionsPageCard({ question, draggableProps, isDragging
userSelect: "none", userSelect: "none",
}} }}
/> />
<IconButton <IconButton sx={{ padding: "0" }} onClick={() => copyQuestion(question.id, question.quizId)}>
sx={{ padding: "0" }} <CopyIcon style={{ color: theme.palette.brightPurple.main }} />
onClick={() => copyQuestion(question.id, question.quizId)}
>
<CopyIcon
style={{ color: theme.palette.brightPurple.main }}
/>
</IconButton> </IconButton>
<IconButton <IconButton
sx={{ sx={{
@ -244,26 +247,30 @@ export default function QuestionsPageCard({ question, draggableProps, isDragging
onClick={() => { onClick={() => {
const deleteFn = () => { const deleteFn = () => {
if (question.type !== null) { if (question.type !== null) {
if (question.content.rule.parentId === "root") { //удалить из стора root и очистить rule всем вопросам if (question.content.rule.parentId === "root") {
//удалить из стора root и очистить rule всем вопросам
updateRootContentId(quiz.id, ""); updateRootContentId(quiz.id, "");
clearRuleForAll(); clearRuleForAll();
deleteQuestion(question.id); deleteQuestion(question.id);
questions.forEach(q => { questions.forEach((q) => {
if (q.type === "result") { if (q.type === "result") {
deleteQuestion(q.id); deleteQuestion(q.id);
} }
}); });
} else if (question.content.rule.parentId.length > 0) { //удалить из стора вопрос из дерева и очистить его потомков } else if (question.content.rule.parentId.length > 0) {
//удалить из стора вопрос из дерева и очистить его потомков
const clearQuestions = [] as string[]; const clearQuestions = [] as string[];
//записываем потомков , а их результаты удаляем //записываем потомков , а их результаты удаляем
const getChildren = (parentQuestion: AnyTypedQuizQuestion) => { const getChildren = (parentQuestion: AnyTypedQuizQuestion) => {
questions.forEach((targetQuestion) => { questions.forEach((targetQuestion) => {
if (targetQuestion.content.rule.parentId === parentQuestion.content.id) {//если у вопроса совпал родитель с родителем => он потомок, в кучу его if (targetQuestion.content.rule.parentId === parentQuestion.content.id) {
//если у вопроса совпал родитель с родителем => он потомок, в кучу его
if (targetQuestion.type === "result") { if (targetQuestion.type === "result") {
deleteQuestion(targetQuestion.id); deleteQuestion(targetQuestion.id);
} else { } else {
if (!clearQuestions.includes(targetQuestion.content.id)) clearQuestions.push(targetQuestion.content.id); if (!clearQuestions.includes(targetQuestion.content.id))
clearQuestions.push(targetQuestion.content.id);
getChildren(targetQuestion); //и ищем его потомков getChildren(targetQuestion); //и ищем его потомков
} }
} }
@ -272,7 +279,7 @@ export default function QuestionsPageCard({ question, draggableProps, isDragging
getChildren(question); getChildren(question);
//чистим потомков от инфы ветвления //чистим потомков от инфы ветвления
clearQuestions.forEach((id) => { clearQuestions.forEach((id) => {
updateQuestion(id, question => { updateQuestion(id, (question) => {
question.content.rule.parentId = ""; question.content.rule.parentId = "";
question.content.rule.main = []; question.content.rule.main = [];
question.content.rule.default = ""; question.content.rule.default = "";
@ -282,10 +289,18 @@ export default function QuestionsPageCard({ question, draggableProps, isDragging
//чистим rule родителя //чистим rule родителя
const parentQuestion = getQuestionByContentId(question.content.rule.parentId); const parentQuestion = getQuestionByContentId(question.content.rule.parentId);
const newRule = {}; const newRule = {};
newRule.main = parentQuestion.content.rule.main.filter((data) => data.next !== question.content.id); //удаляем условия перехода от родителя к этому вопросу newRule.main = parentQuestion.content.rule.main.filter(
(data) => data.next !== question.content.id
); //удаляем условия перехода от родителя к этому вопросу
newRule.parentId = parentQuestion.content.rule.parentId; newRule.parentId = parentQuestion.content.rule.parentId;
newRule.default = parentQuestion.content.rule.parentId === question.content.id ? "" : parentQuestion.content.rule.parentId; newRule.default =
newRule.children = [...parentQuestion.content.rule.children].splice(parentQuestion.content.rule.children.indexOf(question.content.id), 1); parentQuestion.content.rule.parentId === question.content.id
? ""
: parentQuestion.content.rule.parentId;
newRule.children = [...parentQuestion.content.rule.children].splice(
parentQuestion.content.rule.children.indexOf(question.content.id),
1
);
updateQuestion(question.content.rule.parentId, (PQ) => { updateQuestion(question.content.rule.parentId, (PQ) => {
PQ.content.rule = newRule; PQ.content.rule = newRule;
@ -293,7 +308,6 @@ export default function QuestionsPageCard({ question, draggableProps, isDragging
deleteQuestion(question.id); deleteQuestion(question.id);
} }
deleteQuestion(question.id); deleteQuestion(question.id);
} else { } else {
console.log("удаляю безтипогово"); console.log("удаляю безтипогово");
@ -305,13 +319,11 @@ export default function QuestionsPageCard({ question, draggableProps, isDragging
}} }}
data-cy="delete-question" data-cy="delete-question"
> >
<DeleteIcon <DeleteIcon style={{ color: theme.palette.brightPurple.main }} />
style={{ color: theme.palette.brightPurple.main }}
/>
</IconButton> </IconButton>
</Box> </Box>
)} )}
{question.type !== null && {question.type !== null && (
<Box <Box
style={{ style={{
display: "flex", display: "flex",
@ -322,17 +334,13 @@ export default function QuestionsPageCard({ question, draggableProps, isDragging
marginLeft: "3px", marginLeft: "3px",
borderRadius: "50%", borderRadius: "50%",
fontSize: "16px", fontSize: "16px",
color: question.expanded color: question.expanded ? theme.palette.brightPurple.main : "#FFF",
? theme.palette.brightPurple.main background: question.expanded ? "#EEE4FC" : theme.palette.brightPurple.main,
: "#FFF",
background: question.expanded
? "#EEE4FC"
: theme.palette.brightPurple.main,
}} }}
> >
{question.page + 1} {question.page + 1}
</Box> </Box>
} )}
<IconButton <IconButton
disableRipple disableRipple
sx={{ sx={{
@ -392,8 +400,7 @@ export default function QuestionsPageCard({ question, draggableProps, isDragging
backgroundPosition: "bottom", backgroundPosition: "bottom",
backgroundRepeat: "repeat-x", backgroundRepeat: "repeat-x",
backgroundSize: "20px 1px", backgroundSize: "20px 1px",
backgroundImage: backgroundImage: "radial-gradient(circle, #7E2AEA 6px, #F2F3F7 1px)",
"radial-gradient(circle, #7E2AEA 6px, #F2F3F7 1px)",
}} }}
/> />
<PlusIcon /> <PlusIcon />
@ -406,82 +413,27 @@ export default function QuestionsPageCard({ question, draggableProps, isDragging
const IconAndrom = (isExpanded: boolean, questionType: QuestionType | null) => { const IconAndrom = (isExpanded: boolean, questionType: QuestionType | null) => {
switch (questionType) { switch (questionType) {
case "variant": case "variant":
return ( return <Answer color={isExpanded ? "#9A9AAF" : "#7E2AEA"} sx={{ height: "22px", width: "20px" }} />;
<Answer
color={isExpanded ? "#9A9AAF" : "#7E2AEA"}
sx={{ height: "22px", width: "20px" }}
/>
);
case "images": case "images":
return ( return <OptionsPict color={isExpanded ? "#9A9AAF" : "#7E2AEA"} sx={{ height: "22px", width: "20px" }} />;
<OptionsPict
color={isExpanded ? "#9A9AAF" : "#7E2AEA"}
sx={{ height: "22px", width: "20px" }}
/>
);
case "varimg": case "varimg":
return ( return <OptionsAndPict color={isExpanded ? "#9A9AAF" : "#7E2AEA"} sx={{ height: "22px", width: "20px" }} />;
<OptionsAndPict
color={isExpanded ? "#9A9AAF" : "#7E2AEA"}
sx={{ height: "22px", width: "20px" }}
/>
);
case "emoji": case "emoji":
return ( return <Emoji color={isExpanded ? "#9A9AAF" : "#7E2AEA"} sx={{ height: "22px", width: "20px" }} />;
<Emoji
color={isExpanded ? "#9A9AAF" : "#7E2AEA"}
sx={{ height: "22px", width: "20px" }}
/>
);
case "text": case "text":
return ( return <Input color={isExpanded ? "#9A9AAF" : "#7E2AEA"} sx={{ height: "22px", width: "20px" }} />;
<Input
color={isExpanded ? "#9A9AAF" : "#7E2AEA"}
sx={{ height: "22px", width: "20px" }}
/>
);
case "select": case "select":
return ( return <DropDown color={isExpanded ? "#9A9AAF" : "#7E2AEA"} sx={{ height: "22px", width: "20px" }} />;
<DropDown
color={isExpanded ? "#9A9AAF" : "#7E2AEA"}
sx={{ height: "22px", width: "20px" }}
/>
);
case "date": case "date":
return ( return <Date color={isExpanded ? "#9A9AAF" : "#7E2AEA"} sx={{ height: "22px", width: "20px" }} />;
<Date
color={isExpanded ? "#9A9AAF" : "#7E2AEA"}
sx={{ height: "22px", width: "20px" }}
/>
);
case "number": case "number":
return ( return <Slider color={isExpanded ? "#9A9AAF" : "#7E2AEA"} sx={{ height: "22px", width: "20px" }} />;
<Slider
color={isExpanded ? "#9A9AAF" : "#7E2AEA"}
sx={{ height: "22px", width: "20px" }}
/>
);
case "file": case "file":
return ( return <Download color={isExpanded ? "#9A9AAF" : "#7E2AEA"} sx={{ height: "22px", width: "20px" }} />;
<Download
color={isExpanded ? "#9A9AAF" : "#7E2AEA"}
sx={{ height: "22px", width: "20px" }}
/>
);
case "page": case "page":
return ( return <Page color={isExpanded ? "#9A9AAF" : "#7E2AEA"} sx={{ height: "22px", width: "20px" }} />;
<Page
color={isExpanded ? "#9A9AAF" : "#7E2AEA"}
sx={{ height: "22px", width: "20px" }}
/>
);
case "rating": case "rating":
return ( return <RatingIcon color={isExpanded ? "#9A9AAF" : "#7E2AEA"} sx={{ height: "22px", width: "20px" }} />;
<RatingIcon
color={isExpanded ? "#9A9AAF" : "#7E2AEA"}
sx={{ height: "22px", width: "20px" }}
/>
);
default: default:
return <></>; return <></>;
} }

@ -5,14 +5,12 @@ import { Draggable } from "react-beautiful-dnd";
import { AnyTypedQuizQuestion, UntypedQuizQuestion } from "../../../../model/questionTypes/shared"; import { AnyTypedQuizQuestion, UntypedQuizQuestion } from "../../../../model/questionTypes/shared";
import QuestionsPageCard from "./QuestionPageCard"; import QuestionsPageCard from "./QuestionPageCard";
type FormDraggableListItemProps = { type FormDraggableListItemProps = {
question: AnyTypedQuizQuestion | UntypedQuizQuestion; question: AnyTypedQuizQuestion | UntypedQuizQuestion;
questionIndex: number; questionIndex: number;
}; };
export default memo( export default memo(({ question, questionIndex }: FormDraggableListItemProps) => {
({ question, questionIndex }: FormDraggableListItemProps) => {
const theme = useTheme(); const theme = useTheme();
return ( return (
@ -45,7 +43,7 @@ export default memo(
</Typography> </Typography>
<Typography <Typography
onClick={() => { onClick={() => {
updateQuestion(question.id, question => { updateQuestion(question.id, (question) => {
question.deleted = false; question.deleted = false;
}); });
}} }}
@ -80,5 +78,4 @@ export default memo(
)} )}
</Draggable> </Draggable>
); );
} });
);

@ -11,8 +11,8 @@ import OptionsPict from "@icons/questionsPage/options_pict";
import Page from "@icons/questionsPage/page"; import Page from "@icons/questionsPage/page";
import RatingIcon from "@icons/questionsPage/rating"; import RatingIcon from "@icons/questionsPage/rating";
import Slider from "@icons/questionsPage/slider"; import Slider from "@icons/questionsPage/slider";
import { Box, InputAdornment, Paper } from "@mui/material"; import { Box, FormControlLabel, IconButton, InputAdornment, Paper, useMediaQuery, useTheme } from "@mui/material";
import { updateQuestion, updateUntypedQuestion } from "@root/questions/actions"; import { toggleExpandQuestion, updateQuestion, updateUntypedQuestion } from "@root/questions/actions";
import CustomTextField from "@ui_kit/CustomTextField"; import CustomTextField from "@ui_kit/CustomTextField";
import { useRef, useState } from "react"; import { useRef, useState } from "react";
import type { DraggableProvidedDragHandleProps } from "react-beautiful-dnd"; import type { DraggableProvidedDragHandleProps } from "react-beautiful-dnd";
@ -22,7 +22,13 @@ import SwitchQuestionsPage from "../../SwitchQuestionsPage";
import { ChooseAnswerModal } from "./ChooseAnswerModal"; import { ChooseAnswerModal } from "./ChooseAnswerModal";
import FormTypeQuestions from "../FormTypeQuestions"; import FormTypeQuestions from "../FormTypeQuestions";
import { QuestionType } from "@model/question/question"; import { QuestionType } from "@model/question/question";
import { CrossedEyeIcon } from "@icons/CrossedEyeIcon";
import { ArrowDownIcon } from "@icons/questionsPage/ArrowDownIcon";
import { CopyIcon } from "@icons/questionsPage/CopyIcon";
import { DeleteIcon } from "@icons/questionsPage/deleteIcon";
import { HideIcon } from "@icons/questionsPage/hideIcon";
import ExpandLessIcon from "@mui/icons-material/ExpandLess";
import { NoLuggageOutlined, SignalCellularNullOutlined } from "@mui/icons-material";
interface Props { interface Props {
question: AnyTypedQuizQuestion | UntypedQuizQuestion; question: AnyTypedQuizQuestion | UntypedQuizQuestion;
@ -30,18 +36,17 @@ interface Props {
draggableProps: DraggableProvidedDragHandleProps | null | undefined; draggableProps: DraggableProvidedDragHandleProps | null | undefined;
} }
export default function QuestionsPageCard({ export default function QuestionsPageCard({ question, questionIndex, draggableProps }: Props) {
question,
questionIndex,
draggableProps,
}: Props) {
const [open, setOpen] = useState<boolean>(false); const [open, setOpen] = useState<boolean>(false);
const anchorRef = useRef(null); const anchorRef = useRef(null);
const theme = useTheme();
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
const isMobile = useMediaQuery(theme.breakpoints.down(790));
const setTitle = useDebouncedCallback((title) => { const setTitle = useDebouncedCallback((title) => {
const updateQuestionFn = question.type === null ? updateUntypedQuestion : updateQuestion; const updateQuestionFn = question.type === null ? updateUntypedQuestion : updateQuestion;
updateQuestionFn(question.id, question => { updateQuestionFn(question.id, (question) => {
question.title = title; question.title = title;
}); });
}, 200); }, 200);
@ -65,15 +70,24 @@ export default function QuestionsPageCard({
<Box <Box
sx={{ sx={{
display: "flex", display: "flex",
p: 0,
flexDirection: "column", flexDirection: "column",
padding: 0, }}
>
<Box
sx={{
display: "flex",
alignItems: "center",
margin: "20px",
gap: "18px",
flexDirection: isMobile ? "column-reverse" : null,
}} }}
> >
<CustomTextField <CustomTextField
placeholder={`Заголовок ${questionIndex + 1} вопроса`} placeholder={`Заголовок ${questionIndex + 1} вопроса`}
text={question.title} text={question.title}
onChange={({ target }) => setTitle(target.value)} onChange={({ target }) => setTitle(target.value)}
sx={{ margin: "20px", width: "auto" }} sx={{ width: "100%" }}
InputProps={{ InputProps={{
startAdornment: ( startAdornment: (
<Box> <Box>
@ -94,19 +108,84 @@ export default function QuestionsPageCard({
/> />
</Box> </Box>
), ),
endAdornment: (
<Box {...draggableProps}>
{questionIndex !== 0 && (
<InputAdornment position="start">
<PointsIcon
style={{ color: "#9A9AAF", fontSize: "30px" }}
/>
</InputAdornment>
)}
</Box>
),
}} }}
/> />
<Box
sx={{
display: "flex",
alignItems: "center",
justifyContent: "space-between",
width: isMobile ? "100%" : "auto",
position: "relative",
}}
>
<Box
sx={{
flexDirection: isMobile ? "row-reverse" : null,
display: "flex",
alignItems: "center",
gap: "4px",
}}
>
<IconButton
sx={{ padding: "0", margin: "5px" }}
disableRipple
data-cy="expand-question"
onClick={() => toggleExpandQuestion(question.id)}
>
{question.expanded ? (
<ArrowDownIcon
style={{
width: "18px",
color: "#4D4D4D",
}}
/>
) : (
<ExpandLessIcon
sx={{
boxSizing: "border-box",
fill: theme.palette.brightPurple.main,
background: "#FFF",
borderRadius: "6px",
height: "30px",
width: "30px",
}}
/>
)}
</IconButton>
<Box
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
height: "30px",
width: "30px",
marginLeft: "3px",
borderRadius: "50%",
fontSize: "16px",
color: question.expanded ? theme.palette.brightPurple.main : "#FFF",
background: question.expanded ? "#EEE4FC" : theme.palette.brightPurple.main,
}}
>
{questionIndex + 1}
</Box>
</Box>
<IconButton
disableRipple
sx={{
padding: isMobile ? "0" : "0 5px",
right: isMobile ? "0" : null,
bottom: isMobile ? "0" : null,
}}
{...draggableProps}
>
<PointsIcon style={{ color: "#4D4D4D", fontSize: "30px" }} />
</IconButton>
</Box>
</Box>
{question.type === null ? ( {question.type === null ? (
<FormTypeQuestions question={question} /> <FormTypeQuestions question={question} />
) : ( ) : (
@ -123,41 +202,26 @@ const IconAndrom = (questionType: QuestionType | null) => {
case "variant": case "variant":
return <Answer color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />; return <Answer color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />;
case "images": case "images":
return ( return <OptionsPict color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />;
<OptionsPict color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />
);
case "varimg": case "varimg":
return ( return <OptionsAndPict color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />;
<OptionsAndPict
color="#9A9AAF"
sx={{ height: "22px", width: "20px" }}
/>
);
case "emoji": case "emoji":
return <Emoji color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />; return <Emoji color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />;
case "text": case "text":
return <Input color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />; return <Input color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />;
case "select": case "select":
return ( return <DropDown color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />;
<DropDown color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />
);
case "date": case "date":
return <Date color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />; return <Date color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />;
case "number": case "number":
return <Slider color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />; return <Slider color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />;
case "file": case "file":
return ( return <Download color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />;
<Download color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />
);
case "page": case "page":
return <Page color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />; return <Page color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />;
case "rating": case "rating":
return ( return <RatingIcon color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />;
<RatingIcon color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />
);
default: default:
return ( return <AnswerGroup color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />;
<AnswerGroup color="#9A9AAF" sx={{ height: "22px", width: "20px" }} />
);
} }
}; };

@ -5,10 +5,8 @@ import { DragDropContext, Droppable } from "react-beautiful-dnd";
import FormDraggableListItem from "./FormDraggableListItem"; import FormDraggableListItem from "./FormDraggableListItem";
import { useQuestions } from "@root/questions/hooks"; import { useQuestions } from "@root/questions/hooks";
export const FormDraggableList = () => { export const FormDraggableList = () => {
const { questions } = useQuestions();
const { questions } = useQuestions()
const onDragEnd = ({ destination, source }: DropResult) => { const onDragEnd = ({ destination, source }: DropResult) => {
if (destination) reorderQuestions(source.index, destination.index); if (destination) reorderQuestions(source.index, destination.index);
@ -20,11 +18,7 @@ export const FormDraggableList = () => {
{(provided) => ( {(provided) => (
<Box ref={provided.innerRef} {...provided.droppableProps}> <Box ref={provided.innerRef} {...provided.droppableProps}>
{questions?.map((question, index) => ( {questions?.map((question, index) => (
<FormDraggableListItem <FormDraggableListItem key={question.id} question={question} questionIndex={index} />
key={question.id}
question={question}
questionIndex={index}
/>
))} ))}
{provided.placeholder} {provided.placeholder}
</Box> </Box>

@ -8,7 +8,6 @@ import { FormDraggableList } from "./FormDraggableList";
import { collapseAllQuestions, createUntypedQuestion } from "@root/questions/actions"; import { collapseAllQuestions, createUntypedQuestion } from "@root/questions/actions";
import { useCurrentQuiz } from "@root/quizes/hooks"; import { useCurrentQuiz } from "@root/quizes/hooks";
export default function FormQuestionsPage() { export default function FormQuestionsPage() {
const theme = useTheme(); const theme = useTheme();
const quiz = useCurrentQuiz(); const quiz = useCurrentQuiz();
@ -73,9 +72,7 @@ export default function FormQuestionsPage() {
data-cy="create-question" data-cy="create-question"
> >
<AddAnswer color="#EEE4FC" /> <AddAnswer color="#EEE4FC" />
<Typography sx={{ color: "#9A9AAF" }}> <Typography sx={{ color: "#9A9AAF" }}>Добавить еще один вопрос</Typography>
Добавить еще один вопрос
</Typography>
</Box> </Box>
</Box> </Box>
<Box <Box

@ -12,10 +12,7 @@ import Slider from "../../../assets/icons/questionsPage/slider";
import { QuestionType } from "@model/question/question"; import { QuestionType } from "@model/question/question";
import { createTypedQuestion } from "@root/questions/actions"; import { createTypedQuestion } from "@root/questions/actions";
import type { import type { UntypedQuizQuestion } from "../../../model/questionTypes/shared";
UntypedQuizQuestion
} from "../../../model/questionTypes/shared";
type ButtonTypeQuestion = { type ButtonTypeQuestion = {
icon: JSX.Element; icon: JSX.Element;
@ -61,7 +58,6 @@ interface Props {
} }
export default function FormTypeQuestions({ question }: Props) { export default function FormTypeQuestions({ question }: Props) {
return ( return (
<Box> <Box>
<Box <Box
@ -72,10 +68,8 @@ export default function FormTypeQuestions({ question }: Props) {
margin: "20px", margin: "20px",
}} }}
> >
{(("page" in question) && question.page === 0 {("page" in question && question.page === 0 ? BUTTON_TYPE_QUESTIONS : BUTTON_TYPE_SHORT_QUESTIONS).map(
? BUTTON_TYPE_QUESTIONS ({ icon, title, value: questionType }) => (
: BUTTON_TYPE_SHORT_QUESTIONS
).map(({ icon, title, value: questionType }) => (
<QuestionsMiniButton <QuestionsMiniButton
key={title} key={title}
onClick={() => { onClick={() => {
@ -84,7 +78,8 @@ export default function FormTypeQuestions({ question }: Props) {
icon={icon} icon={icon}
text={title} text={title}
/> />
))} )
)}
</Box> </Box>
</Box> </Box>
); );

@ -1,12 +1,5 @@
import { useState, useEffect, useLayoutEffect, useRef } from "react" import { useState, useEffect, useLayoutEffect, useRef } from "react";
import { import { Box, Button, IconButton, Typography, useMediaQuery, useTheme } from "@mui/material";
Box,
Button,
IconButton,
Typography,
useMediaQuery,
useTheme,
} from "@mui/material";
import { collapseAllQuestions, createUntypedQuestion } from "@root/questions/actions"; import { collapseAllQuestions, createUntypedQuestion } from "@root/questions/actions";
import { decrementCurrentStep, incrementCurrentStep } from "@root/quizes/actions"; import { decrementCurrentStep, incrementCurrentStep } from "@root/quizes/actions";
import { useCurrentQuiz } from "@root/quizes/hooks"; import { useCurrentQuiz } from "@root/quizes/hooks";
@ -14,7 +7,7 @@ import QuizPreview from "@ui_kit/QuizPreview/QuizPreview";
import { createPortal } from "react-dom"; import { createPortal } from "react-dom";
import AddPlus from "../../assets/icons/questionsPage/addPlus"; import AddPlus from "../../assets/icons/questionsPage/addPlus";
import ArrowLeft from "../../assets/icons/questionsPage/arrowLeft"; import ArrowLeft from "../../assets/icons/questionsPage/arrowLeft";
import BranchingQuestions from "./BranchingModal/BranchingQuestionsModal" import BranchingQuestions from "./BranchingModal/BranchingQuestionsModal";
import { QuestionSwitchWindowTool } from "./QuestionSwitchWindowTool"; import { QuestionSwitchWindowTool } from "./QuestionSwitchWindowTool";
import { useQuestionsStore } from "@root/questions/store"; import { useQuestionsStore } from "@root/questions/store";
import { updateOpenBranchingPanel, updateEditSomeQuestion } from "@root/uiTools/actions"; import { updateOpenBranchingPanel, updateEditSomeQuestion } from "@root/uiTools/actions";
@ -26,14 +19,13 @@ export default function QuestionsPage() {
const isMobile = useMediaQuery(theme.breakpoints.down(660)); const isMobile = useMediaQuery(theme.breakpoints.down(660));
const quiz = useCurrentQuiz(); const quiz = useCurrentQuiz();
useLayoutEffect(() => { useLayoutEffect(() => {
updateOpenBranchingPanel(false) updateOpenBranchingPanel(false);
updateEditSomeQuestion() updateEditSomeQuestion();
},[]) }, []);
const ref = useRef() const ref = useRef();
if (!quiz) return null; if (!quiz) return null;
return ( return (
<> <>
<Box <Box
@ -47,8 +39,7 @@ export default function QuestionsPage() {
margin: "60px 0 40px 0", margin: "60px 0 40px 0",
}} }}
> >
<Typography variant={"h5"}>{ <Typography variant={"h5"}>{quiz.name ? quiz.name : "Заголовок квиза"}</Typography>
quiz.name ? quiz.name : "Заголовок квиза" }</Typography>
<Button <Button
sx={{ sx={{
display: openBranchingPanel ? "none" : "flex", display: openBranchingPanel ? "none" : "flex",
@ -64,7 +55,7 @@ export default function QuestionsPage() {
Свернуть всё Свернуть всё
</Button> </Button>
</Box> </Box>
<QuestionSwitchWindowTool/> <QuestionSwitchWindowTool />
<Box <Box
sx={{ sx={{
display: "flex", display: "flex",
@ -86,7 +77,6 @@ export default function QuestionsPage() {
<AddPlus /> <AddPlus />
</IconButton> </IconButton>
<Box sx={{ display: "flex", gap: "8px", marginLeft: "auto" }}> <Box sx={{ display: "flex", gap: "8px", marginLeft: "auto" }}>
<Button <Button
variant="outlined" variant="outlined"
@ -112,7 +102,7 @@ export default function QuestionsPage() {
</Box> </Box>
</Box> </Box>
{createPortal(<QuizPreview />, document.body)} {createPortal(<QuizPreview />, document.body)}
{openedModalSettingsId !== null && <BranchingQuestions/>} {openedModalSettingsId !== null && <BranchingQuestions />}
</> </>
); );
} }

@ -12,13 +12,11 @@ import UploadFile from "./UploadFile/UploadFile";
import AnswerOptions from "./answerOptions/AnswerOptions"; import AnswerOptions from "./answerOptions/AnswerOptions";
import { notReachable } from "../../utils/notReachable"; import { notReachable } from "../../utils/notReachable";
interface Props { interface Props {
question: AnyTypedQuizQuestion; question: AnyTypedQuizQuestion;
} }
export default function SwitchQuestionsPage({ question }: Props) { export default function SwitchQuestionsPage({ question }: Props) {
switch (question.type) { switch (question.type) {
case "variant": case "variant":
return <AnswerOptions question={question} />; return <AnswerOptions question={question} />;
@ -54,6 +52,6 @@ export default function SwitchQuestionsPage({ question }: Props) {
return <RatingOptions question={question} />; return <RatingOptions question={question} />;
default: default:
notReachable(question) notReachable(question);
} }
} }