feat: DeleteNodeModal
This commit is contained in:
parent
ddc73f47a2
commit
283a73d8e4
@ -20,6 +20,9 @@ import {
|
||||
} from "@root/questions/actions";
|
||||
import { updateOpenedModalSettingsId } from "@root/uiTools/actions";
|
||||
import { cleardragQuestionContentId } from "@root/uiTools/actions";
|
||||
import { updateDeleteId } from "@root/uiTools/actions";
|
||||
|
||||
import { DeleteNodeModal } from "../DeleteNodeModal";
|
||||
|
||||
import { useRemoveNode } from "./hooks/useRemoveNode";
|
||||
import { usePopper } from "./hooks/usePopper";
|
||||
@ -229,7 +232,7 @@ function CsComponent({
|
||||
|
||||
useEffect(() => {
|
||||
if (startRemove) {
|
||||
removeNode(startRemove);
|
||||
updateDeleteId(startRemove);
|
||||
setStartRemove("");
|
||||
}
|
||||
}, [startRemove]);
|
||||
@ -293,6 +296,7 @@ function CsComponent({
|
||||
}}
|
||||
autoungrabify={true}
|
||||
/>
|
||||
<DeleteNodeModal />
|
||||
{/* <button onClick={() => {
|
||||
console.log("NODES____________________________")
|
||||
cyRef.current?.elements().forEach((ele: any) => {
|
||||
|
@ -2,40 +2,53 @@ import { Box } from "@mui/material";
|
||||
import { FirstNodeField } from "./FirstNodeField";
|
||||
import CsComponent from "./CsComponent";
|
||||
import { useCurrentQuiz } from "@root/quizes/hooks";
|
||||
import { useState } from "react";
|
||||
import {BranchingQuestionsModal} from "../BranchingQuestionsModal"
|
||||
import { useEffect, useState } from "react";
|
||||
import { BranchingQuestionsModal } from "../BranchingQuestionsModal";
|
||||
import { useUiTools } from "@root/uiTools/store";
|
||||
|
||||
|
||||
export const BranchingMap = () => {
|
||||
const quiz = useCurrentQuiz();
|
||||
const { dragQuestionContentId } = useUiTools()
|
||||
const [modalQuestionParentContentId, setModalQuestionParentContentId] = useState<string>("")
|
||||
const [modalQuestionTargetContentId, setModalQuestionTargetContentId] = useState<string>("")
|
||||
const [openedModalQuestions, setOpenedModalQuestions] = useState<boolean>(false)
|
||||
const { dragQuestionContentId } = useUiTools();
|
||||
const [modalQuestionParentContentId, setModalQuestionParentContentId] =
|
||||
useState<string>("");
|
||||
const [modalQuestionTargetContentId, setModalQuestionTargetContentId] =
|
||||
useState<string>("");
|
||||
const [openedModalQuestions, setOpenedModalQuestions] =
|
||||
useState<boolean>(false);
|
||||
|
||||
return (
|
||||
<Box
|
||||
id="cytoscape-container"
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
padding: "20px",
|
||||
background: "#FFFFFF",
|
||||
borderRadius: "12px",
|
||||
boxShadow: "0px 8px 24px rgba(210, 208, 225, 0.4)",
|
||||
marginBottom: "40px",
|
||||
height: "568px",
|
||||
border: dragQuestionContentId === null ? "none" : "#7e2aea 2px dashed"
|
||||
}}
|
||||
>
|
||||
|
||||
{
|
||||
quiz?.config.haveRoot ?
|
||||
<CsComponent modalQuestionParentContentId={modalQuestionParentContentId} modalQuestionTargetContentId={modalQuestionTargetContentId} setOpenedModalQuestions={setOpenedModalQuestions} setModalQuestionParentContentId={setModalQuestionParentContentId} setModalQuestionTargetContentId={setModalQuestionTargetContentId}/>
|
||||
:
|
||||
<FirstNodeField setOpenedModalQuestions={setOpenedModalQuestions} modalQuestionTargetContentId={modalQuestionTargetContentId}/>
|
||||
}
|
||||
<BranchingQuestionsModal openedModalQuestions={openedModalQuestions} setOpenedModalQuestions={setOpenedModalQuestions} setModalQuestionTargetContentId={setModalQuestionTargetContentId} />
|
||||
</Box>
|
||||
<Box
|
||||
id="cytoscape-container"
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
padding: "20px",
|
||||
background: "#FFFFFF",
|
||||
borderRadius: "12px",
|
||||
boxShadow: "0px 8px 24px rgba(210, 208, 225, 0.4)",
|
||||
marginBottom: "40px",
|
||||
height: "568px",
|
||||
border: dragQuestionContentId === null ? "none" : "#7e2aea 2px dashed",
|
||||
}}
|
||||
>
|
||||
{quiz?.config.haveRoot ? (
|
||||
<CsComponent
|
||||
modalQuestionParentContentId={modalQuestionParentContentId}
|
||||
modalQuestionTargetContentId={modalQuestionTargetContentId}
|
||||
setOpenedModalQuestions={setOpenedModalQuestions}
|
||||
setModalQuestionParentContentId={setModalQuestionParentContentId}
|
||||
setModalQuestionTargetContentId={setModalQuestionTargetContentId}
|
||||
/>
|
||||
) : (
|
||||
<FirstNodeField
|
||||
setOpenedModalQuestions={setOpenedModalQuestions}
|
||||
modalQuestionTargetContentId={modalQuestionTargetContentId}
|
||||
/>
|
||||
)}
|
||||
<BranchingQuestionsModal
|
||||
openedModalQuestions={openedModalQuestions}
|
||||
setOpenedModalQuestions={setOpenedModalQuestions}
|
||||
setModalQuestionTargetContentId={setModalQuestionTargetContentId}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
@ -23,10 +23,14 @@ export const BranchingQuestionsModal = ({
|
||||
};
|
||||
|
||||
const typedQuestions: AnyTypedQuizQuestion[] = questions.filter(
|
||||
(question) => question.type && !question.content.rule.parentId && question.type !== "result"
|
||||
(question) =>
|
||||
question.type &&
|
||||
!question.content.rule.parentId &&
|
||||
question.type !== "result"
|
||||
) as AnyTypedQuizQuestion[];
|
||||
|
||||
if (typedQuestions.length === 0) return <></>
|
||||
if (typedQuestions.length === 0) return <></>;
|
||||
|
||||
return (
|
||||
<Modal open={openedModalQuestions} onClose={handleClose}>
|
||||
<Box
|
||||
@ -42,7 +46,7 @@ export const BranchingQuestionsModal = ({
|
||||
borderRadius: "12px",
|
||||
boxShadow: 24,
|
||||
padding: "30px 0",
|
||||
height: "80vh"
|
||||
height: "80vh",
|
||||
}}
|
||||
>
|
||||
<Box sx={{ margin: "0 auto", maxWidth: "350px" }}>
|
||||
|
122
src/pages/Questions/DeleteNodeModal/index.tsx
Normal file
122
src/pages/Questions/DeleteNodeModal/index.tsx
Normal file
@ -0,0 +1,122 @@
|
||||
import { useState, useRef, useEffect, useLayoutEffect } from "react";
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
FormControl,
|
||||
FormControlLabel,
|
||||
Link,
|
||||
Modal,
|
||||
Radio,
|
||||
RadioGroup,
|
||||
Tooltip,
|
||||
Typography,
|
||||
useTheme,
|
||||
Checkbox,
|
||||
} from "@mui/material";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import {
|
||||
AnyTypedQuizQuestion,
|
||||
createBranchingRuleMain,
|
||||
} from "../../../model/questionTypes/shared";
|
||||
import { Select } from "../Select";
|
||||
|
||||
import RadioCheck from "@ui_kit/RadioCheck";
|
||||
import RadioIcon from "@ui_kit/RadioIcon";
|
||||
import InfoIcon from "@icons/Info";
|
||||
import { DeleteIcon } from "@icons/questionsPage/deleteIcon";
|
||||
|
||||
import {
|
||||
getQuestionById,
|
||||
getQuestionByContentId,
|
||||
updateQuestion,
|
||||
} from "@root/questions/actions";
|
||||
import { updateOpenedModalSettingsId } from "@root/uiTools/actions";
|
||||
import { useUiTools } from "@root/uiTools/store";
|
||||
|
||||
export const DeleteNodeModal = () => {
|
||||
const { deleteNodeId } = useUiTools();
|
||||
const targetQuestion = getQuestionById(deleteNodeId);
|
||||
|
||||
const saveData = () => {
|
||||
// if (parentQuestion !== null) {
|
||||
// updateQuestion(
|
||||
// parentQuestion.content.id,
|
||||
// (question) => (question.content = parentQuestion.content)
|
||||
// );
|
||||
// }
|
||||
// handleClose();
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
updateOpenedModalSettingsId();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal open={!!deleteNodeId} onClose={handleClose}>
|
||||
<Box
|
||||
sx={{
|
||||
position: "absolute",
|
||||
overflow: "hidden",
|
||||
top: "50%",
|
||||
left: "50%",
|
||||
transform: "translate(-50%, -50%)",
|
||||
maxWidth: "620px",
|
||||
width: "100%",
|
||||
bgcolor: "background.paper",
|
||||
borderRadius: "12px",
|
||||
boxShadow: 24,
|
||||
p: 0,
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
boxSizing: "border-box",
|
||||
background: "#F2F3F7",
|
||||
height: "70px",
|
||||
padding: "0 25px",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<Box sx={{ color: "#4d4d4d" }}>
|
||||
<Typography component="span">{targetQuestion?.title}</Typography>
|
||||
</Box>
|
||||
<Tooltip
|
||||
title="Настройте условия, при которых данный вопрос будет отображаться в квизе."
|
||||
placement="top"
|
||||
>
|
||||
<Box>
|
||||
<InfoIcon />
|
||||
</Box>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
justifyContent: "end",
|
||||
gap: "10px",
|
||||
margin: "20px",
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
variant="outlined"
|
||||
onClick={handleClose}
|
||||
sx={{ width: "100%", maxWidth: "130px" }}
|
||||
>
|
||||
Отмена
|
||||
</Button>
|
||||
<Button
|
||||
variant="contained"
|
||||
sx={{ width: "100%", maxWidth: "130px" }}
|
||||
onClick={saveData}
|
||||
>
|
||||
Готово
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
@ -31,4 +31,5 @@ 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 updateDeleteId = (deleteNodeId: string | null = null) => useUiTools.setState({ deleteNodeId });
|
||||
|
@ -1,32 +1,30 @@
|
||||
import { create } from "zustand";
|
||||
import { devtools } from "zustand/middleware";
|
||||
|
||||
|
||||
export type UiTools = {
|
||||
openedModalSettingsId: string | null;
|
||||
dragQuestionContentId: string | null;
|
||||
openBranchingPanel: boolean;
|
||||
desireToOpenABranchingModal: string | null;
|
||||
editSomeQuestion: string | null;
|
||||
lastDeletionNodeTime: number | null;
|
||||
openedModalSettingsId: string | null;
|
||||
dragQuestionContentId: string | null;
|
||||
openBranchingPanel: boolean;
|
||||
desireToOpenABranchingModal: string | null;
|
||||
editSomeQuestion: string | null;
|
||||
lastDeletionNodeTime: number | null;
|
||||
deleteNodeId: string | null;
|
||||
};
|
||||
|
||||
const initialState: UiTools = {
|
||||
openedModalSettingsId: null,
|
||||
dragQuestionContentId: null,
|
||||
openBranchingPanel: false,
|
||||
desireToOpenABranchingModal: null,
|
||||
editSomeQuestion: null,
|
||||
lastDeletionNodeTime: null
|
||||
openedModalSettingsId: null,
|
||||
dragQuestionContentId: null,
|
||||
openBranchingPanel: false,
|
||||
desireToOpenABranchingModal: null,
|
||||
editSomeQuestion: null,
|
||||
lastDeletionNodeTime: null,
|
||||
deleteNodeId: null,
|
||||
};
|
||||
|
||||
export const useUiTools = create<UiTools>()(
|
||||
devtools(
|
||||
() => initialState,
|
||||
{
|
||||
name: "UiTools",
|
||||
enabled: process.env.NODE_ENV === "development",
|
||||
trace: process.env.NODE_ENV === "development",
|
||||
}
|
||||
)
|
||||
devtools(() => initialState, {
|
||||
name: "UiTools",
|
||||
enabled: process.env.NODE_ENV === "development",
|
||||
trace: process.env.NODE_ENV === "development",
|
||||
})
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user