From bec4b6fc4d93d902665413d0e7007bbd34ab54a8 Mon Sep 17 00:00:00 2001 From: Nastya Date: Thu, 14 Dec 2023 19:50:02 +0300 Subject: [PATCH] private route, delete untyped questions, stop open empty modal node creator --- src/App.tsx | 20 ++++++++++--------- .../AnswerDraggableList/AnswerItem.tsx | 4 ++-- .../Questions/BranchingMap/CsComponent.tsx | 8 +++++--- .../Questions/BranchingMap/FirstNodeField.tsx | 3 ++- .../BranchingQuestionsModal.tsx | 16 +++++++++++---- .../BranchingQuestionsModal/index.tsx | 3 ++- src/pages/Questions/ButtonsOptions.tsx | 4 ++-- src/pages/Questions/ButtonsOptionsAndPict.tsx | 2 +- .../Questions/DataOptions/settingData.tsx | 2 +- .../DraggableList/QuestionPageCard.tsx | 2 +- .../Questions/DropDown/settingDropDown.tsx | 2 +- .../Form/FormDraggableList/index.tsx | 5 ++++- src/pages/Questions/UploadVideoModal.tsx | 4 ++-- .../answerOptions/responseSettings.tsx | 2 +- src/pages/Questions/helpQuestions.tsx | 2 +- .../StartPageViewPublication.tsx | 2 +- src/pages/ViewPublicationPage/index.tsx | 16 +++++++-------- src/pages/createQuize/QuizCard.tsx | 4 ++-- src/stores/questions/actions.ts | 3 +-- src/stores/uiTools/actions.ts | 5 ++++- src/ui_kit/PrivateRoute.tsx | 9 +++++++++ 21 files changed, 73 insertions(+), 45 deletions(-) create mode 100644 src/ui_kit/PrivateRoute.tsx diff --git a/src/App.tsx b/src/App.tsx index d1323fc0..65083d8f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -19,6 +19,7 @@ import EditPage from "./pages/startPage/EditPage"; import { clearAuthToken, getMessageFromFetchError, useUserFetcher } from "@frontend/kitui"; import { clearUserData, setUser, useUserStore } from "@root/user"; import { enqueueSnackbar } from "notistack"; +import PrivateRoute from "@ui_kit/PrivateRoute"; dayjs.locale("ru"); @@ -64,16 +65,17 @@ export default function App() { )} - {routeslink.map((e, i) => ( - } /> - ))} - } /> - } /> - } /> - } /> - } />/> + }> + {routeslink.map((e, i) => ( + } /> + ))} + } /> + } /> + } /> + } /> + } /> + - } /> ); diff --git a/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx b/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx index 467132ab..8eca8d32 100644 --- a/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx +++ b/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx @@ -77,7 +77,7 @@ export const AnswerItem = ({ placeholder={"Добавьте ответ"} multiline={largeCheck} onChange={({ target }) => { - setQuestionVariantAnswer(target.value); + setQuestionVariantAnswer(target.value || " "); }} onKeyDown={(event: KeyboardEvent) => { if (event.code === "Enter" && !largeCheck) { @@ -124,7 +124,7 @@ export const AnswerItem = ({ style={{ margin: "10px" }} placeholder="Подсказка для этого ответа" value={variant.hints} - onChange={e => setQuestionVariantAnswer(e.target.value)} + onChange={e => setQuestionVariantAnswer(e.target.value || " ")} onKeyDown={( event: KeyboardEvent ) => event.stopPropagation()} diff --git a/src/pages/Questions/BranchingMap/CsComponent.tsx b/src/pages/Questions/BranchingMap/CsComponent.tsx index f38ab54c..04817d41 100644 --- a/src/pages/Questions/BranchingMap/CsComponent.tsx +++ b/src/pages/Questions/BranchingMap/CsComponent.tsx @@ -7,7 +7,8 @@ import { useCurrentQuiz } from "@root/quizes/hooks"; import { updateRootContentId } from "@root/quizes/actions" import { AnyTypedQuizQuestion } from "@model/questionTypes/shared" import { useQuestionsStore } from "@root/questions/store"; -import { deleteQuestion, updateQuestion, updateOpenedModalSettingsId, getQuestionByContentId, clearRuleForAll } from "@root/questions/actions"; +import { deleteQuestion, updateQuestion, getQuestionByContentId, clearRuleForAll } from "@root/questions/actions"; +import { updateOpenedModalSettingsId, } from "@root/uiTools/actions"; import { cleardragQuestionContentId } from "@root/uiTools/actions"; import { withErrorBoundary } from "react-error-boundary"; @@ -660,6 +661,7 @@ let gearsPopper = null gearElement.style.zIndex = "1" gearsContainer.current?.appendChild(gearElement); gearElement.addEventListener("mouseup", (e) => { + console.log("up") updateOpenedModalSettingsId(item.id()) }); @@ -811,7 +813,7 @@ let gearsPopper = null }} autoungrabify={true} /> - + }}>elements */} ); }; diff --git a/src/pages/Questions/BranchingMap/FirstNodeField.tsx b/src/pages/Questions/BranchingMap/FirstNodeField.tsx index ad43d5f2..b86b713f 100644 --- a/src/pages/Questions/BranchingMap/FirstNodeField.tsx +++ b/src/pages/Questions/BranchingMap/FirstNodeField.tsx @@ -1,6 +1,7 @@ import { Box } from "@mui/material" import { useEffect, useRef, useLayoutEffect } from "react"; -import { deleteQuestion, clearRuleForAll, updateQuestion, updateOpenedModalSettingsId } from "@root/questions/actions" +import { deleteQuestion, clearRuleForAll, updateQuestion } from "@root/questions/actions" +import { updateOpenedModalSettingsId } from "@root/uiTools/actions" import { updateRootContentId } from "@root/quizes/actions" import { useCurrentQuiz } from "@root/quizes/hooks" import { useQuestionsStore } from "@root/questions/store" diff --git a/src/pages/Questions/BranchingModal/BranchingQuestionsModal.tsx b/src/pages/Questions/BranchingModal/BranchingQuestionsModal.tsx index 8323aee2..5a5c69f7 100644 --- a/src/pages/Questions/BranchingModal/BranchingQuestionsModal.tsx +++ b/src/pages/Questions/BranchingModal/BranchingQuestionsModal.tsx @@ -22,15 +22,16 @@ import InfoIcon from "@icons/Info"; import { DeleteIcon } from "@icons/questionsPage/deleteIcon"; import { TypeSwitch, BlockRule } from "./Settings"; -import { getQuestionById, getQuestionByContentId, updateOpenedModalSettingsId, updateQuestion } from "@root/questions/actions"; -import { useQuestionsStore } from "@root/questions/store"; +import { getQuestionById, getQuestionByContentId, updateQuestion } from "@root/questions/actions"; +import { updateOpenedModalSettingsId } from "@root/uiTools/actions"; +import { useUiTools } from "@root/uiTools/store"; import { enqueueSnackbar } from "notistack"; export default function BranchingQuestions() { const theme = useTheme(); - const { openedModalSettingsId } = useQuestionsStore(); + const { openedModalSettingsId } = useUiTools(); const [targetQuestion, setTargetQuestion] = useState(getQuestionById(openedModalSettingsId) || getQuestionByContentId(openedModalSettingsId)) const [parentQuestion, setParentQuestion] = useState(getQuestionByContentId(targetQuestion?.content.rule.parentId)) @@ -49,6 +50,8 @@ export default function BranchingQuestions() { setParentQuestion(mutate) } }) + console.log("targetQuestion ", targetQuestion) + console.log("parentQuestion ", parentQuestion) if (targetQuestion === null || parentQuestion === null) { enqueueSnackbar("Невозможно найти данные ветвления для этого вопроса") @@ -164,8 +167,13 @@ export default function BranchingQuestions() { checked={parentQuestion.content.rule.default === targetQuestion.content.id} onClick={() => { + console.log("default ", parentQuestion.content.rule.default) + console.log("следующий вопрос ", targetQuestion.content.id) + console.log("а этот вопрос дефолтный? ", parentQuestion.content.rule.default === targetQuestion.content.id) + + let mutate = JSON.parse(JSON.stringify(parentQuestion)) - mutate.content.rule.default = targetQuestion.id + mutate.content.rule.default = parentQuestion.content.rule.default === targetQuestion.content.id ? "" : targetQuestion.content.id setParentQuestion(mutate) }} />} label="Следующий вопрос по-умолчанию" /> diff --git a/src/pages/Questions/BranchingQuestionsModal/index.tsx b/src/pages/Questions/BranchingQuestionsModal/index.tsx index 007d8395..6f54f49f 100644 --- a/src/pages/Questions/BranchingQuestionsModal/index.tsx +++ b/src/pages/Questions/BranchingQuestionsModal/index.tsx @@ -23,9 +23,10 @@ export const BranchingQuestionsModal = ({ }; const typedQuestions: AnyTypedQuizQuestion[] = questions.filter( - (question) => question.type && !question.content.rule.parentId + (question) => question.type && !question.content.rule.parentId && question.type !== "result" ) as AnyTypedQuizQuestion[]; + if (typedQuestions.length === 0) return <> return ( { - updateOpenBranchingPanel(true); + // updateOpenBranchingPanel(true); updateDesireToOpenABranchingModal(question.content.id); } }, diff --git a/src/pages/Questions/ButtonsOptionsAndPict.tsx b/src/pages/Questions/ButtonsOptionsAndPict.tsx index a6b6ff3e..16e51dc3 100644 --- a/src/pages/Questions/ButtonsOptionsAndPict.tsx +++ b/src/pages/Questions/ButtonsOptionsAndPict.tsx @@ -191,7 +191,7 @@ export default function ButtonsOptionsAndPict({ onMouseEnter={() => setButtonHover("branching")} onMouseLeave={() => setButtonHover("")} onClick={() => { - updateOpenBranchingPanel(true); + // updateOpenBranchingPanel(true); updateDesireToOpenABranchingModal(question.content.id); }} sx={{ diff --git a/src/pages/Questions/DataOptions/settingData.tsx b/src/pages/Questions/DataOptions/settingData.tsx index 750a331d..857ef33c 100644 --- a/src/pages/Questions/DataOptions/settingData.tsx +++ b/src/pages/Questions/DataOptions/settingData.tsx @@ -125,7 +125,7 @@ export default function SettingsData({ question }: SettingsDataProps) { setInnerName(target.value)} + onChange={({ target }) => setInnerName(target.value || " ")} /> )} diff --git a/src/pages/Questions/DraggableList/QuestionPageCard.tsx b/src/pages/Questions/DraggableList/QuestionPageCard.tsx index 65c4fc86..d4ea5342 100644 --- a/src/pages/Questions/DraggableList/QuestionPageCard.tsx +++ b/src/pages/Questions/DraggableList/QuestionPageCard.tsx @@ -102,7 +102,7 @@ export default function QuestionsPageCard({ question, draggableProps, isDragging setTitle(target.value)} + onChange={({ target }: { target: HTMLInputElement; }) => setTitle(target.value || " ")} InputProps={{ startAdornment: ( diff --git a/src/pages/Questions/DropDown/settingDropDown.tsx b/src/pages/Questions/DropDown/settingDropDown.tsx index 9074588d..0bc10a2f 100644 --- a/src/pages/Questions/DropDown/settingDropDown.tsx +++ b/src/pages/Questions/DropDown/settingDropDown.tsx @@ -184,7 +184,7 @@ export default function SettingDropDown({ question }: SettingDropDownProps) { debounced(target.value)} + onChange={({ target }) => debounced(target.value || " ")} /> )} diff --git a/src/pages/Questions/Form/FormDraggableList/index.tsx b/src/pages/Questions/Form/FormDraggableList/index.tsx index 477aad09..9eda5284 100644 --- a/src/pages/Questions/Form/FormDraggableList/index.tsx +++ b/src/pages/Questions/Form/FormDraggableList/index.tsx @@ -3,10 +3,13 @@ import { reorderQuestions } from "@root/questions/actions"; import type { DropResult } from "react-beautiful-dnd"; import { DragDropContext, Droppable } from "react-beautiful-dnd"; import FormDraggableListItem from "./FormDraggableListItem"; +import { useQuestions } from "@root/questions/hooks"; export const FormDraggableList = () => { + const { questions } = useQuestions() + const onDragEnd = ({ destination, source }: DropResult) => { if (destination) reorderQuestions(source.index, destination.index); }; @@ -16,7 +19,7 @@ export const FormDraggableList = () => { {(provided) => ( - {questions.map((question, index) => ( + {questions?.map((question, index) => ( onUpload(target.value)} + onChange={({ target }) => onUpload(target.value || " ")} /> ) : ( @@ -114,7 +114,7 @@ export const UploadVideoModal = ({ { if (target.files?.length) { - onUpload(URL.createObjectURL(target.files[0])); + onUpload(URL.createObjectURL(target.files[0] || " ")); } }} hidden diff --git a/src/pages/Questions/answerOptions/responseSettings.tsx b/src/pages/Questions/answerOptions/responseSettings.tsx index ee594382..b50eff9b 100644 --- a/src/pages/Questions/answerOptions/responseSettings.tsx +++ b/src/pages/Questions/answerOptions/responseSettings.tsx @@ -168,7 +168,7 @@ export default function ResponseSettings({ question }: Props) { sx={{ mr: isMobile ? "0px" : "16px" }} placeholder={"Развёрнутое описание вопроса"} text={question.content.innerName} - onChange={({ target }) => updateQuestionInnerName(target.value)} + onChange={({ target }) => updateQuestionInnerName(target.value || " ")} /> )} diff --git a/src/pages/Questions/helpQuestions.tsx b/src/pages/Questions/helpQuestions.tsx index 6e68264d..08f4d899 100644 --- a/src/pages/Questions/helpQuestions.tsx +++ b/src/pages/Questions/helpQuestions.tsx @@ -62,7 +62,7 @@ export default function HelpQuestions({ question }: HelpQuestionsProps) { updateQuestionHint(target.value)} + onChange={({ target }) => updateQuestionHint(target.value || " ")} /> ) : ( diff --git a/src/pages/ViewPublicationPage/StartPageViewPublication.tsx b/src/pages/ViewPublicationPage/StartPageViewPublication.tsx index a24c1893..2754f88a 100644 --- a/src/pages/ViewPublicationPage/StartPageViewPublication.tsx +++ b/src/pages/ViewPublicationPage/StartPageViewPublication.tsx @@ -144,7 +144,7 @@ export const StartPageViewPublication = ({setVisualStartPage}:Props) => { padding: "10px 15px", width: quiz.config.startpageType === "standard" ? "100%" : "auto" }} - onClick={() => setVisualStartPage(false)} + onClick={() => setVisualStartPage(true)} > {quiz.config.startpage.button.trim() ? quiz.config.startpage.button : "Пройти тест"} diff --git a/src/pages/ViewPublicationPage/index.tsx b/src/pages/ViewPublicationPage/index.tsx index e8a97e1d..bfb86530 100644 --- a/src/pages/ViewPublicationPage/index.tsx +++ b/src/pages/ViewPublicationPage/index.tsx @@ -25,17 +25,17 @@ export const ViewPage = () => { useEffect(() => { const getData = async () => { - const quizes = await quizApi.getList() - setQuizes(quizes) + const quizes = await quizApi.getList() + setQuizes(quizes) - const questions = await questionApi.getList({ quiz_id: editQuizId }) - setQuestions(questions) + const questions = await questionApi.getList({ quiz_id: editQuizId }) + setQuestions(questions) } getData() -}, []) -useEffect(() => { + }, []) + useEffect(() => { setVisualStartPage(quiz?.config.noStartPage) -}, [questions]) + }, [questions]) const [visualStartPage, setVisualStartPage] = useState(); @@ -57,7 +57,7 @@ useEffect(() => { return ( {!visualStartPage ? ( - + ) : ( )} diff --git a/src/pages/createQuize/QuizCard.tsx b/src/pages/createQuize/QuizCard.tsx index 352470a5..f0d4c7ff 100755 --- a/src/pages/createQuize/QuizCard.tsx +++ b/src/pages/createQuize/QuizCard.tsx @@ -156,7 +156,7 @@ export default function QuizCard({ anchorOrigin={{ vertical: "top", horizontal: "right" }} > setSubMenuOpen(false)}> - + */}