frontPanel/src/pages/Analytics/Analytics.tsx

217 lines
5.8 KiB
TypeScript
Raw Normal View History

2024-03-20 14:44:51 +00:00
import { useState, useEffect } 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-20 14:44:51 +00:00
import { enqueueSnackbar } from "notistack";
import HeaderFull from "@ui_kit/Header/HeaderFull";
import SectionWrapper from "@ui_kit/SectionWrapper";
import { Devices } from "./Devices";
import { getDevicesList } from "@api/statistic";
2024-03-19 06:56:21 +00:00
import CalendarIcon from "@icons/CalendarIcon";
2024-03-20 14:44:51 +00:00
import type { DevicesResponse } from "@api/statistic";
const DEVICES_MOCK: DevicesResponse = {
device: {
additionalProp1: 10,
additionalProp2: 20,
additionalProp3: 30,
},
os: {
additionalProp1: 20,
additionalProp2: 78,
additionalProp3: 2,
},
browser: {
additionalProp1: 55,
additionalProp2: 11,
additionalProp3: 3,
},
};
2024-03-19 06:56:21 +00:00
2024-03-20 12:18:09 +00:00
export default function Analytics() {
2024-03-20 14:44:51 +00:00
const [devices, setDevices] = useState<DevicesResponse>(DEVICES_MOCK);
const [isOpen, setOpen] = useState(false);
const [isOpenEnd, setOpenEnd] = useState(false);
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
};
2024-03-19 06:56:21 +00:00
2024-03-20 12:18:09 +00:00
const now = moment();
return (
<>
<HeaderFull isRequest={true} />
<SectionWrapper component={"section"} sx={{ paddingTop: "60px" }}>
<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>
),
},
},
}}
/>
</Box>
<Box>
<Typography
sx={{
fontSize: "16px",
marginBottom: "5px",
fontWeight: 500,
color: "4D4D4D",
}}
>
Дата окончания
</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
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>
<Box>
<Paper>
<Typography>Открыли quiz</Typography>
<LineChart
xAxis={[{ data: [1, 2, 3, 5, 8, 10] }]}
series={[
{
data: [2, 5.5, 2, 8.5, 1.5, 5],
},
]}
width={500}
height={300}
/>
</Paper>
</Box>
2024-03-20 14:44:51 +00:00
<Devices devices={devices} />
2024-03-20 12:18:09 +00:00
</SectionWrapper>
</>
);
}