frontPanel/src/pages/Analytics/Analytics.tsx

210 lines
5.9 KiB
TypeScript
Raw Normal View History

2024-03-28 09:18:24 +00:00
import { useLayoutEffect, useState } from "react";
2024-03-20 12:18:09 +00:00
import {
Box,
Button,
IconButton,
Paper,
Typography,
useMediaQuery,
useTheme,
} from "@mui/material";
import { DatePicker } from "@mui/x-date-pickers";
2024-03-20 14:44:51 +00:00
import { LineChart } from "@mui/x-charts";
2024-03-20 12:18:09 +00:00
import moment from "moment";
2024-03-28 09:18:24 +00:00
import { useQuizStore } from "@root/quizes/store";
import { useAnalytics } from "@utils/hooks/useAnalytics";
2024-03-20 14:44:51 +00:00
import HeaderFull from "@ui_kit/Header/HeaderFull";
import SectionWrapper from "@ui_kit/SectionWrapper";
2024-03-21 14:24:56 +00:00
import { General } from "./General";
2024-03-25 15:02:24 +00:00
import { AnswersStatistics } from "./Answers";
2024-03-20 14:44:51 +00:00
import { Devices } from "./Devices";
2024-03-19 06:56:21 +00:00
import CalendarIcon from "@icons/CalendarIcon";
2024-03-28 09:18:24 +00:00
import { redirect } from "react-router-dom";
2024-03-20 14:44:51 +00:00
2024-03-20 12:18:09 +00:00
export default function Analytics() {
2024-03-28 09:18:24 +00:00
const { editQuizId } = useQuizStore();
2024-03-20 14:44:51 +00:00
const [isOpen, setOpen] = useState(false);
const [isOpenEnd, setOpenEnd] = useState(false);
2024-03-29 06:10:33 +00:00
const [to, setTo] = useState(null);
const [from, setFrom] = useState(null);
2024-03-28 09:18:24 +00:00
const { devices, general, questions } = useAnalytics({
quizId: editQuizId?.toString(),
to,
from,
});
2024-03-20 14:44:51 +00:00
2024-03-29 06:10:33 +00:00
const resetTime = () => {
setTo(null);
setFrom(null);
};
2024-03-28 09:18:24 +00:00
useLayoutEffect(() => {
if (editQuizId === undefined) redirect("/list");
}, [editQuizId]);
2024-03-20 12:18:09 +00:00
const theme = useTheme();
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
const isMobile = useMediaQuery(theme.breakpoints.down(600));
2024-03-19 06:56:21 +00:00
2024-03-20 12:18:09 +00:00
const handleClose = () => {
setOpen(false);
};
const handleOpen = () => {
setOpen(true);
};
const onAdornmentClick = () => {
setOpen((old) => !old);
if (isOpenEnd === true) {
handleCloseEnd();
2024-03-19 06:56:21 +00:00
}
2024-03-20 12:18:09 +00:00
};
2024-03-19 06:56:21 +00:00
2024-03-20 12:18:09 +00:00
const handleCloseEnd = () => {
setOpenEnd(false);
};
const handleOpenEnd = () => {
setOpenEnd(true);
};
const onAdornmentClickEnd = () => {
setOpenEnd((old) => !old);
if (isOpen === true) {
handleClose();
2024-03-19 06:56:21 +00:00
}
2024-03-20 12:18:09 +00:00
};
console.log("questions", questions);
console.log("general", general);
console.log("devices", devices);
2024-03-19 06:56:21 +00:00
2024-03-20 12:18:09 +00:00
const now = moment();
return (
<>
2024-03-21 14:24:56 +00:00
<HeaderFull isRequest />
<SectionWrapper component={"section"} sx={{ padding: "60px 20px" }}>
2024-03-20 12:18:09 +00:00
<Typography variant={"h4"}>Аналитика</Typography>
<Box
sx={{
display: "flex",
gap: isMobile ? "15px" : "20px",
alignItems: "end",
justifyContent: "space-between",
padding: "40px 0 20px",
borderBottom: `1px solid ${theme.palette.grey2.main}`,
}}
>
<Box sx={{ display: "flex", gap: isMobile ? "15px" : "20px" }}>
<Box>
<Typography
sx={{
fontSize: "16px",
marginBottom: "5px",
fontWeight: 500,
color: "4D4D4D",
}}
>
Дата начала
</Typography>
<DatePicker
open={isOpen}
onClose={handleClose}
onOpen={handleOpen}
// defaultValue={now}
sx={{
width: isMobile ? "146px" : "169px",
2024-03-19 06:56:21 +00:00
2024-03-20 12:18:09 +00:00
"& .MuiOutlinedInput-root": {
borderRadius: "10px",
fontSize: "16px",
},
"& .MuiInputBase-input": {
padding: "12.5px 14px",
},
}}
slotProps={{
textField: {
InputProps: {
endAdornment: (
<IconButton onClick={onAdornmentClick}>
<CalendarIcon />
</IconButton>
),
},
},
}}
2024-03-29 06:10:33 +00:00
value={to}
onChange={(newValue) => setTo(newValue)}
2024-03-20 12:18:09 +00:00
/>
</Box>
<Box>
<Typography
sx={{
fontSize: "16px",
marginBottom: "5px",
fontWeight: 500,
color: "4D4D4D",
}}
>
value={from}
onChange={(newValue) => setValue(setFrom)}
2024-03-20 12:18:09 +00:00
Дата окончания
</Typography>
<DatePicker
open={isOpenEnd}
onClose={handleCloseEnd}
onOpen={handleOpenEnd}
// defaultValue={now}
sx={{
width: isMobile ? "146px" : "169px",
"& .MuiOutlinedInput-root": {
borderRadius: "10px",
fontSize: "16px",
},
"& .MuiInputBase-input": {
padding: "12.5px 14px",
},
}}
slotProps={{
textField: {
InputProps: {
endAdornment: (
<IconButton onClick={onAdornmentClickEnd}>
<CalendarIcon />
</IconButton>
),
},
},
}}
/>
</Box>
</Box>
2024-03-19 06:56:21 +00:00
2024-03-20 12:18:09 +00:00
<Button
onClick={resetTime}
2024-03-20 12:18:09 +00:00
variant="outlined"
sx={{
minWidth: isMobile ? "144px" : "180px",
px: isMobile ? "31px" : "43px",
color: theme.palette.brightPurple.main,
"&:hover": {
backgroundColor: "#581CA7",
color: "#FFFFFF",
},
"&:active": {
backgroundColor: "#000000",
color: "#FFFFFF",
},
}}
>
Сбросить
</Button>
</Box>
<General data={general} />
<AnswersStatistics data={questions} />
<Devices data={devices} />
2024-03-20 12:18:09 +00:00
</SectionWrapper>
</>
);
}