type store update

This commit is contained in:
ArtChaos189 2023-07-30 18:35:40 +03:00
parent e978bb09c6
commit a6640f75fa
3 changed files with 20 additions and 25 deletions

@ -24,14 +24,13 @@ import RadioIcon from "@ui_kit/RadioIcon";
import { questionStore, resetSomeField } from "@root/questions"; import { questionStore, resetSomeField } from "@root/questions";
export default function BranchingQuestions() { export default function BranchingQuestions() {
const {openedModalSettings} = questionStore() const { openedModalSettings } = questionStore();
const theme = useTheme(); const theme = useTheme();
const [condition, setCondition] = useState<boolean>(false); const [condition, setCondition] = useState<boolean>(false);
const handleClose = () => { const handleClose = () => {
resetSomeField({openedModalSettings: ""}) resetSomeField({ openedModalSettings: "" });
};
}
const [display, setDisplay] = React.useState("1"); const [display, setDisplay] = React.useState("1");
const handleChange = (event: SelectChangeEvent) => { const handleChange = (event: SelectChangeEvent) => {
setDisplay(event.target.value); setDisplay(event.target.value);
@ -170,7 +169,7 @@ export default function BranchingQuestions() {
<Box sx={{ display: "flex", justifyContent: "space-between", alignItems: "center", pb: "14px" }}> <Box sx={{ display: "flex", justifyContent: "space-between", alignItems: "center", pb: "14px" }}>
<Typography>Условие 1</Typography> <Typography>Условие 1</Typography>
<IconButton sx={{ borderRadius: "6px", padding: "2px" }}> <IconButton sx={{ borderRadius: "6px", padding: "2px" }}>
<DeleteIcon color={"#4D4D4D"}/> <DeleteIcon color={"#4D4D4D"} />
</IconButton> </IconButton>
</Box> </Box>
@ -247,29 +246,23 @@ export default function BranchingQuestions() {
<FormControlLabel <FormControlLabel
sx={{ color: theme.palette.grey2.main }} sx={{ color: theme.palette.grey2.main }}
value="1" value="1"
control={<Radio checkedIcon={<RadioCheck/>} icon={<RadioIcon/>}/>} control={<Radio checkedIcon={<RadioCheck />} icon={<RadioIcon />} />}
label="Все условия обязательны" label="Все условия обязательны"
/> />
<FormControlLabel <FormControlLabel
sx={{ color: theme.palette.grey2.main }} sx={{ color: theme.palette.grey2.main }}
value="2" value="2"
control={<Radio checkedIcon={<RadioCheck/>} icon={<RadioIcon/>}/>} control={<Radio checkedIcon={<RadioCheck />} icon={<RadioIcon />} />}
label="Обязательно хотя бы одно условие" label="Обязательно хотя бы одно условие"
/> />
</RadioGroup> </RadioGroup>
</FormControl> </FormControl>
</Box> </Box>
<Box sx={{ display: "flex", justifyContent: "end", gap: "10px" }}> <Box sx={{ display: "flex", justifyContent: "end", gap: "10px" }}>
<Button <Button variant="outlined" onClick={handleClose}>
variant="outlined"
onClick={handleClose}
>
Отмена Отмена
</Button> </Button>
<Button <Button variant="contained">Готово</Button>
variant="contained">
Готово
</Button>
</Box> </Box>
</Box> </Box>
</Box> </Box>

@ -2,7 +2,7 @@ import React, { useRef, useState } from "react";
import { Box, Paper, Typography } from "@mui/material"; import { Box, Paper, Typography } from "@mui/material";
import { useDrag, useDrop } from "react-dnd"; import { useDrag, useDrop } from "react-dnd";
import QuestionsPageCard from "./QuestionPageCard"; import QuestionsPageCard from "./QuestionPageCard";
import { questionStore, updateQuestionsLists } from "@root/questions"; import { questionStore, updateQuestionsListDragAndDrop } from "@root/questions";
import IconPlus from "@icons/IconPlus"; import IconPlus from "@icons/IconPlus";
export const ItemTypes = { export const ItemTypes = {
@ -117,9 +117,11 @@ const QuestionList: React.FC = () => {
const updatedQuestions = [...listQuestions]; const updatedQuestions = [...listQuestions];
const [movedItem] = updatedQuestions.splice(fromIndex, 1); const [movedItem] = updatedQuestions.splice(fromIndex, 1);
updatedQuestions.splice(toIndex, 0, movedItem); updatedQuestions.splice(toIndex, 0, movedItem);
updateQuestionsLists(updatedQuestions); updateQuestionsListDragAndDrop(updatedQuestions);
}; };
console.log(listQuestions);
return ( return (
<Box> <Box>
{listQuestions.map((event: any, index: number) => ( {listQuestions.map((event: any, index: number) => (

@ -12,7 +12,7 @@ interface Question {
title: string; title: string;
description: string; description: string;
type: string; type: string;
required: true; required: boolean;
deleted: true; deleted: true;
page: number; page: number;
content: { 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"]]; const array = [...questionStore.getState()["listQuestions"]];
array.splice(index, 1, { ...array[index], ...data }); array.splice(index, 1, { ...array[index], ...data });
questionStore.setState({ listQuestions: array }); questionStore.setState({ listQuestions: array });
}; };
export const updateQuestionsLists = (updatedQuestions: any[]) => { export const updateQuestionsListDragAndDrop = (updatedQuestions: Question[]) => {
questionStore.setState({ listQuestions: updatedQuestions }); questionStore.setState({ listQuestions: updatedQuestions });
}; };
@ -89,14 +89,14 @@ export const removeQuestion = (index: number) => {
questionStore.setState({ listQuestions: array }); questionStore.setState({ listQuestions: array });
}; };
export const resetSomeField = (data: any) => { export const resetSomeField = (data: Record<string, string>) => {
questionStore.setState(data); questionStore.setState(data);
}; };
export const findQuestionById = (id_question: number): null | any => { export const findQuestionById = (id_question: number) => {
let found = null; let found = null;
questionStore.getState()["listQuestions"].some((quiz: any, index: number) => { questionStore.getState()["listQuestions"].some((quiz: Question, index: number) => {
if (quiz.id_question === id_question) { if (quiz.id === id_question) {
found = { quiz, index }; found = { quiz, index };
return true; return true;
} }