вывод таблицы
This commit is contained in:
parent
153b518914
commit
f3b66d92e0
@ -113,7 +113,7 @@ const getPromocodeStatistics = async (id: string, from: number, to: number,) =>
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
useToken: false,
|
useToken: false,
|
||||||
});
|
});
|
||||||
|
console.log(promocodeStatisticsResponse)
|
||||||
return promocodeStatisticsResponse;
|
return promocodeStatisticsResponse;
|
||||||
} catch (nativeError) {
|
} catch (nativeError) {
|
||||||
const [error] = parseAxiosError(nativeError);
|
const [error] = parseAxiosError(nativeError);
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import Box from '@mui/material/Box';
|
||||||
|
import Modal from '@mui/material/Modal';
|
||||||
|
import Button from '@mui/material/Button';
|
||||||
|
import { Typography } from '@mui/material';
|
||||||
|
|
||||||
|
const style = {
|
||||||
|
position: 'absolute' as 'absolute',
|
||||||
|
top: '50%',
|
||||||
|
left: '50%',
|
||||||
|
transform: 'translate(-50%, -50%)',
|
||||||
|
width: 400,
|
||||||
|
bgcolor: '#c1c1c1',
|
||||||
|
border: '2px solid #000',
|
||||||
|
boxShadow: 24,
|
||||||
|
pt: 2,
|
||||||
|
px: 4,
|
||||||
|
pb: 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
id: string;
|
||||||
|
setModal: (id: string) => void;
|
||||||
|
deletePromocode: (id: string) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ({
|
||||||
|
id,
|
||||||
|
setModal,
|
||||||
|
deletePromocode
|
||||||
|
}: Props) {
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
open={Boolean(id)}
|
||||||
|
onClose={() => setModal("")}
|
||||||
|
>
|
||||||
|
<Box sx={{ ...style, width: 400 }}>
|
||||||
|
<Typography
|
||||||
|
variant='h5'
|
||||||
|
textAlign="center"
|
||||||
|
>Точно удалить промокод?</Typography>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "flex",
|
||||||
|
justifyContent: "space-evenly",
|
||||||
|
mt: "15px"
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
onClick={() => { deletePromocode(id); setModal("") }}
|
||||||
|
>Да</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => setModal("")}
|
||||||
|
>Нет</Button>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import {useEffect, useState} from "react";
|
import { useEffect, useState } from "react";
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Button,
|
Button,
|
||||||
@ -16,7 +16,7 @@ import { fadeIn } from "@root/utils/style/keyframes";
|
|||||||
import type { GridColDef } from "@mui/x-data-grid";
|
import type { GridColDef } from "@mui/x-data-grid";
|
||||||
import type { PromocodeStatistics } from "@root/model/promocodes";
|
import type { PromocodeStatistics } from "@root/model/promocodes";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import {promocodeApi} from "@root/api/promocode/requests";
|
import { promocodeApi } from "@root/api/promocode/requests";
|
||||||
|
|
||||||
type StatisticsModalProps = {
|
type StatisticsModalProps = {
|
||||||
id: string;
|
id: string;
|
||||||
@ -26,7 +26,7 @@ type StatisticsModalProps = {
|
|||||||
setTo: (date: number) => void;
|
setTo: (date: number) => void;
|
||||||
setFrom: (date: number) => void;
|
setFrom: (date: number) => void;
|
||||||
// promocodeStatistics: PromocodeStatistics[] | null | undefined;
|
// promocodeStatistics: PromocodeStatistics[] | null | undefined;
|
||||||
// promocodeStatistics: any;
|
// promocodeStatistics: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
const COLUMNS: GridColDef<PromocodeStatistics, string>[] = [
|
const COLUMNS: GridColDef<PromocodeStatistics, string>[] = [
|
||||||
@ -53,6 +53,11 @@ const COLUMNS: GridColDef<PromocodeStatistics, string>[] = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
type ROW = {
|
||||||
|
link: string,
|
||||||
|
useCount: number
|
||||||
|
}
|
||||||
|
|
||||||
export const StatisticsModal = ({
|
export const StatisticsModal = ({
|
||||||
id,
|
id,
|
||||||
setId,
|
setId,
|
||||||
@ -66,23 +71,43 @@ export const StatisticsModal = ({
|
|||||||
const [endDate, setEndDate] = useState<Date>(new Date());
|
const [endDate, setEndDate] = useState<Date>(new Date());
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isMobile = useMediaQuery(theme.breakpoints.down(550));
|
const isMobile = useMediaQuery(theme.breakpoints.down(550));
|
||||||
const [general, setGeneral] = useState({});
|
const [general, setGeneral] = useState({});
|
||||||
// const formatTo = to === null ? 0 : moment(to).unix()
|
const [rows, setRows] = useState([]);
|
||||||
// const formatFrom = from === null ? 0 : moment(from).unix()
|
const getParseData = async () => {
|
||||||
console.log(startDate)
|
const promocodeStatistics = await promocodeApi.getPromocodeStatistics(id, moment(startDate).unix(), moment(endDate).unix())
|
||||||
// useEffect(() => {
|
const rows = [] as ROW[]
|
||||||
// (async () => {
|
//@ts-ignore
|
||||||
// const gottenGeneral = await promocodeStatistics(id, startDate, endDate)
|
for (const [key, value] of Object.entries(promocodeStatistics.usageMap)) {
|
||||||
// setGeneral(gottenGeneral[0])
|
rows.push({
|
||||||
// })()
|
link: key,
|
||||||
// }, [to, from]);
|
//@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 (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
open={Boolean(id)}
|
open={Boolean(id)}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setId("")
|
setId("")
|
||||||
setStartDate(new Date())
|
setStartDate(new Date())
|
||||||
setEndDate(new Date())
|
setEndDate(new Date())
|
||||||
}}
|
}}
|
||||||
sx={{ "& > .MuiBox-root": { outline: "none" } }}
|
sx={{ "& > .MuiBox-root": { outline: "none" } }}
|
||||||
>
|
>
|
||||||
@ -120,16 +145,13 @@ export const StatisticsModal = ({
|
|||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
sx={{ maxWidth: "100px" }}
|
sx={{ maxWidth: "100px" }}
|
||||||
// onClick={() => }
|
// onClick={() => }
|
||||||
>
|
>
|
||||||
Создать короткую ссылку
|
Создать короткую ссылку
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
sx={{ maxWidth: "100px" }}
|
sx={{ maxWidth: "100px" }}
|
||||||
onClick={async () =>{
|
onClick={getParseData}
|
||||||
const promocodeStatistics = promocodeApi.getPromocodeStatistics(id, moment(startDate).unix(), moment(endDate).unix())
|
|
||||||
setGeneral(promocodeStatistics)
|
|
||||||
} }
|
|
||||||
>
|
>
|
||||||
Обновить статистику
|
Обновить статистику
|
||||||
</Button>
|
</Button>
|
||||||
@ -200,7 +222,7 @@ export const StatisticsModal = ({
|
|||||||
</Box>
|
</Box>
|
||||||
<DataGrid
|
<DataGrid
|
||||||
disableSelectionOnClick={true}
|
disableSelectionOnClick={true}
|
||||||
rows={[]}
|
rows={rows}
|
||||||
columns={COLUMNS}
|
columns={COLUMNS}
|
||||||
sx={{
|
sx={{
|
||||||
marginTop: "30px",
|
marginTop: "30px",
|
||||||
|
@ -8,9 +8,14 @@ import { fadeIn } from "@root/utils/style/keyframes";
|
|||||||
import { CreatePromocodeForm } from "./CreatePromocodeForm";
|
import { CreatePromocodeForm } from "./CreatePromocodeForm";
|
||||||
import { usePromocodeGridColDef } from "./usePromocodeGridColDef";
|
import { usePromocodeGridColDef } from "./usePromocodeGridColDef";
|
||||||
import { StatisticsModal } from "./StatisticsModal";
|
import { StatisticsModal } from "./StatisticsModal";
|
||||||
|
import DeleteModal from "./DeleteModal";
|
||||||
|
|
||||||
export const PromocodeManagement = () => {
|
export const PromocodeManagement = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
|
const [deleteModal, setDeleteModal] = useState<string>("")
|
||||||
|
const deleteModalHC = (id:string) => setDeleteModal(id)
|
||||||
|
|
||||||
const [showStatisticsModalId, setShowStatisticsModalId] =
|
const [showStatisticsModalId, setShowStatisticsModalId] =
|
||||||
useState<string>("");
|
useState<string>("");
|
||||||
const [page, setPage] = useState<number>(0);
|
const [page, setPage] = useState<number>(0);
|
||||||
@ -28,7 +33,7 @@ export const PromocodeManagement = () => {
|
|||||||
} = usePromocodes(page, pageSize, showStatisticsModalId, to, from);
|
} = usePromocodes(page, pageSize, showStatisticsModalId, to, from);
|
||||||
const columns = usePromocodeGridColDef(
|
const columns = usePromocodeGridColDef(
|
||||||
setShowStatisticsModalId,
|
setShowStatisticsModalId,
|
||||||
deletePromocode
|
deleteModalHC
|
||||||
);
|
);
|
||||||
console.log(showStatisticsModalId)
|
console.log(showStatisticsModalId)
|
||||||
if (error) return <Typography>Ошибка загрузки промокодов</Typography>;
|
if (error) return <Typography>Ошибка загрузки промокодов</Typography>;
|
||||||
@ -97,6 +102,7 @@ export const PromocodeManagement = () => {
|
|||||||
from={from}
|
from={from}
|
||||||
setFrom={setFrom}
|
setFrom={setFrom}
|
||||||
/>
|
/>
|
||||||
|
<DeleteModal id={deleteModal} setModal={setDeleteModal} deletePromocode={deletePromocode}/>
|
||||||
</LocalizationProvider>
|
</LocalizationProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { IconButton } from "@mui/material";
|
import { IconButton } from "@mui/material";
|
||||||
import { GridColDef } from "@mui/x-data-grid";
|
import { GridColDef } from "@mui/x-data-grid";
|
||||||
import { Promocode } from "@root/model/promocodes";
|
import { Promocode } from "@root/model/promocodes";
|
||||||
import { useMemo } from "react";
|
import { useMemo, useState } from "react";
|
||||||
|
|
||||||
import { BarChart, Delete } from "@mui/icons-material";
|
import { BarChart, Delete } from "@mui/icons-material";
|
||||||
import {promocodeApi} from "@root/api/promocode/requests";
|
import {promocodeApi} from "@root/api/promocode/requests";
|
||||||
|
Loading…
Reference in New Issue
Block a user