diff --git a/src/api/quizStatistic.ts b/src/api/quizStatistic.ts deleted file mode 100644 index 217e300..0000000 --- a/src/api/quizStatistic.ts +++ /dev/null @@ -1,67 +0,0 @@ -import makeRequest from "@root/api/makeRequest"; -import {parseAxiosError} from "@root/utils/parse-error"; - -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 }; - } -}; - -export const getStatisticSchild = async ( - from: number, to: number): 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}]}]; - } -}; - export const getStatisticPromocode = async (from: number, to: number): Promise => { - try { - const StatisticPromo = await makeRequest({ - url: process.env.REACT_APP_DOMAIN + "/customer/promocode/ltv" , - method: "post", - useToken: true, - body: { - "to": to, - "from": from, - }, - }); - return StatisticPromo; - } catch (nativeError) { - - console.log(nativeError) - } - } \ No newline at end of file diff --git a/src/api/quizStatistics/index.ts b/src/api/quizStatistics/index.ts new file mode 100644 index 0000000..f2cc2f7 --- /dev/null +++ b/src/api/quizStatistics/index.ts @@ -0,0 +1,82 @@ +import makeRequest from "@root/api/makeRequest"; + +import type { GetStatisticSchildBody, QuizStatisticsItem } from "./types"; + +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 }; + } +}; + +export const getStatisticSchild = async ( + from: number, + to: number +): Promise => { + try { + const StatisticResponse = await makeRequest< + GetStatisticSchildBody, + QuizStatisticsItem[] + >({ + url: process.env.REACT_APP_DOMAIN + "/customer/quizlogo/stat", + method: "post", + useToken: true, + body: { to, from, page: 0, limit: 100 }, + }); + + if (!StatisticResponse) { + throw new Error("Статистика не найдена"); + } + + return StatisticResponse; + } catch (nativeError) { + return [ + { + ID: "0", + Regs: 0, + Money: 0, + Quizes: [{ QuizID: "0", Regs: 0, Money: 0 }], + }, + ]; + } +}; + +export const getStatisticPromocode = async ( + from: number, + to: number +): Promise => { + try { + const StatisticPromo = await makeRequest({ + url: process.env.REACT_APP_DOMAIN + "/customer/promocode/ltv", + method: "post", + useToken: true, + body: { + to: to, + from: from, + }, + }); + + return StatisticPromo; + } catch (nativeError) { + console.log(nativeError); + } +}; diff --git a/src/api/quizStatistics/types.ts b/src/api/quizStatistics/types.ts new file mode 100644 index 0000000..7aaf69d --- /dev/null +++ b/src/api/quizStatistics/types.ts @@ -0,0 +1,21 @@ +import { Moment } from "moment"; + +export type GetStatisticSchildBody = { + to: Moment | null; + from: Moment | null; + page: number; + limit: number; +}; + +type StatisticsQuizes = { + QuizID: string; + Money: number; + Regs: number; +}; + +export type QuizStatisticsItem = { + ID: string; + Money: number; + Quizes: StatisticsQuizes[]; + Regs: number; +}; diff --git a/src/index.tsx b/src/index.tsx index 5959a90..dcff6e9 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -24,7 +24,7 @@ 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 { QuizStatistics } from "@root/pages/dashboard/Content/QuizStatistics"; import theme from "./theme"; import "./index.css"; @@ -106,10 +106,10 @@ root.render( } /> - + } /> @@ -121,7 +121,7 @@ root.render( /> ))} - } /> + } /> } /> diff --git a/src/pages/dashboard/Content/QuizStatistic/StatisticSchild.tsx b/src/pages/dashboard/Content/QuizStatistic/StatisticSchild.tsx deleted file mode 100644 index 7694877..0000000 --- a/src/pages/dashboard/Content/QuizStatistic/StatisticSchild.tsx +++ /dev/null @@ -1,147 +0,0 @@ -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"; -import DateFilter from "@pages/dashboard/Content/QuizStatistic/dateFilter"; - -export default function StatisticSchild() { - const theme = useTheme() - 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) - useEffect(() => { - if (!openUserModal) { - setActiveUserId(""); - } - }, [openUserModal]); - - useEffect(() => { - if (activeUserId) { - setOpenUserModal(true); - - return; - } - - setOpenUserModal(false); - }, [activeUserId]); - - console.log(statistic) - - return( - - Статистика переходов с шильдика - - - - - Пользователь - Регистраций - Деньги - Квизы - - - {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/StstisticPromocode.tsx b/src/pages/dashboard/Content/QuizStatistic/StstisticPromocode.tsx deleted file mode 100644 index edd80a3..0000000 --- a/src/pages/dashboard/Content/QuizStatistic/StstisticPromocode.tsx +++ /dev/null @@ -1,68 +0,0 @@ -import {Button, Table, TableBody, TableCell, TableHead, TableRow, Typography, useTheme} from "@mui/material"; -import {AdapterMoment} from "@mui/x-date-pickers/AdapterMoment"; -import { DatePicker, LocalizationProvider } from '@mui/x-date-pickers'; -import DateFilter from "@pages/dashboard/Content/QuizStatistic/dateFilter"; -import {useState} from "react"; -import moment, {Moment} from "moment"; -import {usePromocodeStatistic} from "@root/utils/hooks/usePromocodeStatistic"; -import {useAllPromocodes} from "@root/api/promocode/swr"; - -export default function StstisticPromocode() { - const theme = useTheme() - const [from, setFrom] = useState(moment("01.01.2023")); - const [to, setTo] = useState(moment(Date.now())); - const promocodes = useAllPromocodes(); - - const statisticPromo = usePromocodeStatistic({to, from}) - - return( - - Статистика промокодов - - - - - Промокод - Регистации - Внесено - - - - {Object.values(statisticPromo || {}).map((sPromo:any)=> { - let codeword - let listPromo = promocodes - let statisticP = statisticPromo - - for (let key in statisticP) { - const codewordSearch = listPromo.find(obj => obj.id === key) - codeword = codewordSearch?.codeword - // console.log(codeword) - } - - return( - - {codeword} - {sPromo.Regs} - {sPromo.Money} - - ) - }) - } -
-
- ) -} \ No newline at end of file diff --git a/src/pages/dashboard/Content/QuizStatistic/dateFilter.tsx b/src/pages/dashboard/Content/QuizStatistic/dateFilter.tsx deleted file mode 100644 index 9d8339e..0000000 --- a/src/pages/dashboard/Content/QuizStatistic/dateFilter.tsx +++ /dev/null @@ -1,119 +0,0 @@ -import {Box, TextField, Typography, useTheme} from "@mui/material"; -import {useState} from "react"; -import moment, {Moment} from "moment"; -import {DatePicker} from "@mui/x-date-pickers"; - -interface Props{ - from: Moment | null, - to: Moment | null, - setFrom: (a: Moment | null) => void, - setTo: (a: Moment | null) => void, -} - -export default function DateFilter({to, setTo, from, setFrom}: Props) { - const theme = useTheme() - const [isOpen, setOpen] = useState(false); - const [isOpenEnd, setOpenEnd] = useState(false); - 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, - }, - }, - }} - /> - - - - ) -} \ No newline at end of file diff --git a/src/pages/dashboard/Content/QuizStatistic/index.tsx b/src/pages/dashboard/Content/QuizStatistic/index.tsx deleted file mode 100644 index 2dbbcea..0000000 --- a/src/pages/dashboard/Content/QuizStatistic/index.tsx +++ /dev/null @@ -1,73 +0,0 @@ -import { Table, TableBody, TableCell, TableHead, TableRow, useTheme, Typography, Box, TextField, Button } from '@mui/material'; -import { useState } from 'react'; -import moment from "moment"; -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 StatisticSchild from "./StatisticSchild"; -import makeRequest from "@root/api/makeRequest"; -import {parseAxiosError} from "@root/utils/parse-error"; -import DateFilter from "@pages/dashboard/Content/QuizStatistic/dateFilter"; -import StstisticPromocode from "@pages/dashboard/Content/QuizStatistic/StstisticPromocode"; - -export default () => { - const theme = useTheme() - 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())); - }; - - return <> - - - - - - - Регистраций - Quiz - Результаты - - - - {Registrations} - {Quizes} - {Results} - -
- - - -
- -} \ No newline at end of file diff --git a/src/pages/dashboard/Content/QuizStatistics/DateFilter.tsx b/src/pages/dashboard/Content/QuizStatistics/DateFilter.tsx new file mode 100644 index 0000000..e664b8a --- /dev/null +++ b/src/pages/dashboard/Content/QuizStatistics/DateFilter.tsx @@ -0,0 +1,122 @@ +import { Box, TextField, Typography, useTheme } from "@mui/material"; +import { useState } from "react"; +import { DatePicker } from "@mui/x-date-pickers"; + +import { StatisticsPromocode } from "./StastisticsPromocode"; + +import type { Moment } from "moment"; + +interface Props { + from: Moment | null; + to: Moment | null; + setFrom: (a: Moment | null) => void; + setTo: (a: Moment | null) => void; +} + +export const DateFilter = ({ to, setTo, from, setFrom }: Props) => { + const theme = useTheme(); + const [isOpen, setOpen] = useState(false); + const [isOpenEnd, setOpenEnd] = useState(false); + 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, + }, + }, + }} + /> + + + + ); +}; diff --git a/src/pages/dashboard/Content/QuizStatistics/QuizInfo.tsx b/src/pages/dashboard/Content/QuizStatistics/QuizInfo.tsx new file mode 100644 index 0000000..5bde905 --- /dev/null +++ b/src/pages/dashboard/Content/QuizStatistics/QuizInfo.tsx @@ -0,0 +1,148 @@ +import { useState } from "react"; +import moment from "moment"; +import { + Table, + TableBody, + TableCell, + TableHead, + TableRow, + Typography, + Box, + TextField, + Button, + useTheme, +} from "@mui/material"; +import { DatePicker } from "@mui/x-date-pickers"; + +import { useQuizStatistic } from "@root/utils/hooks/useQuizStatistic"; + +import type { Moment } from "moment"; + +export const QuizInfo = () => { + const [from, setFrom] = useState(null); + const [to, setTo] = useState(moment(Date.now())); + const theme = useTheme(); + const { Registrations, Quizes, Results } = useQuizStatistic({ + from, + to, + }); + + const resetTime = () => { + setFrom(moment()); + setTo(moment(Date.now())); + }; + + 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} + + + +
+ + ); +}; diff --git a/src/pages/dashboard/Content/QuizStatistics/StastisticsPromocode.tsx b/src/pages/dashboard/Content/QuizStatistics/StastisticsPromocode.tsx new file mode 100644 index 0000000..5f596e8 --- /dev/null +++ b/src/pages/dashboard/Content/QuizStatistics/StastisticsPromocode.tsx @@ -0,0 +1,85 @@ +import { + Table, + TableBody, + TableCell, + TableHead, + TableRow, + Typography, + useTheme, +} from "@mui/material"; +import { AdapterMoment } from "@mui/x-date-pickers/AdapterMoment"; +import { LocalizationProvider } from "@mui/x-date-pickers"; +import { DateFilter } from "./DateFilter"; +import { useState } from "react"; +import moment, { Moment } from "moment"; +import { usePromocodeStatistics } from "@root/utils/hooks/usePromocodeStatistics"; +import { useAllPromocodes } from "@root/api/promocode/swr"; +import { QuizStatisticsItem } from "@root/api/quizStatistics/types"; + +export const StatisticsPromocode = () => { + const [from, setFrom] = useState(moment("01.01.2023")); + const [to, setTo] = useState(moment(Date.now())); + const promocodes = useAllPromocodes(); + const promocodeStatistics = usePromocodeStatistics({ to, from }); + const theme = useTheme(); + + return ( + + Статистика промокодов + + + + + + Промокод + + + Регистации + + + Внесено + + + + + {/* {Object.values(promocodeStatistics).map(({ Regs, Money }) => { + let codeword = ""; + + for (let value in promocodeStatistics) { + const codewordSearch = promocodes.find(({ id }) => id === value); + + codeword = codewordSearch?.codeword ?? ""; + } + + return ( + + + {codeword} + + + {Regs} + + + {Money} + + + ); + })} */} +
+
+ ); +}; diff --git a/src/pages/dashboard/Content/QuizStatistics/StatisticsSchild.tsx b/src/pages/dashboard/Content/QuizStatistics/StatisticsSchild.tsx new file mode 100644 index 0000000..6e0d494 --- /dev/null +++ b/src/pages/dashboard/Content/QuizStatistics/StatisticsSchild.tsx @@ -0,0 +1,195 @@ +import moment from "moment"; +import { useEffect, useState } from "react"; +import { + Accordion, + AccordionDetails, + AccordionSummary, + Table, + TableBody, + TableCell, + TableHead, + TableRow, + Typography, + Button, + useTheme, +} from "@mui/material"; +import { GridToolbar } from "@mui/x-data-grid"; +import { enqueueSnackbar } from "notistack"; +import DataGrid from "@kitUI/datagrid"; + +import ModalUser from "@pages/dashboard/ModalUser"; +import { DateFilter } from "./DateFilter"; + +import { useSchildStatistics } from "@root/utils/hooks/useSchildStatistics"; + +import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; + +import type { Moment } from "moment"; +import type { QuizStatisticsItem } from "@root/api/quizStatistics/types"; +import type { GridColDef } from "@mui/x-data-grid"; + +const COLUMNS: GridColDef[] = [ + { + field: "user", + headerName: "Пользователь", + width: 250, + valueGetter: ({ row }) => row.ID, + }, + { + field: "regs", + headerName: "Регистраций", + width: 200, + valueGetter: ({ row }) => String(row.Regs), + }, + { + field: "money", + headerName: "Деньги", + width: 200, + valueGetter: ({ row }) => String(row.Money), + }, +]; + +export const StatisticsSchild = () => { + const [openUserModal, setOpenUserModal] = useState(false); + const [activeUserId, setActiveUserId] = useState(""); + const [page, setPage] = useState(1); + const [pageSize, setPageSize] = useState(10); + + const [from, setFrom] = useState( + moment(new Date("01.01.2023")) + ); + const [to, setTo] = useState(moment(Date.now())); + + const theme = useTheme(); + const statistics = useSchildStatistics(from, to); + + useEffect(() => { + if (!openUserModal) { + setActiveUserId(""); + } + }, [openUserModal]); + + useEffect(() => { + if (activeUserId) { + setOpenUserModal(true); + + return; + } + + setOpenUserModal(false); + }, [activeUserId]); + + const copyQuizLink = (quizId: string) => { + navigator.clipboard.writeText( + `https://${ + window.location.href.includes("/admin.") ? "" : "s." + }hbpn.link/${quizId}` + ); + + enqueueSnackbar("Ссылка успешно скопирована"); + }; + + return ( + <> + + Статистика переходов с шильдика + + + ID} + checkboxSelection={true} + rows={statistics} + components={{ Toolbar: GridToolbar }} + rowCount={statistics.length} + rowsPerPageOptions={[1, 10, 25, 50, 100]} + paginationMode="client" + disableSelectionOnClick + page={page} + pageSize={pageSize} + onPageChange={setPage} + onPageSizeChange={setPageSize} + onCellClick={({ id, field }) => + field === "user" && setActiveUserId(String(id)) + } + getRowHeight={() => "auto"} + columns={[ + ...COLUMNS, + { + field: "quizes", + headerName: "Квизы", + flex: 1, + minWidth: 220, + valueGetter: ({ row }) => String(row.Quizes.length), + renderCell: ({ row }) => ( + + } + aria-controls="panel1-content" + id="panel1-header" + > + Статистика по квизам + + + + + + + QuizID + + + Регистрации + + + Деньги + + + + + + {row.Quizes.map(({ QuizID, Regs, Money }) => ( + + + + + + {Regs} + + + {Money} + + + ))} + +
+
+
+ ), + }, + ]} + /> + setOpenUserModal(false)} + userId={activeUserId} + /> + + ); +}; diff --git a/src/pages/dashboard/Content/QuizStatistics/index.tsx b/src/pages/dashboard/Content/QuizStatistics/index.tsx new file mode 100644 index 0000000..b060d99 --- /dev/null +++ b/src/pages/dashboard/Content/QuizStatistics/index.tsx @@ -0,0 +1,12 @@ +import { LocalizationProvider } from "@mui/x-date-pickers"; +import { AdapterMoment } from "@mui/x-date-pickers/AdapterMoment"; + +import { QuizInfo } from "./QuizInfo"; +import { StatisticsSchild } from "./StatisticsSchild"; + +export const QuizStatistics = () => ( + + + + +); diff --git a/src/pages/dashboard/Menu/index.tsx b/src/pages/dashboard/Menu/index.tsx index 8856555..a4e355c 100644 --- a/src/pages/dashboard/Menu/index.tsx +++ b/src/pages/dashboard/Menu/index.tsx @@ -100,7 +100,7 @@ const Drawer = styled(MuiDrawer, { shouldForwardProp: (prop) => prop !== "open" })); const links: { path: string; element: JSX.Element; title: string; className: string }[] = [ - { path: "/quizStatistic", element: <>📝, title: "Статистика Quiz", className: "menu" }, + { path: "/quizStatistics", 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/usePromocodeStatistic.ts b/src/utils/hooks/usePromocodeStatistic.ts deleted file mode 100644 index b881980..0000000 --- a/src/utils/hooks/usePromocodeStatistic.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { useEffect, useState } from "react"; - -import type { Moment } from "moment"; -import {getStatisticPromocode} from "@root/api/quizStatistic"; - -interface useStatisticProps { - to: Moment | null; - from: Moment | null; -} - -export function usePromocodeStatistic({ to, from }: useStatisticProps) { - const formatTo = to?.unix(); - const formatFrom = from?.unix(); - - const [statisticPromo, setStatisticPromo] = useState([]) - - useEffect(() => { - - const requestStatistics = async () => { - - const gottenData = await getStatisticPromocode(Number(formatFrom), Number(formatTo)); - setStatisticPromo(gottenData) - } - - requestStatistics(); - }, []); - - return statisticPromo; -} diff --git a/src/utils/hooks/usePromocodeStatistics.ts b/src/utils/hooks/usePromocodeStatistics.ts new file mode 100644 index 0000000..91420ce --- /dev/null +++ b/src/utils/hooks/usePromocodeStatistics.ts @@ -0,0 +1,36 @@ +import { useEffect, useState } from "react"; +import { getStatisticPromocode } from "@root/api/quizStatistics"; + +import type { Moment } from "moment"; +import type { QuizStatisticsItem } from "@root/api/quizStatistics/types"; + +interface useStatisticProps { + to: Moment | null; + from: Moment | null; +} + +export function usePromocodeStatistics({ to, from }: useStatisticProps) { + const formatTo = to?.unix(); + const formatFrom = from?.unix(); + + const [statisticPromo, setStatisticPromo] = useState({ + ID: "0", + Regs: 0, + Money: 0, + Quizes: [{ QuizID: "0", Regs: 0, Money: 0 }], + }); + + useEffect(() => { + const requestStatistics = async () => { + const gottenData = await getStatisticPromocode( + Number(formatFrom), + Number(formatTo) + ); + setStatisticPromo(gottenData); + }; + + requestStatistics(); + }, []); + + return statisticPromo; +} diff --git a/src/utils/hooks/useQuizStatistic.ts b/src/utils/hooks/useQuizStatistic.ts index 22458a7..605b485 100644 --- a/src/utils/hooks/useQuizStatistic.ts +++ b/src/utils/hooks/useQuizStatistic.ts @@ -1,8 +1,5 @@ import { useEffect, useState } from "react"; -import { - QuizStatisticResponse, - getStatistic -} from "@root/api/quizStatistic"; +import { QuizStatisticResponse, getStatistic } from "@root/api/quizStatistics"; import type { Moment } from "moment"; @@ -15,15 +12,20 @@ export function useQuizStatistic({ to, from }: useQuizStatisticProps) { const formatTo = to?.unix(); const formatFrom = from?.unix(); - const [data, setData] = useState({ Registrations: 0, Quizes: 0, Results: 0 }); + const [data, setData] = useState({ + Registrations: 0, + Quizes: 0, + Results: 0, + }); useEffect(() => { - const requestStatistics = async () => { - - const gottenData = await getStatistic(Number(formatTo), Number(formatFrom)); - setData(gottenData) - } + const gottenData = await getStatistic( + Number(formatTo), + Number(formatFrom) + ); + setData(gottenData); + }; requestStatistics(); }, [to, from]); diff --git a/src/utils/hooks/useSchildStatistic.ts b/src/utils/hooks/useSchildStatistic.ts deleted file mode 100644 index 4167d25..0000000 --- a/src/utils/hooks/useSchildStatistic.ts +++ /dev/null @@ -1,17 +0,0 @@ -import {useEffect, useState} from "react"; -import {getStatisticSchild} from "@root/api/quizStatistic"; - - -export default function useSchildStatistic (from: any, to: any){ - const formatTo = to?.unix(); - const formatFrom = from?.unix(); - const [statistic, setStatistic] = useState([]) - useEffect(() => { - const StatisticsShild = async () => { - const gottenData = await getStatisticSchild(Number(formatFrom), Number(formatTo)); - setStatistic(gottenData) - } - StatisticsShild() - }, []); - return statistic -} diff --git a/src/utils/hooks/useSchildStatistics.ts b/src/utils/hooks/useSchildStatistics.ts new file mode 100644 index 0000000..4bcba2c --- /dev/null +++ b/src/utils/hooks/useSchildStatistics.ts @@ -0,0 +1,27 @@ +import { useEffect, useState } from "react"; +import { getStatisticSchild } from "@root/api/quizStatistics"; + +import type { Moment } from "moment"; + +import type { QuizStatisticsItem } from "@root/api/quizStatistics/types"; + +export const useSchildStatistics = (from: Moment | null, to: Moment | null) => { + const formatTo = to?.unix(); + const formatFrom = from?.unix(); + const [statistics, setStatistics] = useState([]); + + useEffect(() => { + const StatisticsShild = async () => { + const gottenData = await getStatisticSchild( + Number(formatFrom), + Number(formatTo) + ); + + setStatistics(gottenData); + }; + + StatisticsShild(); + }, [formatTo, formatFrom]); + + return statistics; +}; diff --git a/tsconfig.json b/tsconfig.json index 64018cf..fe01ca0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,9 +16,7 @@ "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", - "types": ["node"], + "types": ["node"] }, "include": ["src", "**/*.ts"] } - -