feat: Branching Data logic

This commit is contained in:
IlyaDoronin 2023-12-05 22:55:21 +03:00
parent 7573f7a3e3
commit 0890d5a67c
3 changed files with 12 additions and 6 deletions

@ -10,7 +10,7 @@ import { AnyTypedQuizQuestion } from "../../../model/questionTypes/shared"
import { SelectChangeEvent } from '@mui/material/Select';
import CalendarIcon from "@icons/CalendarIcon";
import { DatePicker } from "@mui/x-date-pickers";
import * as dayjs from 'dayjs'
import dayjs from 'dayjs'
import { TimePicker } from '@mui/x-date-pickers/TimePicker';
import InfoIcon from "@icons/Info";
import { DeleteIcon } from "@icons/questionsPage/deleteIcon";
@ -289,12 +289,12 @@ const DateInputsType = ({ parentQuestion, targetQuestion, ruleIndex, setParentQu
</Typography>
}
<DatePicker
value={parentQuestion.content.rule.main[ruleIndex].rules[0].answers[0]}
defaultValue={dayjs(new Date(parentQuestion.content.rule.main[ruleIndex].rules[0].answers[0]).toLocaleDateString())}
onChange={(dateString) => {
const date = dateString?.$d?.toLocaleDateString("ru-RU", { year: "numeric", month: "2-digit", day: "2-digit" });
const date = dateString?.toDate().toLocaleDateString("ru-RU", { year: "numeric", month: "2-digit", day: "2-digit" });
let newParentQuestion = JSON.parse(JSON.stringify(parentQuestion))
newParentQuestion.content.rule.main[ruleIndex].rules[0].answers = [date]
// setParentQuestion(newParentQuestion)
setParentQuestion(newParentQuestion)
}}
slots={{
openPickerIcon: () => <CalendarIcon />,

@ -56,7 +56,8 @@ const {openBranchingPanel} = useQuestionsStore.getState()
return enqueueSnackbar("У корня нет условий ветвления")
}
if (parentId.length !== 0) {
updateOpenBranchingPanel(value)
// updateOpenBranchingPanel(value)
openedModal()
}
}

@ -17,6 +17,7 @@ export const Date = ({ currentQuestion }: DateProps) => {
answers.find(
({ questionId }) => questionId === currentQuestion.content.id
) ?? {};
const [day, month, year] = answer?.split(".") || [];
return (
<Box>
@ -30,7 +31,11 @@ export const Date = ({ currentQuestion }: DateProps) => {
}}
>
<DatePicker
selected={answer ? new window.Date(answer) : new window.Date()}
selected={
answer
? new window.Date(`${month}.${day}.${year}`)
: new window.Date()
}
onChange={(date) =>
updateAnswer(
currentQuestion.content.id,