статистика шильдика таблица

This commit is contained in:
Tamara 2024-04-25 02:29:39 +03:00
parent a2b7dc8f23
commit 5583b20197
3 changed files with 231 additions and 31 deletions

@ -0,0 +1,192 @@
import {useState} from "react";
import moment, {Moment} from "moment";
import {
Box,
Button,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
TextField,
Typography,
useTheme
} from "@mui/material";
import makeRequest from "@root/api/makeRequest";
import {parseAxiosError} from "@root/utils/parse-error";
import {AdapterMoment} from "@mui/x-date-pickers/AdapterMoment";
import { DatePicker, LocalizationProvider } from '@mui/x-date-pickers';
export default function StatisticSchild() {
const theme = useTheme()
const [isOpen, setOpen] = useState<boolean>(false);
const [isOpenEnd, setOpenEnd] = useState<boolean>(false);
const [from, setFrom] = useState<Moment | null>(null);
const [to, setTo] = useState<Moment | null>(moment(Date.now()));
const [statistic, setStatistic] = useState<any>([])
const handleClose = () => {
setOpen(false);
};
const handleOpen = () => {
setOpen(true);
};
const onAdornmentClick = () => {
setOpen((old) => !old);
if (isOpenEnd) {
handleCloseEnd();
}
};
const handleCloseEnd = () => {
setOpenEnd(false);
};
const handleOpenEnd = () => {
setOpenEnd(true);
};
const onAdornmentClickEnd = () => {
setOpenEnd((old) => !old);
if (isOpen) {
handleClose();
}
};
const StatisticsShild = async (from: any, to: any) => {
try {
const StatisticResponse = await makeRequest<unknown, unknown>({
url: process.env.REACT_APP_DOMAIN + "/customer/quizlogo/stat" ,
method: "post",
useToken: true,
body: {
"to": to.unix(),
"from": from.unix(),
"page": 0,
"limit": 100
},
});
setStatistic(StatisticResponse)
return [StatisticResponse];
} catch (nativeError) {
const [error] = parseAxiosError(nativeError);
return [null, `Ошибка запроса статистики. ${error}`];
}
}
console.log(statistic)
return(
<LocalizationProvider dateAdapter={AdapterMoment}>
<Typography sx={{mt: "20px", mb: "20px"}}>Статистика переходов с шильдика</Typography>
<Box>
<Typography
sx={{
fontSize: "16px",
marginBottom: "5px",
fontWeight: 500,
color: "4D4D4D",
}}
>
Дата начала
</Typography>
<DatePicker
inputFormat="DD/MM/YYYY"
value={from}
onChange={(date) => date && setFrom(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>
<Typography
sx={{
fontSize: "16px",
marginBottom: "5px",
fontWeight: 500,
color: "4D4D4D",
}}
>
Дата окончания
</Typography>
<DatePicker
inputFormat="DD/MM/YYYY"
value={to}
onChange={(date) => date && setTo(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>
<Button
sx={{
m: '10px 0'
}}
onClick={async() =>StatisticsShild(from, to)}
>
Запросить статистику(тест)
</Button>
<Table
sx={{
width: "80%",
border: "2px solid",
borderColor: theme.palette.secondary.main,
bgcolor: theme.palette.content.main,
color: "white"
}}
>
<TableHead>
<TableRow
sx={{
borderBottom: "2px solid",
borderColor: theme.palette.grayLight.main,
height: "100px",
}}
>
<TableCell sx={{color: "inherit"}} align="center">ID</TableCell>
<TableCell sx={{color: "inherit"}} align="center">Регистраций</TableCell>
<TableCell sx={{color: "inherit"}} align="center">Money</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableCell sx={{color: "inherit"}} align="center">{statistic[0].ID}</TableCell>
<TableCell sx={{color: "inherit"}} align="center">{statistic[0].Regs}</TableCell>
<TableCell sx={{color: "inherit"}} align="center">{statistic[0].Money}</TableCell>
</TableBody>
</Table>
</LocalizationProvider>
)
}

@ -8,6 +8,7 @@ import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment'
import makeRequest from "@root/api/makeRequest";
import {Discount} from "@frontend/kitui";
import {parseAxiosError} from "@root/utils/parse-error";
import StatisticSchild from "./StatisticSchild";
export default () => {
const theme = useTheme()
@ -19,6 +20,7 @@ export default () => {
const [to, setTo] = useState<Moment | null>(moment(Date.now()));
const { Registrations, Quizes, Results } = useQuizStatistic({
from,
to,
@ -59,28 +61,28 @@ export default () => {
}
};
const StatisticsShild = async (from: any, to: any) => {
try {
const StatisticResponse = await makeRequest<unknown, unknown>({
url: process.env.REACT_APP_DOMAIN + "/customer/quizlogo/stat" ,
method: "post",
useToken: true,
body: {
"to": to.unix(),
"from": from.unix(),
"page": 0,
"limit": 100
},
});
return [StatisticResponse];
} catch (nativeError) {
const [error] = parseAxiosError(nativeError);
return [null, `Ошибка запроса статистики. ${error}`];
}
}
// const StatisticsShild = async (from: any, to: any) => {
// try {
// const StatisticResponse = await makeRequest<unknown, unknown>({
// url: process.env.REACT_APP_DOMAIN + "/customer/quizlogo/stat" ,
// method: "post",
// useToken: true,
// body: {
// "to": to.unix(),
// "from": from.unix(),
// "page": 0,
// "limit": 100
// },
// });
//
// return [StatisticResponse];
// } catch (nativeError) {
// const [error] = parseAxiosError(nativeError);
//
// return [null, `Ошибка запроса статистики. ${error}`];
// }
// }
//
return <>
<LocalizationProvider dateAdapter={AdapterMoment}>
@ -160,14 +162,14 @@ export default () => {
>
Сбросить даты
</Button>
<Button
sx={{
m: '10px 0'
}}
onClick={async() =>StatisticsShild(from, to)}
>
Запросить статистику(тест)
</Button>
{/*<Button*/}
{/*sx={{*/}
{/* m: '10px 0'*/}
{/*}}*/}
{/*onClick={async() =>StatisticsShild(from, to)}*/}
{/*>*/}
{/* Запросить статистику(тест)*/}
{/*</Button>*/}
<Table
sx={{
@ -197,6 +199,9 @@ export default () => {
<TableCell sx={{color: "inherit"}} align="center">{Results}</TableCell>
</TableBody>
</Table>
<StatisticSchild/>
</LocalizationProvider>
</>
}

@ -66,7 +66,10 @@ export default function CloseTicketModal({ticketId, openModal, setOpenModal}: Pr
}}
>
<Button
onClick={CloseTicket}
onClick={async ()=>{
CloseTicket()
setOpenModal(false)
}}
sx={{width: "40px", height: "25px"}}
>
Да