import { useLayoutEffect, useState } from "react"; import { Box, Button, IconButton, Paper, Typography, useMediaQuery, useTheme, } from "@mui/material"; import dayjs from "dayjs"; import { DatePicker } from "@mui/x-date-pickers"; import { LineChart } from "@mui/x-charts"; import moment from "moment"; import { useQuizStore } from "@root/quizes/store"; import { useCurrentQuiz } from "@root/quizes/hooks"; import { useAnalytics } from "@utils/hooks/useAnalytics"; import HeaderFull from "@ui_kit/Header/HeaderFull"; import SectionWrapper from "@ui_kit/SectionWrapper"; import { General } from "./General"; import { AnswersStatistics } from "./Answers"; import { Devices } from "./Devices"; import CalendarIcon from "@icons/CalendarIcon"; import { redirect } from "react-router-dom"; import type { Dayjs } from "dayjs"; export default function Analytics() { const quiz = useCurrentQuiz(); const { editQuizId } = useQuizStore(); const [isOpen, setOpen] = useState(false); const [isOpenEnd, setOpenEnd] = useState(false); const [from, setFrom] = useState(dayjs(0)); const [to, setTo] = useState(dayjs(Date.now())); console.log(11, to); const { devices, general, questions } = useAnalytics({ quizId: editQuizId?.toString() || "", to: to.unix(), from: from.unix(), }); const resetTime = () => { setTo(dayjs(Date.now())); setFrom(dayjs(0)); }; useLayoutEffect(() => { if (editQuizId === undefined) redirect("/list"); }, [editQuizId]); const theme = useTheme(); const isTablet = useMediaQuery(theme.breakpoints.down(1000)); const isMobile = useMediaQuery(theme.breakpoints.down(600)); const handleClose = () => { setOpen(false); }; const handleOpen = () => { setOpen(true); }; const onAdornmentClick = () => { setOpen((old) => !old); if (isOpenEnd === true) { handleCloseEnd(); } }; const handleCloseEnd = () => { setOpenEnd(false); }; const handleOpenEnd = () => { setOpenEnd(true); }; const onAdornmentClickEnd = () => { setOpenEnd((old) => !old); if (isOpen === true) { handleClose(); } }; console.log("questions", questions); console.log("general", general); console.log("devices", devices); const now = moment(); return ( <> Аналитика Дата начала ), }, }, }} value={dayjs(from)} onChange={(newValue) => newValue && setFrom(newValue)} /> Дата окончания ), }, }, }} value={dayjs(to)} onChange={(newValue) => newValue && setTo(newValue)} /> ); }