2024-03-21 14:24:56 +00:00
|
|
|
|
import { Box, Paper, Typography, useMediaQuery, useTheme } from "@mui/material";
|
|
|
|
|
import { LineChart } from "@mui/x-charts";
|
2024-04-03 23:35:36 +00:00
|
|
|
|
import moment from "moment";
|
2024-03-21 14:24:56 +00:00
|
|
|
|
|
|
|
|
|
import type { GeneralResponse } from "@api/statistic";
|
2024-04-01 18:09:26 +00:00
|
|
|
|
import { FC } from "react";
|
2024-03-21 14:24:56 +00:00
|
|
|
|
|
2024-04-01 18:09:26 +00:00
|
|
|
|
type GeneralItemsProps = {
|
2024-03-21 14:24:56 +00:00
|
|
|
|
title: string;
|
|
|
|
|
general: Record<string, number>;
|
|
|
|
|
color: string;
|
|
|
|
|
numberType: "sum" | "percent";
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-01 18:09:26 +00:00
|
|
|
|
type GeneralProps = {
|
|
|
|
|
data: GeneralResponse | null;
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-21 14:24:56 +00:00
|
|
|
|
const COLORS: Record<number, string> = {
|
|
|
|
|
0: "#61BB1A",
|
|
|
|
|
1: "#7E2AEA",
|
|
|
|
|
2: "#FB5607",
|
|
|
|
|
3: "#0886FB",
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-03 23:35:36 +00:00
|
|
|
|
const dateParser = (object: Record<string, number>): Record<string, number> => {
|
|
|
|
|
const result = {} as Record<string, number>
|
|
|
|
|
for (var key in object) {
|
2024-04-05 10:47:16 +00:00
|
|
|
|
result[moment.utc(Number(key)*1000).format('DD/MM/YYYY')] = object[key]
|
2024-04-03 23:35:36 +00:00
|
|
|
|
console.log(result)
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-01 18:09:26 +00:00
|
|
|
|
const GeneralItem = ({
|
|
|
|
|
title,
|
|
|
|
|
general,
|
|
|
|
|
color,
|
|
|
|
|
numberType,
|
|
|
|
|
}: GeneralItemsProps) => {
|
2024-03-21 14:24:56 +00:00
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(700));
|
|
|
|
|
|
|
|
|
|
const numberValue =
|
|
|
|
|
numberType === "sum"
|
|
|
|
|
? Object.values(general).reduce((total, item) => total + item, 0)
|
|
|
|
|
: Object.entries(general).reduce(
|
2024-04-03 23:35:36 +00:00
|
|
|
|
(total, [key, value]) => total + (value / Number(key)) * 100,
|
|
|
|
|
0,
|
|
|
|
|
) / Object.keys(general).length || Number(0);
|
2024-03-21 14:24:56 +00:00
|
|
|
|
return (
|
|
|
|
|
<Paper
|
|
|
|
|
sx={{
|
|
|
|
|
overflow: "hidden",
|
|
|
|
|
borderRadius: "12px",
|
|
|
|
|
boxShadow: "0 0 20px rgba(0, 0, 0, 0.15)",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography sx={{ margin: "20px 20px 0" }}>{title}</Typography>
|
|
|
|
|
<Typography sx={{ margin: "10px 20px 0", fontWeight: "bold" }}>
|
|
|
|
|
{numberType === "sum" ? numberValue : `${numberValue.toFixed()}%`}
|
|
|
|
|
</Typography>
|
|
|
|
|
<LineChart
|
2024-04-05 10:47:16 +00:00
|
|
|
|
xAxis={[{ data: Object.keys(general), valueFormatter: (value) => moment.utc(Number(value)*1000).format('DD/MM/YYYY') }]}
|
2024-03-21 14:24:56 +00:00
|
|
|
|
series={[{ data: Object.values(general) }]}
|
|
|
|
|
height={220}
|
|
|
|
|
colors={[color]}
|
|
|
|
|
sx={{
|
|
|
|
|
transform: isMobile ? "scale(1.1)" : "scale(1.2)",
|
|
|
|
|
"& .MuiChartsAxis-tickContainer": { display: "none" },
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Paper>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-01 18:09:26 +00:00
|
|
|
|
export const General: FC<GeneralProps> = ({ data }) => {
|
2024-03-21 14:24:56 +00:00
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
|
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(700));
|
|
|
|
|
|
2024-04-01 18:09:26 +00:00
|
|
|
|
if (!data) {
|
2024-03-30 18:54:28 +00:00
|
|
|
|
return (
|
|
|
|
|
<Typography textAlign="center" m="10px 0">
|
|
|
|
|
нет данных о ключевых метриках
|
|
|
|
|
</Typography>
|
|
|
|
|
);
|
2024-04-01 18:09:26 +00:00
|
|
|
|
}
|
2024-03-21 14:24:56 +00:00
|
|
|
|
return (
|
|
|
|
|
<Box sx={{ marginTop: "45px" }}>
|
|
|
|
|
<Typography
|
|
|
|
|
component="h3"
|
|
|
|
|
sx={{
|
|
|
|
|
fontSize: "24px",
|
|
|
|
|
fontWeight: "bold",
|
|
|
|
|
color: theme.palette.text.primary,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Ключевые метрики
|
|
|
|
|
</Typography>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "grid",
|
|
|
|
|
gridTemplateColumns: isTablet
|
|
|
|
|
? isMobile
|
|
|
|
|
? "1fr"
|
|
|
|
|
: "1fr 1fr"
|
|
|
|
|
: "1fr 1fr 1fr",
|
|
|
|
|
gap: "20px",
|
|
|
|
|
marginTop: "40px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<GeneralItem
|
|
|
|
|
title="Открыли квиз"
|
|
|
|
|
numberType="sum"
|
2024-04-03 14:22:51 +00:00
|
|
|
|
general={data.Open || { 0: 0 }}
|
2024-03-21 14:24:56 +00:00
|
|
|
|
color={COLORS[0]}
|
|
|
|
|
/>
|
|
|
|
|
<GeneralItem
|
|
|
|
|
title="Получено заявок"
|
|
|
|
|
numberType="sum"
|
2024-04-03 14:22:51 +00:00
|
|
|
|
general={data.Result || { 0: 0 }}
|
2024-03-21 14:24:56 +00:00
|
|
|
|
color={COLORS[1]}
|
|
|
|
|
/>
|
|
|
|
|
<GeneralItem
|
|
|
|
|
title="Конверсия"
|
|
|
|
|
numberType="percent"
|
2024-04-03 14:22:51 +00:00
|
|
|
|
general={data.Conversion || { 0: 0 }}
|
2024-03-21 14:24:56 +00:00
|
|
|
|
color={COLORS[2]}
|
|
|
|
|
/>
|
|
|
|
|
<GeneralItem
|
|
|
|
|
title="Среднее время прохождения квиза"
|
|
|
|
|
numberType="percent"
|
2024-04-03 14:22:51 +00:00
|
|
|
|
general={data.AvTime || { 0: 0 }}
|
2024-03-21 14:24:56 +00:00
|
|
|
|
color={COLORS[3]}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|