fix: questions store

This commit is contained in:
IlyaDoronin 2023-10-04 12:07:59 +03:00
parent ade9e25d5f
commit f5867f30ce
31 changed files with 178 additions and 305 deletions

@ -10,6 +10,16 @@ export const QUIZ_QUESTION_BASE: Omit<QuizQuestionBase, "id"> = {
text: "", text: "",
video: "", video: "",
}, },
rule: {
or: true,
show: true,
reqs: [
{
id: "",
vars: [],
},
],
},
back: "", back: "",
autofill: false, autofill: false,
}, },

@ -13,19 +13,5 @@ export const QUIZ_QUESTION_DATE: Omit<QuizQuestionDate, "id"> = {
type: "calendar", type: "calendar",
dateRange: false, dateRange: false,
time: false, time: false,
hint: {
text: "",
video: "",
},
rule: {
or: true,
show: true,
reqs: [
{
id: "",
vars: [],
},
],
},
}, },
}; };

@ -19,19 +19,5 @@ export const QUIZ_QUESTION_EMOJI: Omit<QuizQuestionEmoji, "id"> = {
extendedText: "", extendedText: "",
}, },
], ],
hint: {
text: "",
video: "",
},
rule: {
or: true,
show: true,
reqs: [
{
id: "",
vars: [],
},
],
},
}, },
}; };

@ -11,19 +11,5 @@ export const QUIZ_QUESTION_FILE: Omit<QuizQuestionFile, "id"> = {
innerNameCheck: false, innerNameCheck: false,
innerName: "", innerName: "",
type: "all", type: "all",
hint: {
text: "",
video: "",
},
rule: {
or: true,
show: true,
reqs: [
{
id: "",
vars: [],
},
],
},
}, },
}; };

@ -22,20 +22,6 @@ export const QUIZ_QUESTION_IMAGES: Omit<QuizQuestionImages, "id"> = {
extendedText: "", extendedText: "",
}, },
], ],
hint: {
text: "",
video: "",
},
rule: {
or: true,
show: true,
reqs: [
{
id: "",
vars: [],
},
],
},
largeCheck: false, largeCheck: false,
}, },
}; };

@ -16,20 +16,6 @@ export const QUIZ_QUESTION_NUMBER: Omit<QuizQuestionNumber, "id"> = {
steps: 5, steps: 5,
start: 50, start: 50,
chooseRange: false, chooseRange: false,
hint: {
text: "",
video: "",
},
rule: {
or: true,
show: true,
reqs: [
{
id: "",
vars: [],
},
],
},
form: "star", form: "star",
}, },
}; };

@ -11,19 +11,5 @@ export const QUIZ_QUESTION_PAGE: Omit<QuizQuestionPage, "id"> = {
innerName: "", innerName: "",
text: "", text: "",
video: "", video: "",
hint: {
text: "",
video: "",
},
rule: {
or: true,
show: true,
reqs: [
{
id: "",
vars: [],
},
],
},
}, },
}; };

@ -14,19 +14,5 @@ export const QUIZ_QUESTION_RATING: Omit<QuizQuestionRating, "id"> = {
ratingExpanded: false, ratingExpanded: false,
ratingDescription: "", ratingDescription: "",
form: "", form: "",
hint: {
text: "",
video: "",
},
rule: {
or: true,
show: true,
reqs: [
{
id: "",
vars: [],
},
],
},
}, },
}; };

@ -12,19 +12,6 @@ export const QUIZ_QUESTION_SELECT: Omit<QuizQuestionSelect, "id"> = {
innerNameCheck: false, innerNameCheck: false,
innerName: "", innerName: "",
default: "", default: "",
hint: { variants: [{ answer: "", hints: "", extendedText: "" }],
text: "",
video: "",
},
rule: {
or: true,
show: true,
reqs: [
{
id: "",
vars: [],
},
],
},
}, },
}; };

@ -12,19 +12,5 @@ export const QUIZ_QUESTION_TEXT: Omit<QuizQuestionText, "id"> = {
innerName: "", innerName: "",
required: false, required: false,
answerType: "single", answerType: "single",
hint: {
text: "",
video: "",
},
rule: {
or: true,
show: true,
reqs: [
{
id: "",
vars: [],
},
],
},
}, },
}; };

@ -14,19 +14,5 @@ export const QUIZ_QUESTION_VARIANT: Omit<QuizQuestionVariant, "id"> = {
required: false, required: false,
innerName: "", innerName: "",
variants: [{ answer: "", hints: "", extendedText: "" }], variants: [{ answer: "", hints: "", extendedText: "" }],
hint: {
text: "",
video: "",
},
rule: {
or: true,
show: true,
reqs: [
{
id: "",
vars: [],
},
],
},
}, },
}; };

@ -12,20 +12,6 @@ export const QUIZ_QUESTION_VARIMG: Omit<QuizQuestionVarImg, "id"> = {
innerName: "", innerName: "",
required: false, required: false,
variants: [{ answer: "", hints: "", extendedText: "" }], variants: [{ answer: "", hints: "", extendedText: "" }],
hint: {
text: "",
video: "",
},
rule: {
or: true,
show: true,
reqs: [
{
id: "",
vars: [],
},
],
},
largeCheck: false, largeCheck: false,
replText: "", replText: "",
}, },

@ -1,7 +1,7 @@
import type { import type {
QuizQuestionBase, QuizQuestionBase,
QuizQuestionBranchingRules, QuestionHint,
QuizQuestionHint, QuestionBranchingRule,
} from "./shared"; } from "./shared";
export interface QuizQuestionDate extends QuizQuestionBase { export interface QuizQuestionDate extends QuizQuestionBase {
@ -16,8 +16,8 @@ export interface QuizQuestionDate extends QuizQuestionBase {
type: "calendar" | "mask"; type: "calendar" | "mask";
dateRange: boolean; dateRange: boolean;
time: boolean; time: boolean;
hint: QuizQuestionHint; hint: QuestionHint;
rule: QuizQuestionBranchingRules; rule: QuestionBranchingRule;
back: string; back: string;
autofill: boolean; autofill: boolean;
}; };

@ -1,8 +1,8 @@
import type { import type {
QuizQuestionBase, QuizQuestionBase,
QuizQuestionBranchingRules, QuestionVariant,
QuizQuestionHint, QuestionHint,
Variant, QuestionBranchingRule,
} from "./shared"; } from "./shared";
export interface QuizQuestionEmoji extends QuizQuestionBase { export interface QuizQuestionEmoji extends QuizQuestionBase {
@ -18,9 +18,9 @@ export interface QuizQuestionEmoji extends QuizQuestionBase {
innerName: string; innerName: string;
/** Чекбокс "Необязательный вопрос" */ /** Чекбокс "Необязательный вопрос" */
required: boolean; required: boolean;
variants: Variant[]; variants: QuestionVariant[];
hint: QuizQuestionHint; hint: QuestionHint;
rule: QuizQuestionBranchingRules; rule: QuestionBranchingRule;
back: string; back: string;
autofill: boolean; autofill: boolean;
}; };

@ -1,7 +1,7 @@
import type { import type {
QuizQuestionBase, QuizQuestionBase,
QuizQuestionBranchingRules, QuestionHint,
QuizQuestionHint, QuestionBranchingRule,
} from "./shared"; } from "./shared";
export const uploadFileTypesMap = { export const uploadFileTypesMap = {
@ -26,8 +26,8 @@ export interface QuizQuestionFile extends QuizQuestionBase {
/** Чекбокс "Автозаполнение адреса" */ /** Чекбокс "Автозаполнение адреса" */
autofill: boolean; autofill: boolean;
type: UploadFileType; type: UploadFileType;
hint: QuizQuestionHint; hint: QuestionHint;
rule: QuizQuestionBranchingRules; rule: QuestionBranchingRule;
back: string; back: string;
}; };
} }

@ -1,8 +1,8 @@
import type { import type {
QuizQuestionBase, QuizQuestionBase,
QuizQuestionBranchingRules, QuestionVariant,
QuizQuestionHint, QuestionHint,
Variant, QuestionBranchingRule,
} from "./shared"; } from "./shared";
export interface QuizQuestionImages extends QuizQuestionBase { export interface QuizQuestionImages extends QuizQuestionBase {
@ -25,9 +25,9 @@ export interface QuizQuestionImages extends QuizQuestionBase {
/** Чекбокс "Необязательный вопрос" */ /** Чекбокс "Необязательный вопрос" */
required: boolean; required: boolean;
/** Варианты (картинки) */ /** Варианты (картинки) */
variants: Variant[]; variants: QuestionVariant[];
hint: QuizQuestionHint; hint: QuestionHint;
rule: QuizQuestionBranchingRules; rule: QuestionBranchingRule;
back: string; back: string;
autofill: boolean; autofill: boolean;
largeCheck: boolean; largeCheck: boolean;

@ -1,7 +1,7 @@
import type { import type {
QuizQuestionBase, QuizQuestionBase,
QuizQuestionBranchingRules, QuestionHint,
QuizQuestionHint, QuestionBranchingRule,
} from "./shared"; } from "./shared";
export interface QuizQuestionNumber extends QuizQuestionBase { export interface QuizQuestionNumber extends QuizQuestionBase {
@ -24,8 +24,8 @@ export interface QuizQuestionNumber extends QuizQuestionBase {
steps: number; steps: number;
/** Чекбокс "Выбор диапазона (два ползунка)" */ /** Чекбокс "Выбор диапазона (два ползунка)" */
chooseRange: boolean; chooseRange: boolean;
hint: QuizQuestionHint; hint: QuestionHint;
rule: QuizQuestionBranchingRules; rule: QuestionBranchingRule;
back: string; back: string;
autofill: boolean; autofill: boolean;
form: "star" | "trophie" | "flag" | "heart" | "like" | "bubble" | "hashtag"; form: "star" | "trophie" | "flag" | "heart" | "like" | "bubble" | "hashtag";

@ -1,7 +1,7 @@
import type { import type {
QuizQuestionBase, QuizQuestionBase,
QuizQuestionBranchingRules, QuestionHint,
QuizQuestionHint, QuestionBranchingRule,
} from "./shared"; } from "./shared";
export interface QuizQuestionPage extends QuizQuestionBase { export interface QuizQuestionPage extends QuizQuestionBase {
@ -13,8 +13,8 @@ export interface QuizQuestionPage extends QuizQuestionBase {
innerName: string; innerName: string;
text: string; text: string;
video: string; video: string;
hint: QuizQuestionHint; hint: QuestionHint;
rule: QuizQuestionBranchingRules; rule: QuestionBranchingRule;
back: string; back: string;
autofill: boolean; autofill: boolean;
}; };

@ -1,7 +1,7 @@
import type { import type {
QuizQuestionBase, QuizQuestionBase,
QuizQuestionBranchingRules, QuestionHint,
QuizQuestionHint, QuestionBranchingRule,
} from "./shared"; } from "./shared";
export interface QuizQuestionRating extends QuizQuestionBase { export interface QuizQuestionRating extends QuizQuestionBase {
@ -18,8 +18,8 @@ export interface QuizQuestionRating extends QuizQuestionBase {
ratingDescription: string; ratingDescription: string;
/** Форма иконки */ /** Форма иконки */
form: string; form: string;
hint: QuizQuestionHint; hint: QuestionHint;
rule: QuizQuestionBranchingRules; rule: QuestionBranchingRule;
back: string; back: string;
autofill: boolean; autofill: boolean;
}; };

@ -1,8 +1,8 @@
import type { import type {
QuizQuestionBase, QuizQuestionBase,
QuizQuestionBranchingRules, QuestionVariant,
QuizQuestionHint, QuestionHint,
Variant, QuestionBranchingRule,
} from "./shared"; } from "./shared";
export interface QuizQuestionSelect extends QuizQuestionBase { export interface QuizQuestionSelect extends QuizQuestionBase {
@ -18,9 +18,9 @@ export interface QuizQuestionSelect extends QuizQuestionBase {
innerName: string; innerName: string;
/** Поле "Текст в выпадающем списке" */ /** Поле "Текст в выпадающем списке" */
default: string; default: string;
hint: QuizQuestionHint; variants: QuestionVariant[];
rule: QuizQuestionBranchingRules; rule: QuestionBranchingRule;
variants: Variant[]; hint: QuestionHint;
back: string; back: string;
autofill: boolean; autofill: boolean;
}; };

@ -10,7 +10,7 @@ import type { QuizQuestionText } from "./text";
import type { QuizQuestionVariant } from "./variant"; import type { QuizQuestionVariant } from "./variant";
import type { QuizQuestionVarImg } from "./varimg"; import type { QuizQuestionVarImg } from "./varimg";
export interface QuizQuestionBranchingRules { export interface QuestionBranchingRule {
/** Радиокнопка "Все условия обязательны" */ /** Радиокнопка "Все условия обязательны" */
or: boolean; or: boolean;
show: boolean; show: boolean;
@ -21,24 +21,22 @@ export interface QuizQuestionBranchingRules {
}[]; }[];
} }
export interface QuizQuestionHint { export interface QuestionHint {
/** Текст подсказки */ /** Текст подсказки */
text: string; text: string;
/** URL видео подсказки */ /** URL видео подсказки */
video: string; video: string;
} }
export type Variant = { export type QuestionVariant = {
/** Текст */
answer: string; answer: string;
/** Текст подсказки */
hints: string; hints: string;
/** Дополнительное поле для текста, emoji, ссылки на картинку */
extendedText: string; extendedText: string;
}; };
export type Hint = {
text: string;
video: string;
};
export interface QuizQuestionBase { export interface QuizQuestionBase {
id: number; id: number;
title: string; title: string;
@ -46,7 +44,8 @@ export interface QuizQuestionBase {
expanded: boolean; expanded: boolean;
required: boolean; required: boolean;
content: { content: {
hint: Hint; hint: QuestionHint;
rule: QuestionBranchingRule;
back: string; back: string;
autofill: boolean; autofill: boolean;
}; };

@ -1,7 +1,7 @@
import type { import type {
QuizQuestionBase, QuizQuestionBase,
QuizQuestionBranchingRules, QuestionHint,
QuizQuestionHint, QuestionBranchingRule,
} from "./shared"; } from "./shared";
export interface QuizQuestionText extends QuizQuestionBase { export interface QuizQuestionText extends QuizQuestionBase {
@ -17,8 +17,8 @@ export interface QuizQuestionText extends QuizQuestionBase {
/** Чекбокс "Автозаполнение адреса" */ /** Чекбокс "Автозаполнение адреса" */
autofill: boolean; autofill: boolean;
answerType: "single" | "multi" | "number"; answerType: "single" | "multi" | "number";
hint: QuizQuestionHint; hint: QuestionHint;
rule: QuizQuestionBranchingRules; rule: QuestionBranchingRule;
back: string; back: string;
}; };
} }

@ -1,8 +1,8 @@
import type { import type {
QuizQuestionBase, QuizQuestionBase,
QuizQuestionBranchingRules, QuestionVariant,
QuizQuestionHint, QuestionHint,
Variant, QuestionBranchingRule,
} from "./shared"; } from "./shared";
export interface QuizQuestionVariant extends QuizQuestionBase { export interface QuizQuestionVariant extends QuizQuestionBase {
@ -21,9 +21,9 @@ export interface QuizQuestionVariant extends QuizQuestionBase {
/** Поле "Внутреннее название вопроса" */ /** Поле "Внутреннее название вопроса" */
innerName: string; innerName: string;
/** Варианты ответов */ /** Варианты ответов */
variants: Variant[]; variants: QuestionVariant[];
hint: QuizQuestionHint; hint: QuestionHint;
rule: QuizQuestionBranchingRules; rule: QuestionBranchingRule;
back: string; back: string;
autofill: boolean; autofill: boolean;
}; };

@ -1,8 +1,8 @@
import type { import type {
QuizQuestionBase, QuizQuestionBase,
QuizQuestionBranchingRules, QuestionVariant,
QuizQuestionHint, QuestionHint,
Variant, QuestionBranchingRule,
} from "./shared"; } from "./shared";
export interface QuizQuestionVarImg extends QuizQuestionBase { export interface QuizQuestionVarImg extends QuizQuestionBase {
@ -16,9 +16,9 @@ export interface QuizQuestionVarImg extends QuizQuestionBase {
innerName: string; innerName: string;
/** Чекбокс "Необязательный вопрос" */ /** Чекбокс "Необязательный вопрос" */
required: boolean; required: boolean;
variants: Variant[]; variants: QuestionVariant[];
hint: QuizQuestionHint; hint: QuestionHint;
rule: QuizQuestionBranchingRules; rule: QuestionBranchingRule;
back: string; back: string;
autofill: boolean; autofill: boolean;
largeCheck: boolean; largeCheck: boolean;

@ -23,13 +23,14 @@ import TextareaAutosize from "@mui/base/TextareaAutosize";
import AddEmoji from "../../../assets/icons/questionsPage/addEmoji"; import AddEmoji from "../../../assets/icons/questionsPage/addEmoji";
import type { ChangeEvent, KeyboardEvent } from "react"; import type { ChangeEvent, KeyboardEvent } from "react";
import type { Variants } from "@root/questions"; import type { QuizQuestionVariant } from "../../../model/questionTypes/variant";
import type { QuestionVariant } from "../../../model/questionTypes/shared";
type AnswerItemProps = { type AnswerItemProps = {
index: number; index: number;
totalIndex: number; totalIndex: number;
variants: Variants[]; variants: QuestionVariant[];
variant: Variants; variant: QuestionVariant;
emoji: boolean; emoji: boolean;
}; };
@ -46,13 +47,14 @@ export const AnswerItem = ({
const theme = useTheme(); const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down(790)); const isMobile = useMediaQuery(theme.breakpoints.down(790));
const anchorElement = useRef(); const anchorElement = useRef();
const question = listQuestions[quizId][totalIndex] as QuizQuestionVariant;
const debounced = useDebouncedCallback((value) => { const debounced = useDebouncedCallback((value) => {
const answerNew = variants.slice(); const answerNew = variants.slice();
answerNew[index].answer = value; answerNew[index].answer = value;
updateQuestionsList(quizId, totalIndex, { updateQuestionsList(quizId, totalIndex, {
content: { content: {
...listQuestions[quizId][totalIndex].content, ...question.content,
variants: answerNew, variants: answerNew,
}, },
}); });
@ -72,13 +74,10 @@ export const AnswerItem = ({
const addNewAnswer = () => { const addNewAnswer = () => {
const answerNew = variants.slice(); const answerNew = variants.slice();
answerNew.push({ answer: "", hints: "", emoji: "" }); answerNew.push({ answer: "", hints: "", extendedText: "" });
updateQuestionsList(quizId, totalIndex, { updateQuestionsList(quizId, totalIndex, {
content: { content: { ...question.content, variants: answerNew },
...listQuestions[quizId][totalIndex].content,
variants: answerNew,
},
}); });
}; };
@ -87,10 +86,7 @@ export const AnswerItem = ({
answerNew.splice(index, 1); answerNew.splice(index, 1);
updateQuestionsList(quizId, totalIndex, { updateQuestionsList(quizId, totalIndex, {
content: { content: { ...question.content, variants: answerNew },
...listQuestions[quizId][totalIndex].content,
variants: answerNew,
},
}); });
}; };
@ -99,10 +95,7 @@ export const AnswerItem = ({
answerNew[index].hints = event.target.value; answerNew[index].hints = event.target.value;
updateQuestionsList(quizId, totalIndex, { updateQuestionsList(quizId, totalIndex, {
content: { content: { ...question.content, variants: answerNew },
...listQuestions[quizId][totalIndex].content,
variants: answerNew,
},
}); });
}; };
@ -121,13 +114,10 @@ export const AnswerItem = ({
fullWidth fullWidth
focused={false} focused={false}
placeholder={"Добавьте ответ"} placeholder={"Добавьте ответ"}
multiline={listQuestions[quizId][totalIndex].content.largeCheck} multiline={question.content.largeCheck}
onChange={({ target }) => debounced(target.value)} onChange={({ target }) => debounced(target.value)}
onKeyDown={(event: KeyboardEvent<HTMLInputElement>) => { onKeyDown={(event: KeyboardEvent<HTMLInputElement>) => {
if ( if (event.code === "Enter" && !question.content.largeCheck) {
event.code === "Enter" &&
!listQuestions[quizId][totalIndex].content.largeCheck
) {
addNewAnswer(); addNewAnswer();
} }
}} }}
@ -151,8 +141,10 @@ export const AnswerItem = ({
gap: "5px", gap: "5px",
}} }}
> >
{variant.emoji && ( {variant.extendedText && (
<Box sx={{ width: "30px" }}>{variant.emoji}</Box> <Box sx={{ width: "30px" }}>
{variant.extendedText}
</Box>
)} )}
<AddEmoji /> <AddEmoji />
</Box> </Box>
@ -178,7 +170,7 @@ export const AnswerItem = ({
cloneVariants[index] = { cloneVariants[index] = {
...cloneVariants[index], ...cloneVariants[index],
emoji: native, extendedText: native,
}; };
updateQuestionsList(quizId, totalIndex, { updateQuestionsList(quizId, totalIndex, {
@ -223,9 +215,15 @@ export const AnswerItem = ({
}} }}
sx={{ sx={{
"& .MuiInputBase-root": { "& .MuiInputBase-root": {
padding: emoji ? "5px 13.5px" : "13.5px", padding: emoji ? "5px 13px" : "13px",
borderRadius: "10px", borderRadius: "10px",
background: "#ffffff", background: "#ffffff",
"& input.MuiInputBase-input": {
height: "22px",
},
"& textarea.MuiInputBase-input": {
marginTop: "1px",
},
}, },
}} }}
inputProps={{ inputProps={{

@ -9,10 +9,10 @@ import { updateVariants } from "@root/questions";
import { reorder } from "./helper"; import { reorder } from "./helper";
import type { DropResult } from "react-beautiful-dnd"; import type { DropResult } from "react-beautiful-dnd";
import type { Variants } from "@root/questions"; import type { QuestionVariant } from "../../../model/questionTypes/shared";
type AnswerDraggableListProps = { type AnswerDraggableListProps = {
variants: Variants[]; variants: QuestionVariant[];
totalIndex: number; totalIndex: number;
emoji?: boolean; emoji?: boolean;
}; };

@ -13,6 +13,8 @@ import InfoIcon from "../../../assets/icons/InfoIcon";
import SelectableButton from "@ui_kit/SelectableButton"; import SelectableButton from "@ui_kit/SelectableButton";
import { questionStore, updateQuestionsList } from "@root/questions"; import { questionStore, updateQuestionsList } from "@root/questions";
import type { QuizQuestionDate } from "../../../model/questionTypes/date";
interface Props { interface Props {
totalIndex: number; totalIndex: number;
} }
@ -23,16 +25,17 @@ export default function DataOptions({ totalIndex }: Props) {
const { listQuestions } = questionStore(); const { listQuestions } = questionStore();
const theme = useTheme(); const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down(790)); const isMobile = useMediaQuery(theme.breakpoints.down(790));
const question = listQuestions[quizId][totalIndex] as QuizQuestionDate;
const SSHC = (data: string) => { const SSHC = (data: string) => {
setSwitchState(data); setSwitchState(data);
}; };
useEffect(() => { useEffect(() => {
if (listQuestions[quizId][totalIndex].content.type !== "mask") { if (question.content.type !== "mask") {
const clonContent = listQuestions[quizId][totalIndex].content; updateQuestionsList(quizId, totalIndex, {
clonContent.type = "calendar"; content: { ...question.content, type: "calendar" },
updateQuestionsList(quizId, totalIndex, { content: clonContent }); });
} }
}, []); }, []);
@ -50,26 +53,22 @@ export default function DataOptions({ totalIndex }: Props) {
> >
<Box sx={{ gap: "10px", display: "flex", flexWrap: "wrap" }}> <Box sx={{ gap: "10px", display: "flex", flexWrap: "wrap" }}>
<SelectableButton <SelectableButton
isSelected={ isSelected={question.content.type === "calendar"}
listQuestions[quizId][totalIndex].content.type === "calendar"
}
onClick={() => { onClick={() => {
const clonContent = listQuestions[quizId][totalIndex].content; updateQuestionsList(quizId, totalIndex, {
clonContent.type = "calendar"; content: { ...question.content, type: "calendar" },
updateQuestionsList(quizId, totalIndex, { content: clonContent }); });
}} }}
sx={{ maxWidth: "257px", height: "48px", whiteSpace: "nowrap" }} sx={{ maxWidth: "257px", height: "48px", whiteSpace: "nowrap" }}
> >
Использовать календарь Использовать календарь
</SelectableButton> </SelectableButton>
<SelectableButton <SelectableButton
isSelected={ isSelected={question.content.type === "mask"}
listQuestions[quizId][totalIndex].content.type === "mask"
}
onClick={() => { onClick={() => {
const clonContent = listQuestions[quizId][totalIndex].content; updateQuestionsList(quizId, totalIndex, {
clonContent.type = "mask"; content: { ...question.content, type: "mask" },
updateQuestionsList(quizId, totalIndex, { content: clonContent }); });
}} }}
sx={{ maxWidth: "211px", height: "48px", whiteSpace: "nowrap" }} sx={{ maxWidth: "211px", height: "48px", whiteSpace: "nowrap" }}
> >

@ -17,6 +17,8 @@ import {
} from "@root/questions"; } from "@root/questions";
import { DraggableList } from "./DraggableList"; import { DraggableList } from "./DraggableList";
import type { AnyQuizQuestion } from "../../model/questionTypes/shared";
export default function QuestionsPage() { export default function QuestionsPage() {
const { listQuizes, updateQuizesList } = quizStore(); const { listQuizes, updateQuizesList } = quizStore();
const quizId = Number(useParams().quizId); const quizId = Number(useParams().quizId);
@ -32,7 +34,10 @@ export default function QuestionsPage() {
const collapseEverything = () => { const collapseEverything = () => {
listQuestions[quizId].forEach((item, index) => { listQuestions[quizId].forEach((item, index) => {
updateQuestionsList(quizId, index, { ...item, expanded: false }); updateQuestionsList<AnyQuizQuestion>(quizId, index, {
...item,
expanded: false,
});
}); });
}; };

@ -12,6 +12,8 @@ import InfoIcon from "../../../assets/icons/InfoIcon";
import CustomTextField from "@ui_kit/CustomTextField"; import CustomTextField from "@ui_kit/CustomTextField";
import { questionStore, updateQuestionsList } from "@root/questions"; import { questionStore, updateQuestionsList } from "@root/questions";
import type { QuizQuestionVariant } from "../../../model/questionTypes/variant";
interface Props { interface Props {
totalIndex: number; totalIndex: number;
} }
@ -22,10 +24,11 @@ export default function ResponseSettings({ totalIndex }: Props) {
const theme = useTheme(); const theme = useTheme();
const isTablet = useMediaQuery(theme.breakpoints.down(900)); const isTablet = useMediaQuery(theme.breakpoints.down(900));
const isMobile = useMediaQuery(theme.breakpoints.down(790)); const isMobile = useMediaQuery(theme.breakpoints.down(790));
const question = listQuestions[quizId][totalIndex] as QuizQuestionVariant;
const debounced = useDebouncedCallback((value) => { const debounced = useDebouncedCallback((value) => {
let clonContent = listQuestions[quizId][totalIndex].content; updateQuestionsList(quizId, totalIndex, {
clonContent.innerName = value; content: { ...question.content, innerName: value },
updateQuestionsList(quizId, totalIndex, { content: clonContent }); });
}, 1000); }, 1000);
return ( return (
@ -37,41 +40,47 @@ export default function ResponseSettings({ totalIndex }: Props) {
marginRight: isMobile ? "0" : "30px", marginRight: isMobile ? "0" : "30px",
}} }}
> >
<Box sx={{ pt: "20px", pb: "20px", pl: "20px", display: "flex", flexDirection: "column" }}> <Box
sx={{
pt: "20px",
pb: "20px",
pl: "20px",
display: "flex",
flexDirection: "column",
}}
>
<Typography>Настройки ответов</Typography> <Typography>Настройки ответов</Typography>
<CustomCheckbox <CustomCheckbox
sx={{ mr: isMobile ? "0px" : "16px" }} sx={{ mr: isMobile ? "0px" : "16px" }}
label={"Длинный текстовый ответ"} label={"Длинный текстовый ответ"}
checked={listQuestions[quizId][totalIndex].content.largeCheck} checked={question.content.largeCheck}
handleChange={(e) => { handleChange={({ target }) => {
let clonContent = listQuestions[quizId][totalIndex].content; updateQuestionsList(quizId, totalIndex, {
clonContent.largeCheck = e.target.checked; content: {
...question.content,
if (!e.target.checked) { largeCheck: target.checked,
clonContent.large = ""; },
} });
updateQuestionsList(quizId, totalIndex, { content: clonContent });
}} }}
/> />
<CustomCheckbox <CustomCheckbox
sx={{ mr: isMobile ? "0px" : "16px" }} sx={{ mr: isMobile ? "0px" : "16px" }}
label={"Можно несколько"} label={"Можно несколько"}
checked={listQuestions[quizId][totalIndex].content.multi} checked={question.content.multi}
handleChange={(e) => { handleChange={({ target }) => {
let clonContent = listQuestions[quizId][totalIndex].content; updateQuestionsList(quizId, totalIndex, {
clonContent.multi = e.target.checked; content: { ...question.content, multi: target.checked },
updateQuestionsList(quizId, totalIndex, { content: clonContent }); });
}} }}
/> />
<CustomCheckbox <CustomCheckbox
sx={{ mr: isMobile ? "0px" : "16px" }} sx={{ mr: isMobile ? "0px" : "16px" }}
label={'Вариант "свой ответ"'} label={'Вариант "свой ответ"'}
checked={listQuestions[quizId][totalIndex].content.own} checked={question.content.own}
handleChange={(e) => { handleChange={({ target }) => {
let clonContent = listQuestions[quizId][totalIndex].content; updateQuestionsList(quizId, totalIndex, {
clonContent.own = e.target.checked; content: { ...question.content, own: target.checked },
updateQuestionsList(quizId, totalIndex, { content: clonContent }); });
}} }}
/> />
</Box> </Box>
@ -80,28 +89,31 @@ export default function ResponseSettings({ totalIndex }: Props) {
<CustomCheckbox <CustomCheckbox
sx={{ mr: isMobile ? "0px" : "16px" }} sx={{ mr: isMobile ? "0px" : "16px" }}
label={"Необязательный вопрос"} label={"Необязательный вопрос"}
checked={!listQuestions[quizId][totalIndex].required} checked={!question.required}
handleChange={(e) => { handleChange={({ target }) => {
updateQuestionsList(quizId, totalIndex, { updateQuestionsList(quizId, totalIndex, {
required: !e.target.checked, required: !target.checked,
}); });
}} }}
/> />
<Box sx={{ width: isMobile ? "90%" : "auto", display: "flex", alignItems: "center" }}> <Box
sx={{
width: isMobile ? "90%" : "auto",
display: "flex",
alignItems: "center",
}}
>
<CustomCheckbox <CustomCheckbox
sx={{ mr: isMobile ? "0px" : "16px" }} sx={{ mr: isMobile ? "0px" : "16px" }}
label={"Внутреннее название вопроса"} label={"Внутреннее название вопроса"}
checked={listQuestions[quizId][totalIndex].content.innerNameCheck} checked={question.content.innerNameCheck}
handleChange={(e) => { handleChange={({ target }) => {
let clonContent = listQuestions[quizId][totalIndex].content;
clonContent.innerNameCheck = e.target.checked;
if (!e.target.checked) {
clonContent.innerName = "";
}
updateQuestionsList(quizId, totalIndex, { updateQuestionsList(quizId, totalIndex, {
content: clonContent, content: {
...question.content,
innerNameCheck: target.checked,
innerName: target.checked ? question.content.innerName : "",
},
}); });
}} }}
/> />
@ -114,11 +126,11 @@ export default function ResponseSettings({ totalIndex }: Props) {
</Box> </Box>
</Tooltip> </Tooltip>
</Box> </Box>
{listQuestions[quizId][totalIndex].content.innerNameCheck && ( {question.content.innerNameCheck && (
<CustomTextField <CustomTextField
sx={{ mr: isMobile ? "0px" : "16px" }} sx={{ mr: isMobile ? "0px" : "16px" }}
placeholder={"Развёрнутое описание вопроса"} placeholder={"Развёрнутое описание вопроса"}
text={listQuestions[quizId][totalIndex].content.innerName} text={question.content.innerName}
onChange={({ target }) => debounced(target.value)} onChange={({ target }) => debounced(target.value)}
/> />
)} )}

@ -26,6 +26,8 @@ import RadioCheck from "@ui_kit/RadioCheck";
import RadioIcon from "@ui_kit/RadioIcon"; import RadioIcon from "@ui_kit/RadioIcon";
import InfoIcon from "@icons/Info"; import InfoIcon from "@icons/Info";
import type { QuizQuestionBase } from "../../model/questionTypes/shared";
type BranchingQuestionsProps = { type BranchingQuestionsProps = {
totalIndex: number; totalIndex: number;
}; };
@ -47,6 +49,7 @@ export default function BranchingQuestions({
const { openedModalSettings, listQuestions } = questionStore(); const { openedModalSettings, listQuestions } = questionStore();
const theme = useTheme(); const theme = useTheme();
const titleRef = useRef<HTMLDivElement>(null); const titleRef = useRef<HTMLDivElement>(null);
const question = listQuestions[quizId][totalIndex] as QuizQuestionBase;
useEffect(() => { useEffect(() => {
setTitleInputWidth(titleRef.current?.offsetWidth || 0); setTitleInputWidth(titleRef.current?.offsetWidth || 0);

@ -9,7 +9,7 @@ import { QuizQuestionVarImg } from "../model/questionTypes/varimg";
import type { import type {
AnyQuizQuestion, AnyQuizQuestion,
QuizQuestionType, QuizQuestionType,
Variant, QuestionVariant,
} from "../model/questionTypes/shared"; } from "../model/questionTypes/shared";
import { QUIZ_QUESTION_BASE } from "../constants/base"; import { QUIZ_QUESTION_BASE } from "../constants/base";
@ -50,7 +50,7 @@ export interface Question {
deleted: true; deleted: true;
page: number; page: number;
content: { content: {
variants: Variant[]; variants: QuestionVariant[];
hint: Hint; hint: Hint;
rule: Rule; rule: Rule;
images: string[]; images: string[];
@ -203,7 +203,7 @@ export const updateQuestionsListDragAndDrop = (
export const updateVariants = ( export const updateVariants = (
quizId: number, quizId: number,
index: number, index: number,
variants: Variant[] variants: QuestionVariant[]
) => { ) => {
const listQuestions = { ...questionStore.getState()["listQuestions"] }; const listQuestions = { ...questionStore.getState()["listQuestions"] };