2024-01-22 00:38:53 +00:00
|
|
|
import moment from "moment";
|
2023-12-16 14:55:56 +00:00
|
|
|
import { DatePicker } from "@mui/x-date-pickers";
|
2023-12-29 00:58:19 +00:00
|
|
|
import { Box, Typography, useTheme } from "@mui/material";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-01-19 11:46:17 +00:00
|
|
|
import { useQuizViewStore, updateAnswer } from "@stores/quizView/store";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
import type { QuizQuestionDate } from "../../../model/questionTypes/date";
|
|
|
|
import CalendarIcon from "@icons/CalendarIcon";
|
2023-12-17 21:28:57 +00:00
|
|
|
import { enqueueSnackbar } from "notistack";
|
|
|
|
import { sendAnswer } from "@api/quizRelase";
|
2024-02-02 14:35:02 +00:00
|
|
|
|
2024-01-30 16:49:33 +00:00
|
|
|
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
2024-02-02 14:35:02 +00:00
|
|
|
import { useQuizData } from "@utils/hooks/useQuizData";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
type DateProps = {
|
2024-02-02 14:35:02 +00:00
|
|
|
currentQuestion: QuizQuestionDate;
|
2023-12-16 14:55:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const Date = ({ currentQuestion }: DateProps) => {
|
2024-02-02 14:35:02 +00:00
|
|
|
const theme = useTheme();
|
2023-12-29 00:58:19 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
const { settings } = useQuizData();
|
|
|
|
const { answers } = useQuizViewStore();
|
|
|
|
const answer = answers.find(
|
|
|
|
({ questionId }) => questionId === currentQuestion.id
|
|
|
|
)?.answer as string;
|
|
|
|
const currentAnswer = moment(answer) || moment();
|
2024-01-30 16:49:33 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
return (
|
|
|
|
<Box>
|
|
|
|
<Typography variant="h5" color={theme.palette.text.primary}>
|
|
|
|
{currentQuestion.title}
|
|
|
|
</Typography>
|
|
|
|
<Box
|
2024-01-09 10:17:56 +00:00
|
|
|
sx={{
|
2024-02-02 14:35:02 +00:00
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column",
|
|
|
|
width: "100%",
|
|
|
|
marginTop: "20px",
|
2024-01-09 10:17:56 +00:00
|
|
|
}}
|
2024-02-02 14:35:02 +00:00
|
|
|
>
|
|
|
|
<DatePicker
|
|
|
|
slots={{
|
|
|
|
openPickerIcon: () => (
|
|
|
|
<CalendarIcon
|
|
|
|
sx={{
|
|
|
|
"& path": { stroke: theme.palette.primary.main },
|
|
|
|
"& rect": { stroke: theme.palette.primary.main },
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
value={currentAnswer}
|
|
|
|
onChange={async (date) => {
|
|
|
|
console.log(date);
|
|
|
|
if (!date) {
|
|
|
|
return;
|
|
|
|
}
|
2024-01-09 10:17:56 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
try {
|
|
|
|
await sendAnswer({
|
|
|
|
questionId: currentQuestion.id,
|
|
|
|
body: moment(date).format("YYYY.MM.DD"),
|
|
|
|
qid: settings.qid,
|
|
|
|
});
|
2024-01-09 10:17:56 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
updateAnswer(
|
|
|
|
currentQuestion.id,
|
|
|
|
date
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
enqueueSnackbar("ответ не был засчитан");
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
slotProps={{
|
|
|
|
openPickerButton: {
|
|
|
|
sx: {
|
|
|
|
p: 0,
|
|
|
|
},
|
|
|
|
"data-cy": "open-datepicker",
|
|
|
|
},
|
|
|
|
layout: {
|
|
|
|
sx: { backgroundColor: theme.palette.background.default },
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
sx={{
|
|
|
|
"& .MuiInputBase-root": {
|
|
|
|
backgroundColor: quizThemes[settings.cfg.theme].isLight
|
|
|
|
? "white"
|
|
|
|
: theme.palette.background.default,
|
|
|
|
borderRadius: "10px",
|
|
|
|
maxWidth: "250px",
|
|
|
|
pr: "22px",
|
|
|
|
"& input": {
|
|
|
|
py: "11px",
|
|
|
|
pl: "20px",
|
|
|
|
lineHeight: "19px",
|
|
|
|
},
|
|
|
|
"& fieldset": {
|
|
|
|
borderColor: "#9A9AAF",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
2024-01-09 10:17:56 +00:00
|
|
|
};
|