страница настроек определяет у кого из родителей нет потомка
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 React, { useEffect, useLayoutEffect, useState } from "react";
|
||||||
import { Link, useNavigate } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
import { useDebouncedCallback } from "use-debounce";
|
||||||
import { SidebarMobile } from "./Sidebar/SidebarMobile";
|
import { SidebarMobile } from "./Sidebar/SidebarMobile";
|
||||||
import { cleanQuestions, setQuestions } from "@root/questions/actions";
|
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 { BranchingPanel } from "../Questions/BranchingPanel";
|
||||||
import { useQuestionsStore } from "@root/questions/store";
|
import { useQuestionsStore } from "@root/questions/store";
|
||||||
import { useQuizes } from "@root/quizes/hooks";
|
import { useQuizes } from "@root/quizes/hooks";
|
||||||
@ -43,10 +44,12 @@ import Logotip from "../Landing/images/icons/QuizLogo";
|
|||||||
import { clearUserData } from "@root/user";
|
import { clearUserData } from "@root/user";
|
||||||
import { clearAuthToken } from "@frontend/kitui";
|
import { clearAuthToken } from "@frontend/kitui";
|
||||||
import { logout } from "@api/auth";
|
import { logout } from "@api/auth";
|
||||||
|
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
||||||
|
|
||||||
export default function EditPage() {
|
export default function EditPage() {
|
||||||
const quiz = useCurrentQuiz();
|
const quiz = useCurrentQuiz();
|
||||||
const { editQuizId } = useQuizStore();
|
const { editQuizId } = useQuizStore();
|
||||||
|
const { questions } = useQuestionsStore();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const getData = async () => {
|
const getData = async () => {
|
||||||
@ -59,7 +62,7 @@ export default function EditPage() {
|
|||||||
getData();
|
getData();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const { openBranchingPanel } = useUiTools();
|
const { openBranchingPanel, whyCantCreatePublic, canCreatePublic } = useUiTools();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const currentStep = useQuizStore((state) => state.currentStep);
|
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(currentStep)
|
||||||
console.log(quizConfig)
|
console.log(quizConfig)
|
||||||
|
|
||||||
@ -157,6 +199,8 @@ if (!quizConfig) return <></>
|
|||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</Box>
|
</Box>
|
||||||
|
<Button onClick={() => {console.log(canCreatePublic)}}>dddddd</Button>
|
||||||
|
<Button onClick={() => {console.log(whyCantCreatePublic)}}>dddddd</Button>
|
||||||
{isTablet ? (
|
{isTablet ? (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
|
@ -32,3 +32,6 @@ 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;
|
openBranchingPanel: boolean;
|
||||||
desireToOpenABranchingModal: string | null;
|
desireToOpenABranchingModal: string | null;
|
||||||
editSomeQuestion: string | null;
|
editSomeQuestion: string | null;
|
||||||
|
canCreatePublic: boolean;
|
||||||
|
whyCantCreatePublic: Record<string, WhyCantCreatePublic>//ид вопроса и список претензий к нему
|
||||||
};
|
};
|
||||||
|
export type WhyCantCreatePublic = {
|
||||||
|
name: string;
|
||||||
|
problems: string[]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const initialState: UiTools = {
|
const initialState: UiTools = {
|
||||||
openedModalSettingsId: null as null,
|
openedModalSettingsId: null as null,
|
||||||
@ -16,6 +23,8 @@ const initialState: UiTools = {
|
|||||||
openBranchingPanel: false,
|
openBranchingPanel: false,
|
||||||
desireToOpenABranchingModal: null as null,
|
desireToOpenABranchingModal: null as null,
|
||||||
editSomeQuestion: null as null,
|
editSomeQuestion: null as null,
|
||||||
|
canCreatePublic: false,
|
||||||
|
whyCantCreatePublic: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useUiTools = create<UiTools>()(
|
export const useUiTools = create<UiTools>()(
|
||||||
|
Loading…
Reference in New Issue
Block a user