2024-03-29 20:27:07 +00:00
|
|
|
|
import {useEffect, useState} from "react";
|
2024-03-26 15:41:22 +00:00
|
|
|
|
import {
|
|
|
|
|
Box,
|
|
|
|
|
Button,
|
|
|
|
|
Typography,
|
|
|
|
|
Modal,
|
|
|
|
|
TextField,
|
|
|
|
|
useTheme,
|
|
|
|
|
useMediaQuery,
|
|
|
|
|
} from "@mui/material";
|
|
|
|
|
import { DataGrid, GridLoadingOverlay, GridToolbar } from "@mui/x-data-grid";
|
2024-03-29 20:27:07 +00:00
|
|
|
|
import { DatePicker } from "@mui/x-date-pickers/DatePicker";
|
2024-03-26 15:41:22 +00:00
|
|
|
|
|
|
|
|
|
import { fadeIn } from "@root/utils/style/keyframes";
|
|
|
|
|
|
|
|
|
|
import type { GridColDef } from "@mui/x-data-grid";
|
|
|
|
|
import type { PromocodeStatistics } from "@root/model/promocodes";
|
2024-03-29 20:27:07 +00:00
|
|
|
|
import moment from "moment";
|
|
|
|
|
import {promocodeApi} from "@root/api/promocode/requests";
|
2024-03-26 15:41:22 +00:00
|
|
|
|
|
|
|
|
|
type StatisticsModalProps = {
|
|
|
|
|
id: string;
|
2024-03-29 20:27:07 +00:00
|
|
|
|
to: number;
|
|
|
|
|
from: number;
|
2024-03-26 15:41:22 +00:00
|
|
|
|
setId: (id: string) => void;
|
2024-03-29 20:27:07 +00:00
|
|
|
|
setTo: (date: number) => void;
|
|
|
|
|
setFrom: (date: number) => void;
|
2024-03-28 20:31:28 +00:00
|
|
|
|
// promocodeStatistics: PromocodeStatistics[] | null | undefined;
|
2024-03-29 20:27:07 +00:00
|
|
|
|
// promocodeStatistics: any;
|
2024-03-26 15:41:22 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const COLUMNS: GridColDef<PromocodeStatistics, string>[] = [
|
|
|
|
|
{
|
|
|
|
|
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),
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export const StatisticsModal = ({
|
|
|
|
|
id,
|
|
|
|
|
setId,
|
2024-03-29 20:27:07 +00:00
|
|
|
|
setFrom,
|
|
|
|
|
from,
|
|
|
|
|
to,
|
|
|
|
|
setTo,
|
|
|
|
|
//promocodeStatistics,
|
2024-03-26 15:41:22 +00:00
|
|
|
|
}: StatisticsModalProps) => {
|
|
|
|
|
const [startDate, setStartDate] = useState<Date>(new Date());
|
|
|
|
|
const [endDate, setEndDate] = useState<Date>(new Date());
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(550));
|
2024-03-29 20:27:07 +00:00
|
|
|
|
const [general, setGeneral] = useState({});
|
|
|
|
|
// const formatTo = to === null ? 0 : moment(to).unix()
|
|
|
|
|
// const formatFrom = from === null ? 0 : moment(from).unix()
|
|
|
|
|
console.log(startDate)
|
|
|
|
|
// useEffect(() => {
|
|
|
|
|
// (async () => {
|
|
|
|
|
// const gottenGeneral = await promocodeStatistics(id, startDate, endDate)
|
|
|
|
|
// setGeneral(gottenGeneral[0])
|
|
|
|
|
// })()
|
|
|
|
|
// }, [to, from]);
|
2024-03-26 15:41:22 +00:00
|
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
open={Boolean(id)}
|
2024-03-29 20:27:07 +00:00
|
|
|
|
onClose={() => {
|
|
|
|
|
setId("")
|
|
|
|
|
setStartDate(new Date())
|
|
|
|
|
setEndDate(new Date())
|
|
|
|
|
}}
|
2024-03-26 15:41:22 +00:00
|
|
|
|
sx={{ "& > .MuiBox-root": { outline: "none" } }}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: "50%",
|
|
|
|
|
left: "50%",
|
|
|
|
|
transform: "translate(-50%, -50%)",
|
|
|
|
|
width: "95%",
|
|
|
|
|
maxWidth: "600px",
|
2024-03-27 07:35:28 +00:00
|
|
|
|
background: "#1F2126",
|
2024-03-26 15:41:22 +00:00
|
|
|
|
border: "2px solid gray",
|
|
|
|
|
borderRadius: "6px",
|
|
|
|
|
boxShadow: 24,
|
|
|
|
|
p: 4,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
gap: "30px",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
flexDirection: isMobile ? "column" : "row",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
gap: "30px",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
sx={{ maxWidth: "100px" }}
|
|
|
|
|
// onClick={() => }
|
|
|
|
|
>
|
|
|
|
|
Создать короткую ссылку
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
sx={{ maxWidth: "100px" }}
|
2024-03-29 20:27:07 +00:00
|
|
|
|
onClick={async () =>{
|
|
|
|
|
const promocodeStatistics = promocodeApi.getPromocodeStatistics(id, moment(startDate).unix(), moment(endDate).unix())
|
|
|
|
|
setGeneral(promocodeStatistics)
|
|
|
|
|
} }
|
2024-03-26 15:41:22 +00:00
|
|
|
|
>
|
|
|
|
|
Обновить статистику
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box sx={{ minWidth: "200px" }}>
|
|
|
|
|
<Box sx={{ display: "flex", alignItems: "center", gap: "10px" }}>
|
2024-03-27 07:35:28 +00:00
|
|
|
|
<Typography sx={{ minWidth: "20px", color: "#FFFFFF" }}>
|
|
|
|
|
от
|
|
|
|
|
</Typography>
|
2024-03-29 20:27:07 +00:00
|
|
|
|
<DatePicker
|
2024-03-26 15:41:22 +00:00
|
|
|
|
inputFormat="DD/MM/YYYY"
|
|
|
|
|
value={startDate}
|
|
|
|
|
onChange={(date) => date && setStartDate(date)}
|
|
|
|
|
renderInput={(params) => (
|
|
|
|
|
<TextField
|
|
|
|
|
{...params}
|
|
|
|
|
sx={{ background: "#1F2126", borderRadius: "5px" }}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
InputProps={{
|
|
|
|
|
sx: {
|
|
|
|
|
height: "40px",
|
|
|
|
|
color: theme.palette.secondary.main,
|
|
|
|
|
border: "1px solid",
|
|
|
|
|
borderColor: theme.palette.secondary.main,
|
|
|
|
|
"& .MuiSvgIcon-root": {
|
|
|
|
|
color: theme.palette.secondary.main,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
gap: "10px",
|
|
|
|
|
marginTop: "10px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-03-27 07:35:28 +00:00
|
|
|
|
<Typography sx={{ minWidth: "20px", color: "#FFFFFF" }}>
|
|
|
|
|
до
|
|
|
|
|
</Typography>
|
2024-03-29 20:27:07 +00:00
|
|
|
|
<DatePicker
|
2024-03-26 15:41:22 +00:00
|
|
|
|
inputFormat="DD/MM/YYYY"
|
|
|
|
|
value={endDate}
|
|
|
|
|
onChange={(date) => date && setEndDate(date)}
|
|
|
|
|
renderInput={(params) => (
|
|
|
|
|
<TextField
|
|
|
|
|
{...params}
|
|
|
|
|
sx={{ background: "#1F2126", borderRadius: "5px" }}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
InputProps={{
|
|
|
|
|
sx: {
|
|
|
|
|
height: "40px",
|
|
|
|
|
color: theme.palette.secondary.main,
|
|
|
|
|
border: "1px solid",
|
|
|
|
|
borderColor: theme.palette.secondary.main,
|
|
|
|
|
"& .MuiSvgIcon-root": {
|
|
|
|
|
color: theme.palette.secondary.main,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
<DataGrid
|
|
|
|
|
disableSelectionOnClick={true}
|
2024-03-29 20:27:07 +00:00
|
|
|
|
rows={[]}
|
2024-03-26 15:41:22 +00:00
|
|
|
|
columns={COLUMNS}
|
|
|
|
|
sx={{
|
|
|
|
|
marginTop: "30px",
|
|
|
|
|
background: "#1F2126",
|
|
|
|
|
color: theme.palette.secondary.main,
|
|
|
|
|
"& .MuiDataGrid-iconSeparator": { display: "none" },
|
|
|
|
|
"& .css-levciy-MuiTablePagination-displayedRows": {
|
|
|
|
|
color: theme.palette.secondary.main,
|
|
|
|
|
},
|
|
|
|
|
"& .MuiSvgIcon-root": { color: theme.palette.secondary.main },
|
|
|
|
|
"& .MuiTablePagination-selectLabel": {
|
|
|
|
|
color: theme.palette.secondary.main,
|
|
|
|
|
},
|
|
|
|
|
"& .MuiInputBase-root": { color: theme.palette.secondary.main },
|
|
|
|
|
"& .MuiButton-text": { color: theme.palette.secondary.main },
|
|
|
|
|
"& .MuiDataGrid-overlay": {
|
|
|
|
|
backgroundColor: "rgba(255, 255, 255, 0.1)",
|
|
|
|
|
animation: `${fadeIn} 0.5s ease-out`,
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
components={{
|
|
|
|
|
Toolbar: GridToolbar,
|
|
|
|
|
LoadingOverlay: GridLoadingOverlay,
|
|
|
|
|
}}
|
|
|
|
|
rowsPerPageOptions={[10, 25, 50, 100]}
|
|
|
|
|
autoHeight
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
};
|