diff --git a/src/api/quizStatistic.ts b/src/api/quizStatistic.ts index 0c32a34..0551ada 100644 --- a/src/api/quizStatistic.ts +++ b/src/api/quizStatistic.ts @@ -1,4 +1,5 @@ import makeRequest from "@root/api/makeRequest"; +import {parseAxiosError} from "@root/utils/parse-error"; export type QuizStatisticResponse = { Registrations: number; @@ -25,4 +26,25 @@ export const getStatistic = async ( return { Registrations: 0, Quizes: 0, Results: 0 }; } -}; \ No newline at end of file +}; + +export const getStatisticSchild = async ( + from: any, to: any): Promise => { + try { + const StatisticResponse = await makeRequest({ + url: process.env.REACT_APP_DOMAIN + "/customer/quizlogo/stat" , + method: "post", + useToken: true, + body: { + "to": to, + "from": from, + "page": 0, + "limit": 100 + }, + }); + return StatisticResponse; + } catch (nativeError) { + + return [{ID: 0, Regs: 0, Money: 0, Quizes:[{QuizID: 0, Regs: 0, Money: 0}]}]; + } +}; diff --git a/src/pages/dashboard/Content/QuizStatistic/StatisticSchild.tsx b/src/pages/dashboard/Content/QuizStatistic/StatisticSchild.tsx new file mode 100644 index 0000000..74087a0 --- /dev/null +++ b/src/pages/dashboard/Content/QuizStatistic/StatisticSchild.tsx @@ -0,0 +1,245 @@ +import {useEffect, useState} from "react"; +import moment, {Moment} from "moment"; +import { + Accordion, + AccordionDetails, AccordionSummary, + Box, + Button, + Table, + TableBody, + TableCell, + TableHead, + TableRow, + TextField, + Typography, + useTheme +} from "@mui/material"; +import {AdapterMoment} from "@mui/x-date-pickers/AdapterMoment"; +import { DatePicker, LocalizationProvider } from '@mui/x-date-pickers'; +import ModalUser from "@pages/dashboard/ModalUser"; +import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; +import useSchildStatistic from "@root/utils/hooks/useSchildStatistic"; + +export default function StatisticSchild() { + const theme = useTheme() + const [isOpen, setOpen] = useState(false); + const [isOpenEnd, setOpenEnd] = useState(false); + + const [openUserModal, setOpenUserModal] = useState(false); + const [activeUserId, setActiveUserId] = useState(""); + + const [from, setFrom] = useState(moment("01.01.2023")); + const [to, setTo] = useState(moment(Date.now())); + + const statistic = useSchildStatistic(from, to) + 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(); + } + }; + useEffect(() => { + if (!openUserModal) { + setActiveUserId(""); + } + }, [openUserModal]); + + useEffect(() => { + if (activeUserId) { + setOpenUserModal(true); + + return; + } + + setOpenUserModal(false); + }, [activeUserId]); + + console.log(statistic) + + return( + + Статистика переходов с шильдика + + + Дата начала + + date && setFrom(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 && setTo(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, + }, + }, + }} + /> + + + + + Пользователь + Регистраций + Деньги + Квизы + + + {statistic.map((stat: any) => ( + + setActiveUserId(stat?.ID)} + >{stat?.ID} + setOpenUserModal(false)} + userId={activeUserId} + /> + {stat?.Regs} + {stat?.Money} + + + } + aria-controls="panel1-content" + id="panel1-header" + > + Статистика по квизам + + +
+ + + QuizID + Регистрации + Деньги + + + + {stat?.Quizes.map((quiz:any)=> ( + + {quiz?.QuizID} + {quiz?.Regs} + {quiz?.Money} + + ))} + + +
+ + + + + )) + } + + +
+ ) + +} diff --git a/src/pages/dashboard/Content/QuizStatistic/index.tsx b/src/pages/dashboard/Content/QuizStatistic/index.tsx index 9e93461..172aeba 100644 --- a/src/pages/dashboard/Content/QuizStatistic/index.tsx +++ b/src/pages/dashboard/Content/QuizStatistic/index.tsx @@ -5,9 +5,7 @@ import type { Moment } from "moment"; import { DatePicker, LocalizationProvider } from '@mui/x-date-pickers'; import { useQuizStatistic } from '@root/utils/hooks/useQuizStatistic'; 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 +17,7 @@ export default () => { const [to, setTo] = useState(moment(Date.now())); + const { Registrations, Quizes, Results } = useQuizStatistic({ from, to, @@ -59,29 +58,6 @@ export default () => { } }; - const StatisticsShild = async (from: any, to: any) => { - try { - const StatisticResponse = await makeRequest({ - 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 <> @@ -160,15 +136,6 @@ export default () => { > Сбросить даты - - { {Results}
+ + +
} \ No newline at end of file diff --git a/src/pages/dashboard/Content/Support/TicketList/CloseTicketModal.tsx b/src/pages/dashboard/Content/Support/TicketList/CloseTicketModal.tsx index 450d49c..1c12a27 100644 --- a/src/pages/dashboard/Content/Support/TicketList/CloseTicketModal.tsx +++ b/src/pages/dashboard/Content/Support/TicketList/CloseTicketModal.tsx @@ -66,7 +66,10 @@ export default function CloseTicketModal({ticketId, openModal, setOpenModal}: Pr }} >