fix: View Date(WIP)

This commit is contained in:
IlyaDoronin 2023-12-05 16:46:31 +03:00
parent 5c5ef3fac2
commit bd36307e86
2 changed files with 22 additions and 3 deletions

@ -290,7 +290,12 @@ const DateInputsType = ({ parentQuestion, targetQuestion, ruleIndex, setParentQu
} }
<DatePicker <DatePicker
value={parentQuestion.content.rule.main[ruleIndex].rules[0].answers[0]} value={parentQuestion.content.rule.main[ruleIndex].rules[0].answers[0]}
onChange={(e) => console.log(e)} onChange={(dateString) => {
const date = dateString?.$d?.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)
}}
slots={{ slots={{
openPickerIcon: () => <CalendarIcon />, openPickerIcon: () => <CalendarIcon />,
}} }}

@ -13,7 +13,10 @@ type DateProps = {
export const Date = ({ currentQuestion }: DateProps) => { export const Date = ({ currentQuestion }: DateProps) => {
const { answers } = useQuizViewStore(); const { answers } = useQuizViewStore();
const { answer } = answers.find(({ questionId }) => questionId === currentQuestion.content.id) ?? {}; const { answer } =
answers.find(
({ questionId }) => questionId === currentQuestion.content.id
) ?? {};
return ( return (
<Box> <Box>
@ -28,7 +31,18 @@ export const Date = ({ currentQuestion }: DateProps) => {
> >
<DatePicker <DatePicker
selected={answer ? new window.Date(answer) : new window.Date()} selected={answer ? new window.Date(answer) : new window.Date()}
onChange={(date) => updateAnswer(currentQuestion.content.id, String(date))} onChange={(date) =>
updateAnswer(
currentQuestion.content.id,
String(
date?.toLocaleDateString("ru-RU", {
year: "numeric",
month: "2-digit",
day: "2-digit",
})
)
)
}
/> />
</Box> </Box>
</Box> </Box>