открытие модалки ветвления через стор(в процессе)

This commit is contained in:
Tamara 2023-07-14 14:43:28 +03:00
parent b656a3b3ae
commit 16468c601f
4 changed files with 39 additions and 15 deletions

@ -19,7 +19,10 @@ interface Props {
export default function ButtonsOptionsAndPict({ SSHC, switchState, totalIndex }: Props) { export default function ButtonsOptionsAndPict({ SSHC, switchState, totalIndex }: Props) {
const params = Number(useParams().quizId); const params = Number(useParams().quizId);
const {listQuestions, updateQuestionsList, createQuestion, removeQuestion} = questionStore() const {listQuestions, updateQuestionsList, createQuestion, removeQuestion, openedModalSettings} = questionStore()
const openedModal = () => {
}
const theme = useTheme(); const theme = useTheme();
return ( return (
<Box <Box

@ -1,5 +1,5 @@
import {Box, Typography, Link, useTheme, TextField, FormControl, InputAdornment, IconButton} from "@mui/material"; import {Box, Typography, Link, useTheme, TextField, FormControl, InputAdornment, IconButton} from "@mui/material";
import React from "react"; import React, {useState} from "react";
import EnterIcon from "../../../assets/icons/questionsPage/enterIcon"; import EnterIcon from "../../../assets/icons/questionsPage/enterIcon";
import SwitchAnswerOptions from "./switchAnswerOptions"; import SwitchAnswerOptions from "./switchAnswerOptions";
import ButtonsOptionsAndPict from "../ButtonsOptionsAndPict"; import ButtonsOptionsAndPict from "../ButtonsOptionsAndPict";
@ -28,7 +28,9 @@ export default function AnswerOptions({totalIndex}: Props) {
const SSHC = (data: string) => { const SSHC = (data: string) => {
setSwitchState(data) setSwitchState(data)
} }
// const [openBranch, setOpenBranch] = useState(false);
// const handleOpenBranch = () => setOpenBranch(true);
// const handleCloseBranch = () => setOpenBranch(false);
const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null); const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null);
@ -66,12 +68,12 @@ export default function AnswerOptions({totalIndex}: Props) {
sx={{ p: "0 0 20px 0" }} sx={{ p: "0 0 20px 0" }}
> >
<TextField <TextField
value={Answer[index]} value={Answer[index].answer}
fullWidth fullWidth
placeholder={"Добавьте ответ"} placeholder={"Добавьте ответ"}
onChange={(e) => { onChange={(e) => {
const answerNew = Answer const answerNew = Answer
answerNew[index] = e.target.value answerNew[index].answer = e.target.value
let clonContent = listQuestions[params][totalIndex].content let clonContent = listQuestions[params][totalIndex].content
clonContent.variants = answerNew clonContent.variants = answerNew
updateQuestionsList(params, totalIndex, {content: clonContent})}} updateQuestionsList(params, totalIndex, {content: clonContent})}}
@ -96,7 +98,14 @@ export default function AnswerOptions({totalIndex}: Props) {
horizontal: 'left', horizontal: 'left',
}} }}
> >
<TextareaAutosize style={{margin: "10px"}} placeholder="Подсказка для этого ответа" /> <TextareaAutosize style={{margin: "10px"}} placeholder="Подсказка для этого ответа" value={Answer[index].hints}
onChange={(e) => {
const answerNew = Answer
answerNew[index].hints = e.target.value
let clonContent = listQuestions[params][totalIndex].content
clonContent.variants = answerNew
updateQuestionsList(params, totalIndex, {content: clonContent})}}
/>
</Popover> </Popover>
<IconButton <IconButton
onClick={() => { onClick={() => {
@ -142,7 +151,7 @@ export default function AnswerOptions({totalIndex}: Props) {
sx={{color: theme.palette.brightPurple.main}} sx={{color: theme.palette.brightPurple.main}}
onClick={() => { onClick={() => {
const answerNew = Answer const answerNew = Answer
answerNew.push("") answerNew.push({answer: "",})
let clonContent = listQuestions[params][totalIndex].content let clonContent = listQuestions[params][totalIndex].content
clonContent.variants = answerNew clonContent.variants = answerNew
updateQuestionsList(params, totalIndex, {content: clonContent}) updateQuestionsList(params, totalIndex, {content: clonContent})

@ -24,10 +24,10 @@ import RadioIcon from "@ui_kit/RadioIcon";
export default function BranchingQuestions() { export default function BranchingQuestions() {
const theme = useTheme(); const theme = useTheme();
const [open, setOpen] = useState(false); // const [open, setOpen] = useState(false);
const [condition, setCondition] = useState<boolean>(false); const [condition, setCondition] = useState<boolean>(false);
const handleOpen = () => setOpen(true); // const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false); // const handleClose = () => setOpen(false);
const [display, setDisplay] = React.useState("1"); const [display, setDisplay] = React.useState("1");
const handleChange = (event: SelectChangeEvent) => { const handleChange = (event: SelectChangeEvent) => {
@ -41,10 +41,9 @@ export default function BranchingQuestions() {
}; };
return ( return (
<> <>
<Button onClick={handleOpen}>открыть</Button>
<Modal <Modal
open={open} open={openBranch}
onClose={handleClose} onClose={handleCloseBranch}
aria-labelledby="modal-modal-title" aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description" aria-describedby="modal-modal-description"
> >
@ -260,7 +259,7 @@ export default function BranchingQuestions() {
<Box sx={{ display: "flex", justifyContent: "end", gap: "10px" }}> <Box sx={{ display: "flex", justifyContent: "end", gap: "10px" }}>
<Button <Button
variant="outlined" variant="outlined"
onClick={handleClose} onClick={handleCloseBranch}
> >
Отмена Отмена
</Button> </Button>

@ -6,6 +6,7 @@ interface QuestionStore {
updateQuestionsList: (id: number, index: number, values: unknown) => void; updateQuestionsList: (id: number, index: number, values: unknown) => void;
removeQuestion: any; removeQuestion: any;
createQuestion: (id: number) => void; createQuestion: (id: number) => void;
openedModalSettings: any
} }
export const questionStore = create<QuestionStore>()( export const questionStore = create<QuestionStore>()(
@ -39,7 +40,11 @@ export const questionStore = create<QuestionStore>()(
"page": 0, "page": 0,
"content": { "content": {
variants: [ variants: [
{
answer: "",
answerLong: "",
hints: ""
}
], ],
own: true, own: true,
multi: true multi: true
@ -64,6 +69,14 @@ export const questionStore = create<QuestionStore>()(
state[id] = array state[id] = array
set({listQuestions: state}); set({listQuestions: state});
}, },
openedModalSettings: [],
createOpenedModalSettings: (id: number) => {
const state = get()["openedModalSettings"] || [];
state.push(String(id))
set({openedModalSettings: state})
}
}), }),
{ {