type store update
This commit is contained in:
parent
e978bb09c6
commit
a6640f75fa
@ -24,14 +24,13 @@ import RadioIcon from "@ui_kit/RadioIcon";
|
||||
import { questionStore, resetSomeField } from "@root/questions";
|
||||
|
||||
export default function BranchingQuestions() {
|
||||
const {openedModalSettings} = questionStore()
|
||||
const theme = useTheme();
|
||||
const { openedModalSettings } = questionStore();
|
||||
const theme = useTheme();
|
||||
|
||||
const [condition, setCondition] = useState<boolean>(false);
|
||||
const handleClose = () => {
|
||||
resetSomeField({openedModalSettings: ""})
|
||||
|
||||
}
|
||||
resetSomeField({ openedModalSettings: "" });
|
||||
};
|
||||
const [display, setDisplay] = React.useState("1");
|
||||
const handleChange = (event: SelectChangeEvent) => {
|
||||
setDisplay(event.target.value);
|
||||
@ -170,7 +169,7 @@ export default function BranchingQuestions() {
|
||||
<Box sx={{ display: "flex", justifyContent: "space-between", alignItems: "center", pb: "14px" }}>
|
||||
<Typography>Условие 1</Typography>
|
||||
<IconButton sx={{ borderRadius: "6px", padding: "2px" }}>
|
||||
<DeleteIcon color={"#4D4D4D"}/>
|
||||
<DeleteIcon color={"#4D4D4D"} />
|
||||
</IconButton>
|
||||
</Box>
|
||||
|
||||
@ -247,29 +246,23 @@ export default function BranchingQuestions() {
|
||||
<FormControlLabel
|
||||
sx={{ color: theme.palette.grey2.main }}
|
||||
value="1"
|
||||
control={<Radio checkedIcon={<RadioCheck/>} icon={<RadioIcon/>}/>}
|
||||
control={<Radio checkedIcon={<RadioCheck />} icon={<RadioIcon />} />}
|
||||
label="Все условия обязательны"
|
||||
/>
|
||||
<FormControlLabel
|
||||
sx={{ color: theme.palette.grey2.main }}
|
||||
value="2"
|
||||
control={<Radio checkedIcon={<RadioCheck/>} icon={<RadioIcon/>}/>}
|
||||
control={<Radio checkedIcon={<RadioCheck />} icon={<RadioIcon />} />}
|
||||
label="Обязательно хотя бы одно условие"
|
||||
/>
|
||||
</RadioGroup>
|
||||
</FormControl>
|
||||
</Box>
|
||||
<Box sx={{ display: "flex", justifyContent: "end", gap: "10px" }}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
onClick={handleClose}
|
||||
>
|
||||
<Button variant="outlined" onClick={handleClose}>
|
||||
Отмена
|
||||
</Button>
|
||||
<Button
|
||||
variant="contained">
|
||||
Готово
|
||||
</Button>
|
||||
<Button variant="contained">Готово</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
|
@ -2,7 +2,7 @@ import React, { useRef, useState } from "react";
|
||||
import { Box, Paper, Typography } from "@mui/material";
|
||||
import { useDrag, useDrop } from "react-dnd";
|
||||
import QuestionsPageCard from "./QuestionPageCard";
|
||||
import { questionStore, updateQuestionsLists } from "@root/questions";
|
||||
import { questionStore, updateQuestionsListDragAndDrop } from "@root/questions";
|
||||
import IconPlus from "@icons/IconPlus";
|
||||
|
||||
export const ItemTypes = {
|
||||
@ -117,9 +117,11 @@ const QuestionList: React.FC = () => {
|
||||
const updatedQuestions = [...listQuestions];
|
||||
const [movedItem] = updatedQuestions.splice(fromIndex, 1);
|
||||
updatedQuestions.splice(toIndex, 0, movedItem);
|
||||
updateQuestionsLists(updatedQuestions);
|
||||
updateQuestionsListDragAndDrop(updatedQuestions);
|
||||
};
|
||||
|
||||
console.log(listQuestions);
|
||||
|
||||
return (
|
||||
<Box>
|
||||
{listQuestions.map((event: any, index: number) => (
|
||||
|
@ -12,7 +12,7 @@ interface Question {
|
||||
title: string;
|
||||
description: string;
|
||||
type: string;
|
||||
required: true;
|
||||
required: boolean;
|
||||
deleted: true;
|
||||
page: number;
|
||||
content: {
|
||||
@ -43,13 +43,13 @@ export const questionStore = create<QuestionStore>()(
|
||||
}
|
||||
)
|
||||
);
|
||||
export const updateQuestionsList = (index: number, data: any) => {
|
||||
export const updateQuestionsList = (index: number, data: Partial<Question>) => {
|
||||
const array = [...questionStore.getState()["listQuestions"]];
|
||||
array.splice(index, 1, { ...array[index], ...data });
|
||||
questionStore.setState({ listQuestions: array });
|
||||
};
|
||||
|
||||
export const updateQuestionsLists = (updatedQuestions: any[]) => {
|
||||
export const updateQuestionsListDragAndDrop = (updatedQuestions: Question[]) => {
|
||||
questionStore.setState({ listQuestions: updatedQuestions });
|
||||
};
|
||||
|
||||
@ -89,14 +89,14 @@ export const removeQuestion = (index: number) => {
|
||||
questionStore.setState({ listQuestions: array });
|
||||
};
|
||||
|
||||
export const resetSomeField = (data: any) => {
|
||||
export const resetSomeField = (data: Record<string, string>) => {
|
||||
questionStore.setState(data);
|
||||
};
|
||||
|
||||
export const findQuestionById = (id_question: number): null | any => {
|
||||
export const findQuestionById = (id_question: number) => {
|
||||
let found = null;
|
||||
questionStore.getState()["listQuestions"].some((quiz: any, index: number) => {
|
||||
if (quiz.id_question === id_question) {
|
||||
questionStore.getState()["listQuestions"].some((quiz: Question, index: number) => {
|
||||
if (quiz.id === id_question) {
|
||||
found = { quiz, index };
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user