страница настроек определяет у кого из родителей нет потомка
This commit is contained in:
parent
a27a724ccd
commit
3b4cab3de5
@ -30,9 +30,10 @@ import { enqueueSnackbar } from "notistack";
|
||||
import React, { useEffect, useLayoutEffect, useState } from "react";
|
||||
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 { updateOpenBranchingPanel } from "@root/uiTools/actions";
|
||||
import { updateOpenBranchingPanel, updateCanCreatePublic } from "@root/uiTools/actions";
|
||||
import { BranchingPanel } from "../Questions/BranchingPanel";
|
||||
import { useQuestionsStore } from "@root/questions/store";
|
||||
import { useQuizes } from "@root/quizes/hooks";
|
||||
@ -43,10 +44,12 @@ import Logotip from "../Landing/images/icons/QuizLogo";
|
||||
import { clearUserData } from "@root/user";
|
||||
import { clearAuthToken } from "@frontend/kitui";
|
||||
import { logout } from "@api/auth";
|
||||
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
||||
|
||||
export default function EditPage() {
|
||||
const quiz = useCurrentQuiz();
|
||||
const { editQuizId } = useQuizStore();
|
||||
const { questions } = useQuestionsStore();
|
||||
|
||||
useEffect(() => {
|
||||
const getData = async () => {
|
||||
@ -59,7 +62,7 @@ export default function EditPage() {
|
||||
getData();
|
||||
}, []);
|
||||
|
||||
const { openBranchingPanel } = useUiTools();
|
||||
const { openBranchingPanel, whyCantCreatePublic, canCreatePublic } = useUiTools();
|
||||
const theme = useTheme();
|
||||
const navigate = useNavigate();
|
||||
const currentStep = useQuizStore((state) => state.currentStep);
|
||||
@ -80,6 +83,45 @@ export default function EditPage() {
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
|
||||
|
||||
const updateQuestionHint = useDebouncedCallback((questions:AnyTypedQuizQuestion[]) => {
|
||||
console.log("пересчитываю")
|
||||
|
||||
const problems:any = {}
|
||||
|
||||
questions.forEach((question) => {
|
||||
//Если не участвует в ветвлении, или безтиповый, или резулт - он нам не интересен
|
||||
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: ["Не выбран дефолтный вопрос"]
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
useUiTools.setState({ whyCantCreatePublic: problems })
|
||||
if (Object.keys(problems).length > 0) { updateCanCreatePublic(false) } else { updateCanCreatePublic(true) }
|
||||
console.log(problems)
|
||||
console.log(Object.keys(problems).length > 0)
|
||||
|
||||
}, 1000);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
updateQuestionHint(questions)
|
||||
console.log(canCreatePublic)
|
||||
}, [questions]);
|
||||
|
||||
|
||||
|
||||
console.log(currentStep)
|
||||
console.log(quizConfig)
|
||||
|
||||
@ -95,7 +137,7 @@ export default function EditPage() {
|
||||
navigate("/");
|
||||
}
|
||||
|
||||
if (!quizConfig) return <></>
|
||||
if (!quizConfig) return <></>
|
||||
return (
|
||||
<>
|
||||
{/*хедер*/}
|
||||
@ -157,6 +199,8 @@ if (!quizConfig) return <></>
|
||||
/>
|
||||
</FormControl>
|
||||
</Box>
|
||||
<Button onClick={() => {console.log(canCreatePublic)}}>dddddd</Button>
|
||||
<Button onClick={() => {console.log(whyCantCreatePublic)}}>dddddd</Button>
|
||||
{isTablet ? (
|
||||
<Box
|
||||
sx={{
|
||||
@ -369,13 +413,13 @@ if (!quizConfig) return <></>
|
||||
>
|
||||
{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>
|
||||
</>
|
||||
|
@ -31,4 +31,7 @@ export const updateEditSomeQuestion = (contentId?: string) => {
|
||||
};
|
||||
|
||||
|
||||
export const updateOpenedModalSettingsId = (id?: string) => useUiTools.setState({ openedModalSettingsId: id ? id : null });
|
||||
export const updateOpenedModalSettingsId = (id?: string) => useUiTools.setState({ openedModalSettingsId: id ? id : null });
|
||||
|
||||
|
||||
export const updateCanCreatePublic = (can?: boolean) => useUiTools.setState({ canCreatePublic: can ? can : false });
|
@ -8,7 +8,14 @@ export type UiTools = {
|
||||
openBranchingPanel: boolean;
|
||||
desireToOpenABranchingModal: string | null;
|
||||
editSomeQuestion: string | null;
|
||||
canCreatePublic: boolean;
|
||||
whyCantCreatePublic: Record<string, WhyCantCreatePublic>//ид вопроса и список претензий к нему
|
||||
};
|
||||
export type WhyCantCreatePublic = {
|
||||
name: string;
|
||||
problems: string[]
|
||||
|
||||
}
|
||||
|
||||
const initialState: UiTools = {
|
||||
openedModalSettingsId: null as null,
|
||||
@ -16,6 +23,8 @@ const initialState: UiTools = {
|
||||
openBranchingPanel: false,
|
||||
desireToOpenABranchingModal: null as null,
|
||||
editSomeQuestion: null as null,
|
||||
canCreatePublic: false,
|
||||
whyCantCreatePublic: {}
|
||||
};
|
||||
|
||||
export const useUiTools = create<UiTools>()(
|
||||
|
Loading…
Reference in New Issue
Block a user