diff --git a/src/api/quizStatistic.ts b/src/api/quizStatistic.ts index 0551ada..217e300 100644 --- a/src/api/quizStatistic.ts +++ b/src/api/quizStatistic.ts @@ -29,7 +29,7 @@ export const getStatistic = async ( }; export const getStatisticSchild = async ( - from: any, to: any): Promise => { + from: number, to: number): Promise => { try { const StatisticResponse = await makeRequest({ url: process.env.REACT_APP_DOMAIN + "/customer/quizlogo/stat" , @@ -48,3 +48,20 @@ export const getStatisticSchild = async ( 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/pages/dashboard/Content/QuizStatistic/StatisticSchild.tsx b/src/pages/dashboard/Content/QuizStatistic/StatisticSchild.tsx index 74087a0..7694877 100644 --- a/src/pages/dashboard/Content/QuizStatistic/StatisticSchild.tsx +++ b/src/pages/dashboard/Content/QuizStatistic/StatisticSchild.tsx @@ -19,12 +19,10 @@ 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 [isOpen, setOpen] = useState(false); - const [isOpenEnd, setOpenEnd] = useState(false); - const [openUserModal, setOpenUserModal] = useState(false); const [activeUserId, setActiveUserId] = useState(""); @@ -32,35 +30,6 @@ export default function StatisticSchild() { 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(""); @@ -82,74 +51,7 @@ export default function StatisticSchild() { 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, - }, - }, - }} - /> - + (moment("01.01.2023")); + const [to, setTo] = useState(moment(Date.now())); + + const statisticPromo = usePromocodeStatistic({to, from}) + + return( + + Статистика промокодов + +
+ + + Промокод + Регистации + Внесено + + + + {/*{Registrations}*/} + {/*{Quizes}*/} + {/*{Results}*/} + +
+
+ ) +} \ No newline at end of file diff --git a/src/pages/dashboard/Content/QuizStatistic/dateFilter.tsx b/src/pages/dashboard/Content/QuizStatistic/dateFilter.tsx new file mode 100644 index 0000000..9d8339e --- /dev/null +++ b/src/pages/dashboard/Content/QuizStatistic/dateFilter.tsx @@ -0,0 +1,119 @@ +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 index 172aeba..2dbbcea 100644 --- a/src/pages/dashboard/Content/QuizStatistic/index.tsx +++ b/src/pages/dashboard/Content/QuizStatistic/index.tsx @@ -6,18 +6,16 @@ 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 [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, @@ -28,106 +26,9 @@ export default () => { 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, - }, - }, - }} - /> - +