fix: date

This commit is contained in:
IlyaDoronin 2024-01-09 13:17:56 +03:00
parent df877e4624
commit 2e7e61ec2a

@ -9,7 +9,7 @@ import type { QuizQuestionDate } from "../../../model/questionTypes/date";
import CalendarIcon from "@icons/CalendarIcon";
import { enqueueSnackbar } from "notistack";
import { sendAnswer } from "@api/quizRelase";
import { useQuestionsStore } from "@root/quizData/store"
import { useQuestionsStore } from "@root/quizData/store";
type DateProps = {
currentQuestion: QuizQuestionDate;
@ -19,7 +19,7 @@ export const Date = ({ currentQuestion }: DateProps) => {
const theme = useTheme();
const mode = modes;
const { settings } = useQuestionsStore()
const { settings } = useQuestionsStore();
const { answers } = useQuizViewStore();
const answer = answers.find(
({ questionId }) => questionId === currentQuestion.id
@ -28,7 +28,9 @@ export const Date = ({ currentQuestion }: DateProps) => {
return (
<Box>
<Typography variant="h5" color={theme.palette.text.primary}>{currentQuestion.title}</Typography>
<Typography variant="h5" color={theme.palette.text.primary}>
{currentQuestion.title}
</Typography>
<Box
sx={{
display: "flex",
@ -40,13 +42,17 @@ export const Date = ({ currentQuestion }: DateProps) => {
<DatePicker
slots={{
//@ts-ignore
openPickerIcon: () => <CalendarIcon sx={{
"& path": {stroke: theme.palette.primary.main},
"& rect": {stroke: theme.palette.primary.main}
}} />,
openPickerIcon: () => (
<CalendarIcon
sx={{
"& path": { stroke: theme.palette.primary.main },
"& rect": { stroke: theme.palette.primary.main },
}}
/>
),
}}
value={dayjs(
answer
month && day && year
? new window.Date(`${month}.${day}.${year}`)
: new window.Date()
)}
@ -54,19 +60,22 @@ export const Date = ({ currentQuestion }: DateProps) => {
if (!date) {
return;
}
try {
await sendAnswer({
questionId: currentQuestion.id,
body: new window.Date(date.toDate()).toLocaleDateString("ru-RU", {
year: "numeric",
month: "2-digit",
day: "2-digit",
}),
body: new window.Date(date.toDate()).toLocaleDateString(
"ru-RU",
{
year: "numeric",
month: "2-digit",
day: "2-digit",
}
),
//@ts-ignore
qid: settings.qid
})
qid: settings.qid,
});
updateAnswer(
currentQuestion.id,
String(
@ -78,9 +87,8 @@ export const Date = ({ currentQuestion }: DateProps) => {
)
);
} catch (e) {
enqueueSnackbar("ответ не был засчитан")
enqueueSnackbar("ответ не был засчитан");
}
}}
slotProps={{
openPickerButton: {
@ -89,14 +97,15 @@ export const Date = ({ currentQuestion }: DateProps) => {
},
"data-cy": "open-datepicker",
},
layout: {
sx: {backgroundColor: theme.palette.background.default,}
}
layout: {
sx: { backgroundColor: theme.palette.background.default },
},
}}
sx={{
"& .MuiInputBase-root": {
backgroundColor: mode[settings.cfg.theme] ? "white" : theme.palette.background.default,
backgroundColor: mode[settings.cfg.theme]
? "white"
: theme.palette.background.default,
borderRadius: "10px",
maxWidth: "250px",
pr: "22px",
@ -109,11 +118,9 @@ export const Date = ({ currentQuestion }: DateProps) => {
borderColor: "#9A9AAF",
},
},
}}
/>
</Box>
</Box>
);
};
};