diff --git a/src/api/quizStatistic.ts b/src/api/quizStatistic.ts new file mode 100644 index 0000000..2cc5f48 --- /dev/null +++ b/src/api/quizStatistic.ts @@ -0,0 +1,28 @@ +import { makeRequest } from "@frontend/kitui"; + +export type QuizStatisticResponse = { + Registrations: number; + Quizes: number; + Results: number +}; + +type TRequest = { + to: number; + from: number; +}; + +export const getStatistic = async ( + to: number, + from: number, +): Promise => { + try { + const generalResponse = await makeRequest({ + url: `${process.env.REACT_APP_DOMAIN}/squiz/statistic`, + body: { to, from } + }) + return generalResponse; + } catch (nativeError) { + + return { Registrations: 0, Quizes: 0, Results: 0 }; + } +}; \ No newline at end of file diff --git a/src/index.tsx b/src/index.tsx index 0223de9..31299ff 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -24,9 +24,11 @@ import { PromocodeManagement } from "@root/pages/dashboard/Content/PromocodeMana import { SettingRoles } from "@pages/Setting/SettingRoles"; import Support from "@pages/dashboard/Content/Support/Support"; import ChatImageNewWindow from "@pages/dashboard/Content/Support/ChatImageNewWindow"; +import QuizStatistic from "@pages/dashboard/Content/QuizStatistic"; import theme from "./theme"; import "./index.css"; +import { makeRequest } from "@frontend/kitui"; const componentsArray = [ ["/users", ], @@ -104,6 +106,14 @@ root.render( } /> + + + + } + /> {componentsArray.map((element) => ( { + const theme = useTheme() + + const [isOpen, setOpen] = useState(false); + const [isOpenEnd, setOpenEnd] = useState(false); + + const [from, setFrom] = useState(null); + const [to, setTo] = useState(moment(Date.now())); + + + const { Registrations, Quizes, Results } = useQuizStatistic({ + from, + to, + }); + + const resetTime = () => { + setFrom(moment(0)); + setTo(moment(Date.now())); + }; + + 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(); + } + }; + + + 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, + }, + }, + }} + /> + + + + + + + Регистраций + Quiz + Результаты + + + + {Registrations} + {Quizes} + {Results} + +
+
+ +} \ No newline at end of file diff --git a/src/pages/dashboard/Content/Users.tsx b/src/pages/dashboard/Content/Users.tsx index dfc4a89..3ea33aa 100644 --- a/src/pages/dashboard/Content/Users.tsx +++ b/src/pages/dashboard/Content/Users.tsx @@ -131,7 +131,7 @@ const Users: React.FC = () => { ); return ( - + */} prop !== "open" })); const links: { path: string; element: JSX.Element; title: string; className: string }[] = [ + { path: "/quizStatistic", element: <>📝, title: "Статистика Quiz", className: "menu" }, { path: "/users", element: , title: "Информация о проекте", className: "menu" }, { path: "/entities", element: , title: "Юридические лица", className: "menu" }, { path: "/tariffs", element: , title: "Тарифы", className: "menu" }, diff --git a/src/utils/hooks/useQuizStatistic.ts b/src/utils/hooks/useQuizStatistic.ts new file mode 100644 index 0000000..f4554f1 --- /dev/null +++ b/src/utils/hooks/useQuizStatistic.ts @@ -0,0 +1,34 @@ +import { useEffect, useState } from "react"; +import { + QuizStatisticResponse, + getStatistic +} from "@root/api/quizStatistic"; + +import type { Moment } from "moment"; + +interface useQuizStatisticProps { + to: Moment | null; + from: Moment | null; +} + +export function useQuizStatistic({ to, from }: useQuizStatisticProps) { + const formatTo = to?.unix(); + const formatFrom = from?.unix(); + + const [data, setData] = useState({ Registrations: 0, Quizes: 0, Results: 0 }); + + useEffect(() => { + + const requestStatistics = async () => { + console.log("работаю раз") + console.log("работаю два") + + const gottenData = await getStatistic(Number(formatTo), Number(formatFrom)); + setData(gottenData) + } + + requestStatistics(); + }, [to, from]); + + return { ...data }; +}