import { useEffect, useState } from "react"; import { Box, Button, Typography, Modal, TextField, useTheme, useMediaQuery, } from "@mui/material"; import { DataGrid, GridLoadingOverlay, GridToolbar } from "@mui/x-data-grid"; import { DatePicker } from "@mui/x-date-pickers/DatePicker"; import { fadeIn } from "@root/utils/style/keyframes"; import type { GridColDef } from "@mui/x-data-grid"; import type { PromocodeStatistics } from "@root/model/promocodes"; import moment from "moment"; import { promocodeApi } from "@root/api/promocode/requests"; type StatisticsModalProps = { id: string; to: number; from: number; setId: (id: string) => void; setTo: (date: number) => void; setFrom: (date: number) => void; // promocodeStatistics: PromocodeStatistics[] | null | undefined; // promocodeStatistics: any; }; const COLUMNS: GridColDef[] = [ { field: "link", headerName: "Ссылка", width: 320, sortable: false, valueGetter: ({ row }) => row.link, }, { field: "useCount", headerName: "Использований", width: 120, sortable: false, valueGetter: ({ row }) => String(row.useCount), }, { field: "purchasesCount", headerName: "Покупок", width: 70, sortable: false, valueGetter: ({ row }) => String(row.purchasesCount), }, ]; type ROW = { link: string, useCount: number } export const StatisticsModal = ({ id, setId, setFrom, from, to, setTo, //promocodeStatistics, }: StatisticsModalProps) => { const [startDate, setStartDate] = useState(new Date()); const [endDate, setEndDate] = useState(new Date()); const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down(550)); const [general, setGeneral] = useState({}); const [rows, setRows] = useState([]); const getParseData = async () => { const promocodeStatistics = await promocodeApi.getPromocodeStatistics(id, moment(startDate).unix(), moment(endDate).unix()) const rows = [] as ROW[] //@ts-ignore for (const [key, value] of Object.entries(promocodeStatistics.usageMap)) { rows.push({ link: key, //@ts-ignore useCount: value, id:rows.length }) } setGeneral(promocodeStatistics) //@ts-ignore setRows(rows) } useEffect(() => { if (id.length > 0) getParseData() }, [id]) // const formatTo = to === null ? 0 : moment(to).unix() // const formatFrom = from === null ? 0 : moment(from).unix() console.log(general) // useEffect(() => { // (async () => { // const gottenGeneral = await promocodeStatistics(id, startDate, endDate) // setGeneral(gottenGeneral[0]) // })() // }, [to, from]); return ( { setId("") setStartDate(new Date()) setEndDate(new Date()) }} sx={{ "& > .MuiBox-root": { outline: "none" } }} > от date && setStartDate(date)} renderInput={(params) => ( )} InputProps={{ sx: { height: "40px", color: theme.palette.secondary.main, border: "1px solid", borderColor: theme.palette.secondary.main, "& .MuiSvgIcon-root": { color: theme.palette.secondary.main, }, }, }} /> до date && setEndDate(date)} renderInput={(params) => ( )} InputProps={{ sx: { height: "40px", color: theme.palette.secondary.main, border: "1px solid", borderColor: theme.palette.secondary.main, "& .MuiSvgIcon-root": { color: theme.palette.secondary.main, }, }, }} /> ); };