Merge branch 'image-video-selector' of penahub.gitlab.yandexcloud.net:frontend/squiz into image-video-selector
This commit is contained in:
commit
9a95536932
23
src/assets/icons/NameplateLogoFQ.tsx
Normal file
23
src/assets/icons/NameplateLogoFQ.tsx
Normal file
File diff suppressed because one or more lines are too long
@ -12,6 +12,7 @@ export const QUIZ_QUESTION_RESULT: Omit<QuizQuestionResult, "id" | "backendId">
|
||||
innerName: "",
|
||||
text: "",
|
||||
price: [0],
|
||||
useImage: true
|
||||
useImage: true,
|
||||
usage: true
|
||||
},
|
||||
};
|
||||
|
||||
@ -18,5 +18,6 @@ export interface QuizQuestionResult extends QuizQuestionBase {
|
||||
rule: QuestionBranchingRule,
|
||||
hint: QuestionHint;
|
||||
autofill: boolean;
|
||||
usage: boolean
|
||||
};
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ export default function Component() {
|
||||
{/*</Box>*/}
|
||||
<Button
|
||||
component={Link}
|
||||
to={userId ? "/list" : "/signin"}
|
||||
to={"/signin"}
|
||||
state={{ backgroundLocation: location }}
|
||||
variant="outlined"
|
||||
sx={{
|
||||
|
||||
@ -16,7 +16,7 @@ import {
|
||||
updateQuestion,
|
||||
getQuestionByContentId,
|
||||
clearRuleForAll,
|
||||
createFrontResult,
|
||||
createResult,
|
||||
} from "@root/questions/actions";
|
||||
import {
|
||||
updateModalInfoWhyCantCreate,
|
||||
@ -130,7 +130,7 @@ function CsComponent({
|
||||
if (Object.keys(targetQuestion).length !== 0 && parentNodeContentId && parentNodeChildren !== undefined) {
|
||||
clearDataAfterAddNode({ parentNodeContentId, targetQuestion, parentNodeChildren })
|
||||
cy?.data('changed', true)
|
||||
createFrontResult(quiz?.backendId, targetQuestion.content.id)
|
||||
createResult(quiz?.backendId, targetQuestion.content.id)
|
||||
const es = cy?.add([
|
||||
{
|
||||
data: {
|
||||
@ -157,10 +157,10 @@ function CsComponent({
|
||||
const parentQuestion = { ...getQuestionByContentId(parentNodeContentId) } as AnyTypedQuizQuestion
|
||||
|
||||
|
||||
//смотрим не добавлен ли родителю result. Если да - убираем его. Веточкам result не нужен
|
||||
//смотрим не добавлен ли родителю result. Если да - делаем его неактивным. Веточкам result не нужен
|
||||
trashQuestions.forEach((targetQuestion) => {
|
||||
if (targetQuestion.type === "result" && targetQuestion.content.rule.parentId === parentQuestion.content.id) {
|
||||
deleteQuestion(targetQuestion.id);
|
||||
updateQuestion(targetQuestion.id, (q) => q.content.usage = false);
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { Box } from "@mui/material"
|
||||
import { useEffect, useRef, useLayoutEffect } from "react";
|
||||
import { deleteQuestion, clearRuleForAll, updateQuestion } from "@root/questions/actions"
|
||||
import { deleteQuestion, clearRuleForAll, updateQuestion, createResult } from "@root/questions/actions"
|
||||
import { updateOpenedModalSettingsId } from "@root/uiTools/actions"
|
||||
import { updateRootContentId } from "@root/quizes/actions"
|
||||
import { useCurrentQuiz } from "@root/quizes/hooks"
|
||||
@ -34,11 +34,7 @@ export const FirstNodeField = ({ setOpenedModalQuestions, modalQuestionTargetCon
|
||||
if (dragQuestionContentId) {
|
||||
updateRootContentId(quiz?.id, dragQuestionContentId)
|
||||
updateQuestion(dragQuestionContentId, (question) => question.content.rule.parentId = "root")
|
||||
//если были результаты - удалить
|
||||
questions.forEach((q) => {
|
||||
if (q.type === 'result') deleteQuestion(q.id)
|
||||
})
|
||||
|
||||
createResult(quiz?.backendId, dragQuestionContentId)
|
||||
}
|
||||
} else {
|
||||
enqueueSnackbar("Нет информации о взятом опроснике")
|
||||
@ -61,10 +57,7 @@ export const FirstNodeField = ({ setOpenedModalQuestions, modalQuestionTargetCon
|
||||
if (modalQuestionTargetContentId) {
|
||||
updateRootContentId(quiz?.id, modalQuestionTargetContentId)
|
||||
updateQuestion(modalQuestionTargetContentId, (question) => question.content.rule.parentId = "root")
|
||||
//если были результаты - удалить
|
||||
questions.forEach((q) => {
|
||||
if (q.type === 'result') deleteQuestion(q.id)
|
||||
})
|
||||
createResult(quiz?.backendId, modalQuestionTargetContentId)
|
||||
}
|
||||
} else {
|
||||
enqueueSnackbar("Нет информации о взятом опроснике")
|
||||
|
||||
@ -3,7 +3,6 @@ import {
|
||||
updateQuestion,
|
||||
getQuestionByContentId,
|
||||
clearRuleForAll,
|
||||
createFrontResult,
|
||||
} from "@root/questions/actions";
|
||||
import { useQuestionsStore } from "@root/questions/store";
|
||||
import { useCurrentQuiz } from "@root/quizes/hooks";
|
||||
@ -143,11 +142,6 @@ export const useRemoveNode = ({
|
||||
question.content.rule.children = [];
|
||||
question.content.rule.default = "";
|
||||
});
|
||||
trashQuestions.forEach((q) => {
|
||||
if (q.type === "result") {
|
||||
deleteQuestion(q.id);
|
||||
}
|
||||
});
|
||||
clearRuleForAll();
|
||||
} else {
|
||||
const parentQuestionContentId = cy
|
||||
@ -159,7 +153,7 @@ export const useRemoveNode = ({
|
||||
quiz &&
|
||||
cy?.edges(`[source="${parentQuestionContentId}"]`).length === 0
|
||||
) {
|
||||
createFrontResult(quiz.backendId, parentQuestionContentId);
|
||||
//createFrontResult(quiz.backendId, parentQuestionContentId);
|
||||
}
|
||||
clearDataAfterRemoveNode({
|
||||
targetQuestionContentId: targetNodeContentId,
|
||||
|
||||
@ -57,11 +57,6 @@ export default function ButtonsOptions({
|
||||
if (question.content.rule.parentId === "root") { //удалить из стора root и очистить rule всем вопросам
|
||||
updateRootContentId(quiz.id, "");
|
||||
clearRuleForAll();
|
||||
questions.forEach(q => {
|
||||
if (q.type === "result") {
|
||||
deleteQuestion(q.id);
|
||||
}
|
||||
});
|
||||
deleteQuestion(question.id);
|
||||
} else if (question.content.rule.parentId.length > 0) { //удалить из стора вопрос из дерева и очистить его потомков
|
||||
const clearQuestions = [] as string[];
|
||||
@ -69,10 +64,8 @@ export default function ButtonsOptions({
|
||||
//записываем потомков , а их результаты удаляем
|
||||
const getChildren = (parentQuestion: AnyTypedQuizQuestion) => {
|
||||
questions.forEach((targetQuestion) => {
|
||||
if (targetQuestion.content.rule.parentId === parentQuestion.content.id) {//если у вопроса совпал родитель с родителем => он потомок, в кучу его
|
||||
if (targetQuestion.type === "result") {
|
||||
deleteQuestion(targetQuestion.id);
|
||||
} else {
|
||||
if (targetQuestion.type !== null && targetQuestion.content.rule.parentId === parentQuestion.content.id) {//если у вопроса совпал родитель с родителем => он потомок, в кучу его
|
||||
if (targetQuestion.type !== "result" && targetQuestion.type !== null) {
|
||||
if (!clearQuestions.includes(targetQuestion.content.id)) clearQuestions.push(targetQuestion.content.id);
|
||||
getChildren(targetQuestion); //и ищем его потомков
|
||||
}
|
||||
|
||||
@ -58,11 +58,6 @@ export default function ButtonsOptionsAndPict({
|
||||
if (question.content.rule.parentId === "root") { //удалить из стора root и очистить rule всем вопросам
|
||||
updateRootContentId(quiz.id, "");
|
||||
clearRuleForAll();
|
||||
questions.forEach(q => {
|
||||
if (q.type === "result") {
|
||||
deleteQuestion(q.id);
|
||||
}
|
||||
});
|
||||
deleteQuestion(question.id);
|
||||
} else if (question.content.rule.parentId.length > 0) { //удалить из стора вопрос из дерева и очистить его потомков
|
||||
const clearQuestions = [] as string[];
|
||||
@ -71,9 +66,7 @@ export default function ButtonsOptionsAndPict({
|
||||
const getChildren = (parentQuestion: AnyTypedQuizQuestion) => {
|
||||
questions.forEach((targetQuestion) => {
|
||||
if (targetQuestion.content.rule.parentId === parentQuestion.content.id) {//если у вопроса совпал родитель с родителем => он потомок, в кучу его
|
||||
if (targetQuestion.type === "result") {
|
||||
deleteQuestion(targetQuestion.id);
|
||||
} else {
|
||||
if (targetQuestion.type !== null && targetQuestion.type !== "result") {
|
||||
if (!clearQuestions.includes(targetQuestion.content.id)) clearQuestions.push(targetQuestion.content.id);
|
||||
getChildren(targetQuestion); //и ищем его потомков
|
||||
}
|
||||
|
||||
@ -93,21 +93,14 @@ const maxLengthTextField = 225;
|
||||
updateRootContentId(quiz.id, "");
|
||||
clearRuleForAll();
|
||||
deleteQuestion(question.id);
|
||||
questions.forEach(q => {
|
||||
if (q.type === "result") {
|
||||
deleteQuestion(q.id);
|
||||
}
|
||||
});
|
||||
} else if (question.content.rule.parentId.length > 0) { //удалить из стора вопрос из дерева и очистить его потомков
|
||||
const clearQuestions = [] as string[];
|
||||
|
||||
//записываем потомков , а их результаты удаляем
|
||||
const getChildren = (parentQuestion: AnyTypedQuizQuestion) => {
|
||||
questions.forEach((targetQuestion) => {
|
||||
if (targetQuestion.content.rule.parentId === parentQuestion.content.id) {//если у вопроса совпал родитель с родителем => он потомок, в кучу его
|
||||
if (targetQuestion.type === "result") {
|
||||
deleteQuestion(targetQuestion.id);
|
||||
} else {
|
||||
if (targetQuestion.type !== null && targetQuestion.content.rule.parentId === parentQuestion.content.id) {//если у вопроса совпал родитель с родителем => он потомок, в кучу его
|
||||
if (targetQuestion.type !== null && targetQuestion.type !== "result") {
|
||||
if (!clearQuestions.includes(targetQuestion.content.id)) clearQuestions.push(targetQuestion.content.id);
|
||||
getChildren(targetQuestion); //и ищем его потомков
|
||||
}
|
||||
|
||||
@ -1,38 +1,10 @@
|
||||
import { ResultSettings } from "./ResultSettings";
|
||||
import { createFrontResult } from "@root/questions/actions";
|
||||
import { useQuestionsStore } from "@root/questions/store";
|
||||
import { useCurrentQuiz } from "@root/quizes/hooks";
|
||||
import { Box, Typography, useTheme, useMediaQuery, Button } from "@mui/material";
|
||||
import image from "../../assets/Rectangle 110.png";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
||||
import ArrowLeft from "../../assets/icons/questionsPage/arrowLeft";
|
||||
import { decrementCurrentStep } from "@root/quizes/actions";
|
||||
|
||||
export const FirstEntry = () => {
|
||||
const theme = useTheme();
|
||||
const quiz = useCurrentQuiz();
|
||||
const { questions } = useQuestionsStore();
|
||||
const isSmallMonitor = useMediaQuery(theme.breakpoints.down(1250));
|
||||
|
||||
const create = () => {
|
||||
if (quiz?.config.haveRoot) {
|
||||
questions
|
||||
.filter((question: AnyTypedQuizQuestion) => {
|
||||
return (
|
||||
question.type !== null &&
|
||||
question.content.rule.parentId.length !== 0 &&
|
||||
question.content.rule.children.length === 0
|
||||
);
|
||||
})
|
||||
.forEach((question) => {
|
||||
createFrontResult(quiz.backendId, question.content.id);
|
||||
});
|
||||
} else {
|
||||
createFrontResult(quiz.backendId, "line");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Box
|
||||
@ -99,35 +71,6 @@ export const FirstEntry = () => {
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box sx={{ display: "flex", justifyContent: "flex-start", alignItems: "center", gap: "8px", mt: "30px" }}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
sx={{
|
||||
padding: "10px 20px",
|
||||
borderRadius: "8px",
|
||||
height: "44px",
|
||||
}}
|
||||
onClick={decrementCurrentStep}
|
||||
>
|
||||
<ArrowLeft />
|
||||
</Button>
|
||||
<Button
|
||||
onClick={create}
|
||||
variant="contained"
|
||||
sx={{
|
||||
backgroundColor: "#7E2AEA",
|
||||
fontSize: "18px",
|
||||
lineHeight: "18px",
|
||||
width: "216px",
|
||||
height: "44px",
|
||||
|
||||
p: "10px 20px",
|
||||
}}
|
||||
>
|
||||
Создать результаты
|
||||
</Button>
|
||||
</Box>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@ -1,15 +1,43 @@
|
||||
import { useQuestionsStore } from "@root/questions/store";
|
||||
import { FirstEntry } from "./FirstEntry"
|
||||
import { ResultSettings } from "./ResultSettings"
|
||||
import { decrementCurrentStep, incrementCurrentStep } from "@root/quizes/actions";
|
||||
import { Box, Button } from "@mui/material";
|
||||
import ArrowLeft from "@icons/questionsPage/arrowLeft"
|
||||
|
||||
export const ResultPage = () => {
|
||||
const { questions } = useQuestionsStore();
|
||||
//ищём хотя бы один result
|
||||
const haveResult = questions.some((question) => question.type === "result")
|
||||
return (
|
||||
haveResult ?
|
||||
<ResultSettings />
|
||||
:
|
||||
<>
|
||||
<FirstEntry />
|
||||
);
|
||||
<ResultSettings />
|
||||
<Box sx={{ display: "flex", justifyContent: "flex-start", alignItems: "center", gap: "8px", mt: "30px" }}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
sx={{
|
||||
padding: "10px 20px",
|
||||
borderRadius: "8px",
|
||||
height: "44px",
|
||||
}}
|
||||
onClick={decrementCurrentStep}
|
||||
>
|
||||
<ArrowLeft />
|
||||
</Button>
|
||||
<Button
|
||||
onClick={incrementCurrentStep}
|
||||
variant="contained"
|
||||
sx={{
|
||||
backgroundColor: "#7E2AEA",
|
||||
fontSize: "18px",
|
||||
lineHeight: "18px",
|
||||
width: "216px",
|
||||
height: "44px",
|
||||
|
||||
p: "10px 20px",
|
||||
}}
|
||||
>
|
||||
Настроить форму
|
||||
</Button>
|
||||
|
||||
</Box>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@ -14,7 +14,7 @@ import { ResultCard, checkEmptyData } from "./cards/ResultCard";
|
||||
import { EmailSettingsCard } from "./cards/EmailSettingsCard";
|
||||
import { useCurrentQuiz } from "@root/quizes/hooks";
|
||||
import { useQuestionsStore } from "@root/questions/store";
|
||||
import { createFrontResult, deleteQuestion } from "@root/questions/actions";
|
||||
import { deleteQuestion } from "@root/questions/actions";
|
||||
import { QuizQuestionResult } from "@model/questionTypes/result";
|
||||
|
||||
export const ResultSettings = () => {
|
||||
@ -25,6 +25,8 @@ export const ResultSettings = () => {
|
||||
const [resultContract, setResultContract] = useState(true);
|
||||
const isReadyToLeaveRef = useRef(true);
|
||||
|
||||
console.log(quiz)
|
||||
console.log(results)
|
||||
useEffect(
|
||||
function calcIsReadyToLeave() {
|
||||
let isReadyToLeave = true;
|
||||
|
||||
@ -6,6 +6,7 @@ import TextIcon from "@icons/ContactFormIcon/TextIcon";
|
||||
import AddressIcon from "@icons/ContactFormIcon/AddressIcon";
|
||||
|
||||
import { useCurrentQuiz } from "@root/quizes/hooks";
|
||||
import { NameplateLogo } from "@icons/NameplateLogo";
|
||||
import CustomCheckbox from "@ui_kit/CustomCheckbox";
|
||||
import { useState } from "react";
|
||||
import { useQuestionsStore } from "@root/questions/store";
|
||||
@ -71,19 +72,19 @@ export const ContactForm = ({
|
||||
}}
|
||||
>
|
||||
{quiz?.config.formContact.title || "Заполните форму, чтобы получить результаты теста"}
|
||||
|
||||
|
||||
</Typography>
|
||||
{
|
||||
quiz?.config.formContact.desc &&
|
||||
<Typography
|
||||
sx={{
|
||||
textAlign: "center",
|
||||
m: "20px 0",
|
||||
fontSize: "18px"
|
||||
}}
|
||||
>
|
||||
{quiz?.config.formContact.desc}
|
||||
</Typography>
|
||||
<Typography
|
||||
sx={{
|
||||
textAlign: "center",
|
||||
m: "20px 0",
|
||||
fontSize: "18px"
|
||||
}}
|
||||
>
|
||||
{quiz?.config.formContact.desc}
|
||||
</Typography>
|
||||
}
|
||||
</Box>
|
||||
|
||||
@ -138,6 +139,16 @@ export const ContactForm = ({
|
||||
</Typography>
|
||||
|
||||
</Box>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
mt: "20px"
|
||||
}}
|
||||
>
|
||||
<NameplateLogo style={{ fontSize: "34px" }} />
|
||||
<Typography sx={{ fontSize: "20px", color: "#4D4D4D", whiteSpace: "nowrap" }}>Сделано на PenaQuiz</Typography>
|
||||
</Box>
|
||||
</Paper>
|
||||
</Box >
|
||||
</Box >
|
||||
@ -154,14 +165,14 @@ const Inputs = () => {
|
||||
if (FC.used) someUsed.push(<CustomInput title={FC.innerText || data.defaultText} desc={FC.text || data.defaultTitle} Icon={data.icon} />)
|
||||
return <CustomInput title={FC.innerText || data.defaultText} desc={FC.text || data.defaultTitle} Icon={data.icon} />
|
||||
})
|
||||
|
||||
|
||||
if (someUsed.length) {
|
||||
return <>{someUsed}</>
|
||||
} else {
|
||||
return <>
|
||||
{Icons[0]}
|
||||
{Icons[1]}
|
||||
{Icons[2]}
|
||||
{Icons[0]}
|
||||
{Icons[1]}
|
||||
{Icons[2]}
|
||||
</>
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import { useQuestionsStore } from "@root/questions/store";
|
||||
import type { AnyTypedQuizQuestion, QuizQuestionBase } from "../../model/questionTypes/shared";
|
||||
import { getQuestionByContentId } from "@root/questions/actions";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { NameplateLogo } from "@icons/NameplateLogo";
|
||||
import { NameplateLogoFQ } from "@icons/NameplateLogoFQ";
|
||||
|
||||
type FooterProps = {
|
||||
setCurrentQuestion: (step: AnyTypedQuizQuestion) => void;
|
||||
@ -189,22 +189,11 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
||||
position: "relative",
|
||||
padding: "15px 0",
|
||||
borderTop: `1px solid ${theme.palette.grey[400]}`,
|
||||
height: '75px',
|
||||
|
||||
display: "flex"
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
position: "absolute",
|
||||
top: "-45px",
|
||||
left: "50%",
|
||||
transform: "translateX(-50%)",
|
||||
gap: "8px",
|
||||
}}
|
||||
>
|
||||
<NameplateLogo style={{ fontSize: "34px" }} />
|
||||
<Typography sx={{ fontSize: "20px", color: "#4D4D4D", whiteSpace: "nowrap" }}>Сделано на PenaQuiz</Typography>
|
||||
</Box>
|
||||
<Box
|
||||
sx={{
|
||||
width: "100%",
|
||||
@ -216,6 +205,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
||||
gap: "10px",
|
||||
}}
|
||||
>
|
||||
<NameplateLogoFQ style={{ fontSize: "34px", width:"200px", height:"auto" }} />
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
|
||||
@ -64,11 +64,14 @@ export const Question = ({ questions }: QuestionProps) => {
|
||||
const QuestionComponent = QUESTIONS_MAP[currentQuestion.type as Exclude<QuestionType, "nonselected">];
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Box
|
||||
|
||||
height="100vh"
|
||||
>
|
||||
{!showContactForm && !showResultForm && (
|
||||
<Box
|
||||
sx={{
|
||||
minHeight: "calc(100vh - 75px)",
|
||||
height: "calc(100vh - 75px)",
|
||||
width: "100%",
|
||||
maxWidth: "1440px",
|
||||
padding: "40px 25px 20px",
|
||||
|
||||
@ -6,6 +6,7 @@ import { useQuestionsStore } from "@root/questions/store";
|
||||
|
||||
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
|
||||
import YoutubeEmbedIframe from "../../ui_kit/StartPagePreview/YoutubeEmbedIframe.tsx"
|
||||
import { NameplateLogo } from "@icons/NameplateLogo";
|
||||
|
||||
type ResultFormProps = {
|
||||
currentQuestion: AnyTypedQuizQuestion;
|
||||
@ -29,7 +30,7 @@ export const ResultForm = ({
|
||||
(question.content.rule.parentId === "line" || currentQuestion.content.id)
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const followNextForm = () => {
|
||||
@ -100,31 +101,59 @@ export const ResultForm = ({
|
||||
|
||||
</Box>
|
||||
|
||||
{
|
||||
quiz?.config.resultInfo.when === "before" &&
|
||||
<Box width="100%">
|
||||
<Box
|
||||
sx={{
|
||||
height: "100px",
|
||||
boxShadow: "0 0 15px 0 rgba(0,0,0,.08)",
|
||||
width: "100%",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center"
|
||||
width: "100%",
|
||||
justifyContent: "end",
|
||||
px: "20px"
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
onClick={followNextForm}
|
||||
variant="contained"
|
||||
<Box
|
||||
sx={{
|
||||
p: "10px 20px",
|
||||
width: "210px",
|
||||
height: "50px"
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
mt: "15px"
|
||||
}}
|
||||
>
|
||||
{resultQuestion.content.hint.text || "Узнать подробнее"}
|
||||
</Button>
|
||||
<NameplateLogo style={{ fontSize: "34px" }} />
|
||||
<Typography sx={{ fontSize: "20px", color: "#4D4D4D", whiteSpace: "nowrap" }}>Сделано на PenaQuiz</Typography>
|
||||
</Box>
|
||||
|
||||
</Box>
|
||||
}
|
||||
|
||||
{
|
||||
quiz?.config.resultInfo.when === "before" &&
|
||||
<>
|
||||
<Box
|
||||
sx={{
|
||||
boxShadow: "0 0 15px 0 rgba(0,0,0,.08)",
|
||||
width: "100%",
|
||||
flexDirection: "column",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
p: "20px"
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
onClick={followNextForm}
|
||||
variant="contained"
|
||||
sx={{
|
||||
p: "10px 20px",
|
||||
width: "210px",
|
||||
height: "50px"
|
||||
}}
|
||||
>
|
||||
{resultQuestion.content.hint.text || "Узнать подробнее"}
|
||||
</Button>
|
||||
</Box>
|
||||
</>
|
||||
}
|
||||
</Box>
|
||||
|
||||
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
@ -32,7 +32,7 @@ import { Link, useNavigate } from "react-router-dom";
|
||||
import useSWR from "swr";
|
||||
import { useDebouncedCallback } from "use-debounce";
|
||||
import { SidebarMobile } from "./Sidebar/SidebarMobile";
|
||||
import { cleanQuestions, setQuestions } from "@root/questions/actions";
|
||||
import { cleanQuestions, createResult, setQuestions } from "@root/questions/actions";
|
||||
import { updateOpenBranchingPanel, updateCanCreatePublic, updateModalInfoWhyCantCreate } from "@root/uiTools/actions";
|
||||
import { BranchingPanel } from "../Questions/BranchingPanel";
|
||||
import { useQuestionsStore } from "@root/questions/store";
|
||||
@ -59,10 +59,14 @@ export default function EditPage() {
|
||||
|
||||
const questions = await questionApi.getList({ quiz_id: editQuizId });
|
||||
setQuestions(questions);
|
||||
if (questions === null || !questions.find(q => q.type !== null && q.content?.rule.parentId === "line")) createResult(quiz?.backendId, "line")
|
||||
};
|
||||
getData();
|
||||
}, []);
|
||||
|
||||
console.log(quiz)
|
||||
console.log(questions)
|
||||
|
||||
const { openBranchingPanel, whyCantCreatePublic, canCreatePublic } = useUiTools();
|
||||
const theme = useTheme();
|
||||
const navigate = useNavigate();
|
||||
@ -71,7 +75,7 @@ export default function EditPage() {
|
||||
const isMobile = useMediaQuery(theme.breakpoints.down(660));
|
||||
const [mobileSidebar, setMobileSidebar] = useState<boolean>(false);
|
||||
const quizConfig = quiz?.config;
|
||||
const disableTest = quiz === undefined ? true : quiz.config.type === null;
|
||||
const disableTest = quiz === undefined ? true : (quiz.config.type === null)
|
||||
|
||||
useEffect(() => {
|
||||
if (editQuizId === null) navigate("/list");
|
||||
@ -87,39 +91,43 @@ export default function EditPage() {
|
||||
);
|
||||
|
||||
const updateQuestionHint = useDebouncedCallback((questions: AnyTypedQuizQuestion[]) => {
|
||||
const problems: any = {};
|
||||
|
||||
const problems: any = {}
|
||||
|
||||
questions.forEach((question) => {
|
||||
//Если не участвует в ветвлении, или безтиповый, или резулт - он нам не интересен
|
||||
if (question.type === null || question.type === "result" || question.content.rule.parentId.length === 0) return;
|
||||
if (question.type === null
|
||||
|| question.type === "result"
|
||||
|| question.content.rule.parentId.length === 0) return
|
||||
|
||||
//если есть дети, но нет дефолта - логическая ошибка. Так нельзя
|
||||
if (question.content.rule.children.length > 0 && question.content.rule.default.length === 0) {
|
||||
problems[question.content.id] = {
|
||||
name: question.title,
|
||||
problems: ["Не выбран дефолтный вопрос"],
|
||||
};
|
||||
problems: ["Не выбран дефолтный вопрос"]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
console.log(problems);
|
||||
|
||||
useUiTools.setState({ whyCantCreatePublic: problems });
|
||||
})
|
||||
|
||||
useUiTools.setState({ whyCantCreatePublic: problems })
|
||||
if (Object.keys(problems).length > 0) {
|
||||
updateQuiz(quiz?.id, (state) => {
|
||||
state.status = "stop";
|
||||
});
|
||||
updateCanCreatePublic(false);
|
||||
updateQuiz(quiz?.id, (state) => { state.status = "stop" })
|
||||
updateCanCreatePublic(false)
|
||||
} else {
|
||||
updateCanCreatePublic(true);
|
||||
updateCanCreatePublic(true)
|
||||
}
|
||||
|
||||
|
||||
}, 600);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
updateQuestionHint(questions);
|
||||
updateQuestionHint(questions)
|
||||
}, [questions]);
|
||||
|
||||
|
||||
|
||||
async function handleLogoutClick() {
|
||||
const [, logoutError] = await logout();
|
||||
|
||||
@ -361,7 +369,7 @@ export default function EditPage() {
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{!canCreatePublic && quiz.config.type !== "form" ? (
|
||||
{!canCreatePublic && quiz.config.type !== "form" ?
|
||||
<Button
|
||||
variant="contained"
|
||||
// disabled
|
||||
@ -371,13 +379,11 @@ export default function EditPage() {
|
||||
height: "34px",
|
||||
minWidth: "130px",
|
||||
}}
|
||||
onClick={() =>
|
||||
Object.keys(whyCantCreatePublic).length === 0 ? null : updateModalInfoWhyCantCreate(true)
|
||||
}
|
||||
onClick={() => Object.keys(whyCantCreatePublic).length === 0 ? () => { } : updateModalInfoWhyCantCreate(true)}
|
||||
>
|
||||
Тестовый просмотр
|
||||
</Button>
|
||||
) : (
|
||||
:
|
||||
<a href={`/view`} target="_blank" rel="noreferrer" style={{ textDecoration: "none" }}>
|
||||
<Button
|
||||
variant="contained"
|
||||
@ -391,7 +397,7 @@ export default function EditPage() {
|
||||
Тестовый просмотр
|
||||
</Button>
|
||||
</a>
|
||||
)}
|
||||
}
|
||||
|
||||
<Button
|
||||
variant="outlined"
|
||||
@ -404,31 +410,26 @@ export default function EditPage() {
|
||||
color: quiz?.status === "start" ? "#FFFFFF" : theme.palette.brightPurple.main,
|
||||
}}
|
||||
onClick={
|
||||
Object.keys(whyCantCreatePublic).length === 0
|
||||
? () =>
|
||||
updateQuiz(quiz?.id, (state) => {
|
||||
state.status = quiz?.status === "start" ? "stop" : "start";
|
||||
})
|
||||
: () => updateModalInfoWhyCantCreate(true)
|
||||
Object.keys(whyCantCreatePublic).length === 0 ?
|
||||
() => updateQuiz(quiz?.id, (state) => {
|
||||
state.status = quiz?.status === "start" ? "stop" : "start";
|
||||
})
|
||||
:
|
||||
() => updateModalInfoWhyCantCreate(true)
|
||||
}
|
||||
>
|
||||
{quiz?.status === "start" ? "Стоп" : "Старт"}
|
||||
</Button>
|
||||
{quiz?.status === "start" && (
|
||||
<Box
|
||||
component={Link}
|
||||
sx={{
|
||||
color: "#7e2aea",
|
||||
fontSize: "14px",
|
||||
}}
|
||||
target="_blank"
|
||||
to={"https://hbpn.link/" + quiz.qid}
|
||||
>
|
||||
https://hbpn.link/{quiz.qid}
|
||||
</Box>
|
||||
)}
|
||||
{quiz?.status === "start" && <Box
|
||||
component={Link}
|
||||
sx={{
|
||||
color: "#7e2aea",
|
||||
fontSize: "14px"
|
||||
}}
|
||||
target="_blank" to={"https://hbpn.link/" + quiz.qid}>https://hbpn.link/{quiz.qid}
|
||||
</Box>}
|
||||
</Box>
|
||||
</Box>
|
||||
</Box >
|
||||
<ModalInfoWhyCantCreate />
|
||||
</>
|
||||
);
|
||||
|
||||
@ -15,6 +15,7 @@ import { useCurrentQuiz } from "@root/quizes/hooks";
|
||||
import { QuestionsStore, useQuestionsStore } from "./store";
|
||||
import { useUiTools } from "../uiTools/store";
|
||||
import { withErrorBoundary } from "react-error-boundary";
|
||||
import { QuizQuestionResult } from "@model/questionTypes/result";
|
||||
|
||||
|
||||
export const setQuestions = (questions: RawQuestion[] | null) => setProducedState(state => {
|
||||
@ -481,7 +482,12 @@ export const getQuestionByContentId = (questionContentId: string | null) => {
|
||||
export const clearRuleForAll = () => {
|
||||
const { questions } = useQuestionsStore.getState();
|
||||
questions.forEach(question => {
|
||||
if (question.type !== null && (question.content.rule.main.length > 0 || question.content.rule.default.length > 0 || question.content.rule.parentId.length > 0)) {
|
||||
if (question.type !== null &&
|
||||
(question.content.rule.main.length > 0
|
||||
|| question.content.rule.default.length > 0
|
||||
|| question.content.rule.parentId.length > 0)
|
||||
&& question.type !== "result") {
|
||||
|
||||
updateQuestion(question.content.id, question => {
|
||||
question.content.rule.parentId = "";
|
||||
question.content.rule.main = [];
|
||||
@ -491,63 +497,48 @@ export const clearRuleForAll = () => {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
export const createFrontResult = (quizId: number, parentContentId?: string) => setProducedState(state => {
|
||||
const frontId = nanoid();
|
||||
const content = JSON.parse(JSON.stringify(defaultQuestionByType["result"].content));
|
||||
content.id = frontId;
|
||||
if (parentContentId) content.rule.parentId = parentContentId;
|
||||
state.questions.push({
|
||||
id: frontId,
|
||||
quizId,
|
||||
type: "result",
|
||||
title: "",
|
||||
description: "",
|
||||
deleted: false,
|
||||
expanded: true,
|
||||
page: 101,
|
||||
required: true,
|
||||
content
|
||||
});
|
||||
}, {
|
||||
type: "createFrontResult",
|
||||
quizId,
|
||||
});
|
||||
|
||||
|
||||
export const createBackResult = async (
|
||||
questionId: string,
|
||||
type: QuestionType,
|
||||
export const createResult = async (
|
||||
quizId: number,
|
||||
parentContentId?: string
|
||||
) => requestQueue.enqueue(async () => {
|
||||
const question = useQuestionsStore.getState().questions.find(q => q.id === questionId);
|
||||
if (!question) return;
|
||||
if (question.type !== "result") throw new Error("Cannot upgrade already typed question");
|
||||
|
||||
try {
|
||||
const createdQuestion = await questionApi.create({
|
||||
quiz_id: question.quizId,
|
||||
type,
|
||||
title: question.title,
|
||||
description: question.description,
|
||||
page: 0,
|
||||
required: true,
|
||||
content: JSON.stringify(defaultQuestionByType[type].content),
|
||||
});
|
||||
|
||||
setProducedState(state => {
|
||||
const questionIndex = state.questions.findIndex(q => q.id === questionId);
|
||||
if (questionIndex !== -1) state.questions.splice(
|
||||
questionIndex,
|
||||
1,
|
||||
rawQuestionToQuestion(createdQuestion)
|
||||
);
|
||||
}, {
|
||||
type: "createBackResult",
|
||||
question,
|
||||
});
|
||||
} catch (error) {
|
||||
devlog("Error creating question", error);
|
||||
enqueueSnackbar("Не удалось создать вопрос");
|
||||
if (!quizId || !parentContentId) {
|
||||
console.error("Нет данных для создания результата. quizId: ", quizId, ", quizId: ", parentContentId)
|
||||
}
|
||||
|
||||
//Мы получили запрос на создание резулта. Анализируем существует ли такой. Если да - просто делаем его активным
|
||||
const question = useQuestionsStore.getState().questions.find(q=> q.type !== null && q?.content.rule.parentContentId === parentContentId)
|
||||
|
||||
if (question) {//существует, делаем активным
|
||||
|
||||
updateQuestion(question.id, (q) => {
|
||||
q.content.usage = true
|
||||
})
|
||||
|
||||
} else {//не существует, создаём
|
||||
const content = JSON.parse(JSON.stringify(defaultQuestionByType["result"].content));
|
||||
content.rule.parentId = parentContentId;
|
||||
|
||||
try {
|
||||
const createdQuestion:RawQuestion = await questionApi.create({
|
||||
quiz_id: quizId,
|
||||
type: "result",
|
||||
title: "",
|
||||
description: "",
|
||||
page: 101,
|
||||
required: true,
|
||||
content: JSON.stringify(content),
|
||||
});
|
||||
|
||||
setProducedState(state => {
|
||||
state.questions.push(rawQuestionToQuestion(createdQuestion))
|
||||
}, {
|
||||
type: "createBackResult",
|
||||
createdQuestion,
|
||||
});
|
||||
} catch (error) {
|
||||
devlog("Error creating question", error);
|
||||
enqueueSnackbar("Не удалось создать вопрос");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -9,8 +9,9 @@ import { NavigateFunction } from "react-router-dom";
|
||||
import { isAxiosCanceledError } from "../../utils/isAxiosCanceledError";
|
||||
import { RequestQueue } from "../../utils/requestQueue";
|
||||
import { QuizStore, useQuizStore } from "./store";
|
||||
import { createUntypedQuestion } from "@root/questions/actions";
|
||||
import { createUntypedQuestion, updateQuestion } from "@root/questions/actions";
|
||||
import { useCurrentQuiz } from "./hooks"
|
||||
import { useQuestionsStore } from "@root/questions/store";
|
||||
|
||||
|
||||
export const setEditQuizId = (quizId: number | null) => setProducedState(state => {
|
||||
@ -176,12 +177,40 @@ export const deleteQuiz = async (quizId: string) => requestQueue.enqueue(async (
|
||||
enqueueSnackbar(`Не удалось удалить квиз. ${message}`);
|
||||
}
|
||||
});
|
||||
export const updateRootContentId = (quizId: string, id:string) => updateQuiz(
|
||||
quizId,
|
||||
quiz => {
|
||||
quiz.config.haveRoot = id
|
||||
},
|
||||
);
|
||||
export const updateRootContentId = (quizId: string, id: string) => {
|
||||
|
||||
if (id.length === 0) {//дерева больше не существует, все результаты неактивны кроме результата линейности
|
||||
useQuestionsStore.getState().questions.forEach((q) => {
|
||||
if (q.type !== null && q.type === "result") {
|
||||
if (q.content.rule.parentId === "line" && q.content.usage === false) {
|
||||
updateQuestion(q.id, (q) => {
|
||||
q.content.usage === true
|
||||
})
|
||||
} else {
|
||||
updateQuestion(q.id, (q) => {
|
||||
q.content.usage === false
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
} else { //было создано дерево, результат линейности неактивен
|
||||
useQuestionsStore.getState().questions.forEach((q) => {
|
||||
if (q.type !== null && q.content.rule.parentId === "line") {
|
||||
updateQuestion(q.id, (q) => {
|
||||
q.content.usage === false
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
updateQuiz(
|
||||
quizId,
|
||||
quiz => {
|
||||
quiz.config.haveRoot = id
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// TODO copy quiz
|
||||
|
||||
Loading…
Reference in New Issue
Block a user