import { useEffect, useState } from "react"; import { Box, Paper, Typography, useMediaQuery, useTheme } from "@mui/material"; import { LineChart } from "@mui/x-charts"; import { enqueueSnackbar } from "notistack"; import { getGeneral } from "@api/statistic"; import type { GeneralResponse } from "@api/statistic"; type GeneralProps = { title: string; general: Record; color: string; numberType: "sum" | "percent"; }; const COLORS: Record = { 0: "#61BB1A", 1: "#7E2AEA", 2: "#FB5607", 3: "#0886FB", }; const GENERAL_MOCK: GeneralResponse = { open: { 100: 20, 50: 10, 60: 5 }, result: { 100: 90, 10: 3, 50: 48 }, avtime: { 100: 0, 2000: 550, 60: 0 }, conversation: { 100: 50, 1000: 50, 10000: 50 }, }; const GeneralItem = ({ title, general, color, numberType }: GeneralProps) => { 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( (total, [key, value]) => total + (value / Number(key)) * 100, 0, ) / Object.keys(general).length; return ( {title} {numberType === "sum" ? numberValue : `${numberValue.toFixed()}%`} ); }; export const General = () => { const [general, setGeneral] = useState(GENERAL_MOCK); const theme = useTheme(); const isTablet = useMediaQuery(theme.breakpoints.down(1000)); const isMobile = useMediaQuery(theme.breakpoints.down(700)); useEffect(() => { const requestGeneral = async () => { const [generalResponse, generalError] = await getGeneral("14761"); if (generalError) { enqueueSnackbar(generalError); return; } if (!generalResponse) { enqueueSnackbar("Список девайсов пуст."); return; } setGeneral(generalResponse); }; // requestGeneral(); }, []); return ( Ключевые метрики ); };