2024-01-20 10:27:21 +00:00
|
|
|
|
import {
|
|
|
|
|
Box,
|
|
|
|
|
Button,
|
|
|
|
|
IconButton,
|
|
|
|
|
Typography,
|
2024-02-10 01:41:13 +00:00
|
|
|
|
MenuItem,
|
2024-01-20 10:27:21 +00:00
|
|
|
|
useTheme,
|
|
|
|
|
useMediaQuery,
|
2024-02-06 02:00:38 +00:00
|
|
|
|
Skeleton,
|
2024-02-10 01:41:13 +00:00
|
|
|
|
FormControl,
|
2024-01-20 10:27:21 +00:00
|
|
|
|
} from "@mui/material";
|
2024-02-10 14:02:56 +00:00
|
|
|
|
import { Select } from "../../pages/Questions/Select";
|
2024-02-10 01:41:13 +00:00
|
|
|
|
import moment from "moment";
|
2024-01-20 10:27:21 +00:00
|
|
|
|
import HeaderFull from "@ui_kit/Header/HeaderFull";
|
|
|
|
|
import SectionWrapper from "@ui_kit/SectionWrapper";
|
2024-02-09 09:09:18 +00:00
|
|
|
|
import { FC, useEffect, useState } from "react";
|
2024-01-20 10:27:21 +00:00
|
|
|
|
import { FileExportIcon } from "./icons/FileExporIcon";
|
|
|
|
|
import { UpdateIcon } from "./icons/UpdateIcon";
|
|
|
|
|
import { CheckboxSelect } from "../../ui_kit/CheckboxSelect";
|
|
|
|
|
import { CardAnswer } from "./CardAnswer";
|
|
|
|
|
import { FilterIcon } from "./icons/FilterIcon";
|
2024-01-21 22:09:26 +00:00
|
|
|
|
import { FilterModal } from "@ui_kit/Modal/FilterModal/FilterModal";
|
|
|
|
|
import { ExportContactsModal } from "@ui_kit/Modal/ExportContactsModal";
|
2024-02-09 15:49:24 +00:00
|
|
|
|
|
2024-02-10 01:41:13 +00:00
|
|
|
|
import { resultApi } from "@api/result";
|
2024-02-10 14:02:56 +00:00
|
|
|
|
import { useResultStore } from "@root/results/store";
|
|
|
|
|
import { setResults } from "@root/results/actions";
|
2024-02-09 15:49:24 +00:00
|
|
|
|
|
|
|
|
|
import { quizApi } from "@api/quiz";
|
2024-02-06 02:00:38 +00:00
|
|
|
|
import { setQuizes } from "@root/quizes/actions";
|
2024-02-09 15:49:24 +00:00
|
|
|
|
import { useCurrentQuiz, useQuizes } from "@root/quizes/hooks";
|
|
|
|
|
import { useQuizStore } from "@root/quizes/store";
|
2024-02-10 01:41:13 +00:00
|
|
|
|
import { questionApi } from "@api/question";
|
2024-02-11 19:21:12 +00:00
|
|
|
|
import { setQuestions } from "@root/questions/actions";
|
2024-01-20 10:27:21 +00:00
|
|
|
|
|
2024-02-10 14:02:56 +00:00
|
|
|
|
const itemsCities = [
|
2024-01-20 10:27:21 +00:00
|
|
|
|
{ label: "Муром (1)", value: "option1" },
|
|
|
|
|
{ label: "Москва (1)", value: "option2" },
|
|
|
|
|
];
|
|
|
|
|
|
2024-02-10 01:41:13 +00:00
|
|
|
|
const itemsTime = [
|
2024-02-10 14:02:56 +00:00
|
|
|
|
"За всё время",
|
2024-02-10 01:41:13 +00:00
|
|
|
|
"Сегодня",
|
|
|
|
|
"Вчера",
|
|
|
|
|
"Последние 7 дней",
|
|
|
|
|
"Последние 30 дней",
|
|
|
|
|
"Этот месяц",
|
|
|
|
|
];
|
2024-02-11 19:21:12 +00:00
|
|
|
|
const itemsNews = ["Все заявки", "Новые"];
|
2024-02-09 19:08:04 +00:00
|
|
|
|
|
2024-02-10 14:02:56 +00:00
|
|
|
|
const resetTime = () => {
|
|
|
|
|
return Math.round(Number(moment().format("X")) / 86400 - 1) * 86400 - 0;
|
2024-02-10 01:41:13 +00:00
|
|
|
|
};
|
2024-02-09 15:49:24 +00:00
|
|
|
|
|
2024-01-20 10:27:21 +00:00
|
|
|
|
export const QuizAnswersPage: FC = () => {
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
|
2024-01-21 22:09:26 +00:00
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(600));
|
2024-02-09 15:49:24 +00:00
|
|
|
|
|
2024-01-21 22:09:26 +00:00
|
|
|
|
const [filterModalOpen, setFilterModalOpen] = useState<boolean>(false);
|
2024-02-11 19:21:12 +00:00
|
|
|
|
const [exportContactsModalOpen, setExportContactsModalOpen] =
|
|
|
|
|
useState<boolean>(false);
|
2024-02-10 01:41:13 +00:00
|
|
|
|
const [filterNew, setFilterNew] = useState<string>("Все заявки");
|
2024-02-10 14:02:56 +00:00
|
|
|
|
const [filterDate, setFilterDate] = useState<string>("За всё время");
|
|
|
|
|
const filterNewHC = (value: string) => {
|
2024-02-11 19:21:12 +00:00
|
|
|
|
setFilterNew(value);
|
|
|
|
|
};
|
2024-02-10 14:02:56 +00:00
|
|
|
|
const filterDateHC = (value: string) => {
|
2024-02-11 19:21:12 +00:00
|
|
|
|
setFilterDate(value);
|
|
|
|
|
};
|
2024-02-09 15:49:24 +00:00
|
|
|
|
|
2024-02-06 02:00:38 +00:00
|
|
|
|
const quizList = useQuizStore();
|
|
|
|
|
const quiz = useCurrentQuiz();
|
2024-02-09 15:49:24 +00:00
|
|
|
|
const { editQuizId } = useQuizStore();
|
2024-02-06 02:00:38 +00:00
|
|
|
|
const { results } = useResultStore();
|
|
|
|
|
const { total_count } = useResultStore();
|
2024-02-09 15:49:24 +00:00
|
|
|
|
// const {idResultArray, addIdResult, clearIdResultArray} = useObsolescenceIdResult()
|
2024-02-06 02:00:38 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
getData();
|
2024-02-10 14:02:56 +00:00
|
|
|
|
}, [filterNew, filterDate]);
|
2024-02-06 02:00:38 +00:00
|
|
|
|
|
|
|
|
|
const DateDefinition = (result: string) => {
|
|
|
|
|
//определяем когда был получен результат - вчера, сегодня или число и месяц
|
|
|
|
|
let restime = new Date(result);
|
|
|
|
|
let timeCompleting = Date.parse(String(result));
|
|
|
|
|
const timeNow = Date.now();
|
|
|
|
|
let dayResult;
|
|
|
|
|
if (timeNow - timeCompleting < 86400000) {
|
|
|
|
|
dayResult = "Сегодня";
|
|
|
|
|
}
|
|
|
|
|
if (172800000 > timeNow - timeCompleting > 86400000) {
|
|
|
|
|
dayResult = "Вчера";
|
|
|
|
|
} else {
|
|
|
|
|
dayResult = restime.toLocaleDateString();
|
|
|
|
|
}
|
|
|
|
|
return dayResult;
|
|
|
|
|
};
|
|
|
|
|
const TimeDefinition = (result: string) => {
|
|
|
|
|
//достаём время
|
|
|
|
|
let timeResult = new Date(result).toLocaleTimeString().slice(0, -3);
|
|
|
|
|
return timeResult;
|
|
|
|
|
};
|
2024-02-10 14:02:56 +00:00
|
|
|
|
const parseFilters = () => {
|
2024-02-11 19:21:12 +00:00
|
|
|
|
const filters: any = {};
|
2024-02-10 14:02:56 +00:00
|
|
|
|
|
2024-02-11 19:21:12 +00:00
|
|
|
|
if (filterNew === "Новые") filters.new = true;
|
2024-02-10 14:02:56 +00:00
|
|
|
|
if (filterDate.length !== 0 && filterDate !== "За всё время") {
|
2024-02-11 19:21:12 +00:00
|
|
|
|
console.log(filterDate);
|
2024-02-10 14:02:56 +00:00
|
|
|
|
|
2024-02-11 19:21:12 +00:00
|
|
|
|
filters.to = new Date();
|
2024-02-10 14:02:56 +00:00
|
|
|
|
|
2024-02-11 19:21:12 +00:00
|
|
|
|
let resetedCurrentTime = Number(resetTime());
|
|
|
|
|
if (filterDate === "Сегодня")
|
|
|
|
|
filters.from = moment.unix(resetedCurrentTime)._d;
|
|
|
|
|
if (filterDate === "Вчера")
|
|
|
|
|
filters.from = moment.unix(resetedCurrentTime - 86400)._d;
|
|
|
|
|
if (filterDate === "Последние 7 дней")
|
|
|
|
|
filters.from = moment.unix(resetedCurrentTime - 604800)._d;
|
|
|
|
|
if (filterDate === "Последние 30 дней")
|
|
|
|
|
filters.from = moment.unix(resetedCurrentTime - 2592000)._d;
|
2024-02-10 14:02:56 +00:00
|
|
|
|
if (filterDate === "Этот месяц") {
|
2024-02-11 19:21:12 +00:00
|
|
|
|
let date = new Date(),
|
|
|
|
|
y = date.getFullYear(),
|
|
|
|
|
m = date.getMonth();
|
|
|
|
|
filters.from = new Date(y, m, 1);
|
2024-02-10 14:02:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-11 19:21:12 +00:00
|
|
|
|
return filters;
|
|
|
|
|
};
|
2024-02-10 14:02:56 +00:00
|
|
|
|
const getData = async () => {
|
|
|
|
|
if (editQuizId !== null) {
|
|
|
|
|
const quizes = await quizApi.getList();
|
|
|
|
|
setQuizes(quizes);
|
|
|
|
|
|
2024-02-11 19:21:12 +00:00
|
|
|
|
const questions = await questionApi.getList({ quiz_id: editQuizId });
|
|
|
|
|
setQuestions(questions);
|
|
|
|
|
|
2024-02-10 14:02:56 +00:00
|
|
|
|
const result = await resultApi.getList(editQuizId, parseFilters());
|
|
|
|
|
setResults(result);
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-02-06 02:00:38 +00:00
|
|
|
|
|
|
|
|
|
if (quiz === undefined)
|
|
|
|
|
return (
|
|
|
|
|
<Skeleton sx={{ width: "100vw", height: "100vh", transform: "none" }} />
|
|
|
|
|
);
|
|
|
|
|
|
2024-01-20 10:27:21 +00:00
|
|
|
|
return (
|
|
|
|
|
<Box>
|
2024-02-09 19:05:40 +00:00
|
|
|
|
<HeaderFull isRequest={true} />
|
2024-01-21 22:09:26 +00:00
|
|
|
|
<SectionWrapper
|
|
|
|
|
sx={{ padding: isMobile ? "0 16px" : "20px" }}
|
|
|
|
|
maxWidth="lg"
|
|
|
|
|
>
|
2024-01-20 10:27:21 +00:00
|
|
|
|
<Typography
|
2024-02-11 19:21:12 +00:00
|
|
|
|
sx={{
|
|
|
|
|
fontSize: "36px",
|
|
|
|
|
fontWeight: "500",
|
|
|
|
|
mb: "50px",
|
|
|
|
|
mt: "60px",
|
|
|
|
|
lineHeight: "normal",
|
|
|
|
|
}}
|
2024-01-20 10:27:21 +00:00
|
|
|
|
>
|
2024-02-06 02:00:38 +00:00
|
|
|
|
{quiz.name}
|
2024-01-20 10:27:21 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
width: "100%",
|
|
|
|
|
display: isTablet ? "flex" : "-moz-initial",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box sx={{ display: "flex", alignItems: "center", gap: "8px" }}>
|
|
|
|
|
<Typography sx={{ fontSize: "18px", color: "#4D4D4D" }}>
|
|
|
|
|
Ответы на квиз
|
|
|
|
|
</Typography>
|
|
|
|
|
<Typography sx={{ fontSize: "18px", color: "#9A9AAF" }}>
|
2024-02-06 02:00:38 +00:00
|
|
|
|
({total_count})
|
2024-01-20 10:27:21 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
mt: "20px",
|
|
|
|
|
mb: "31px",
|
|
|
|
|
gap: "30px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
width: isTablet ? "auto" : "100%",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box sx={{ display: "flex", alignItems: "center", gap: "10px" }}>
|
|
|
|
|
<IconButton
|
2024-02-10 14:02:56 +00:00
|
|
|
|
onClick={async () => {
|
2024-02-11 19:21:12 +00:00
|
|
|
|
const data = await resultApi.export(
|
|
|
|
|
editQuizId,
|
|
|
|
|
parseFilters(),
|
|
|
|
|
);
|
|
|
|
|
console.log(typeof data);
|
2024-02-10 16:31:27 +00:00
|
|
|
|
|
2024-02-11 19:21:12 +00:00
|
|
|
|
const blob = data;
|
2024-02-10 16:31:27 +00:00
|
|
|
|
const link = document.createElement("a");
|
|
|
|
|
link.href = window.URL.createObjectURL(blob);
|
|
|
|
|
link.download = `report_${new Date().getTime()}.xlsx`;
|
|
|
|
|
link.click();
|
2024-02-09 09:09:18 +00:00
|
|
|
|
}}
|
2024-01-20 10:27:21 +00:00
|
|
|
|
sx={{
|
|
|
|
|
width: "44px",
|
|
|
|
|
height: "44px",
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
border: "1px solid #7E2AEA",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<FileExportIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<IconButton
|
|
|
|
|
sx={{
|
|
|
|
|
width: "44px",
|
|
|
|
|
height: "44px",
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
border: "1px solid #7E2AEA",
|
|
|
|
|
}}
|
2024-02-09 19:05:40 +00:00
|
|
|
|
onClick={async () => {
|
2024-02-11 19:21:12 +00:00
|
|
|
|
const result = await resultApi.getList(
|
|
|
|
|
editQuizId,
|
|
|
|
|
parseFilters(),
|
|
|
|
|
);
|
2024-02-09 19:05:40 +00:00
|
|
|
|
console.log(result);
|
|
|
|
|
setResults(result);
|
2024-02-06 02:00:38 +00:00
|
|
|
|
}}
|
2024-01-20 10:27:21 +00:00
|
|
|
|
>
|
|
|
|
|
<UpdateIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
|
|
|
|
|
{isTablet && (
|
|
|
|
|
<IconButton
|
2024-01-21 22:09:26 +00:00
|
|
|
|
onClick={() => setFilterModalOpen(true)}
|
2024-01-20 10:27:21 +00:00
|
|
|
|
sx={{
|
2024-01-21 22:09:26 +00:00
|
|
|
|
background: "#fff",
|
2024-01-20 10:27:21 +00:00
|
|
|
|
width: "44px",
|
|
|
|
|
height: "44px",
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
border: "1px solid #7E2AEA",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<FilterIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
{!isTablet && (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
gap: "20px",
|
|
|
|
|
width: "100%",
|
|
|
|
|
justifyContent: "flex-end",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-02-10 14:02:56 +00:00
|
|
|
|
<Select
|
|
|
|
|
items={itemsTime}
|
|
|
|
|
data={filterDate}
|
|
|
|
|
onChange={filterDateHC}
|
|
|
|
|
placeholder="За всё время"
|
|
|
|
|
/>
|
|
|
|
|
<Select
|
|
|
|
|
items={itemsNews}
|
|
|
|
|
data={filterNew}
|
|
|
|
|
onChange={filterNewHC}
|
|
|
|
|
placeholder="Все заявки"
|
|
|
|
|
/>
|
2024-01-20 10:27:21 +00:00
|
|
|
|
|
|
|
|
|
<Button
|
2024-02-10 01:41:13 +00:00
|
|
|
|
onClick={() => {
|
|
|
|
|
setFilterNew("Все заявки");
|
2024-02-10 14:02:56 +00:00
|
|
|
|
setFilterDate("За всё время");
|
2024-02-10 01:41:13 +00:00
|
|
|
|
}}
|
2024-01-20 10:27:21 +00:00
|
|
|
|
sx={{
|
|
|
|
|
maxWidth: "200px",
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "48px",
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
border: "1px solid #7E2AEA",
|
|
|
|
|
color: "#7E2AEA",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Сбросить фильтры
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
{!isTablet && (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
width: "100%",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
mb: "15px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography sx={{ fontSize: "18px", color: "#9A9AAF", mr: "40px" }}>
|
|
|
|
|
№ заявки
|
|
|
|
|
</Typography>
|
|
|
|
|
<Typography sx={{ fontSize: "18px", color: "#9A9AAF" }}>
|
|
|
|
|
Дата
|
|
|
|
|
</Typography>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{ fontSize: "18px", color: "#9A9AAF", ml: "288px" }}
|
|
|
|
|
>
|
|
|
|
|
Контакты
|
|
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "flex-start",
|
|
|
|
|
flexDirection: isTablet ? "-moz-initial" : "column",
|
|
|
|
|
flexWrap: isTablet ? "wrap" : "nowrap",
|
|
|
|
|
gap: "20px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-02-06 02:00:38 +00:00
|
|
|
|
{results.map((result) => {
|
|
|
|
|
const dataResult = new Date(result.created_at);
|
|
|
|
|
let dayResult = DateDefinition(result.created_at);
|
|
|
|
|
let timeResult = TimeDefinition(result.created_at);
|
|
|
|
|
return (
|
|
|
|
|
<CardAnswer
|
|
|
|
|
name={result.content.name}
|
|
|
|
|
email={result.content.email}
|
2024-02-16 00:11:28 +00:00
|
|
|
|
phone={result.content.phone}
|
|
|
|
|
address={result.content.address}
|
2024-02-06 02:00:38 +00:00
|
|
|
|
isNew={result.new}
|
|
|
|
|
idResult={result.id}
|
|
|
|
|
dayResult={dayResult}
|
|
|
|
|
timeResult={timeResult}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2024-01-20 10:27:21 +00:00
|
|
|
|
</Box>
|
|
|
|
|
</SectionWrapper>
|
2024-01-21 22:09:26 +00:00
|
|
|
|
|
|
|
|
|
<FilterModal
|
|
|
|
|
open={filterModalOpen}
|
|
|
|
|
handleClose={() => setFilterModalOpen(false)}
|
2024-02-10 01:41:13 +00:00
|
|
|
|
filterNew={filterNew}
|
|
|
|
|
filterDate={filterDate}
|
2024-02-10 14:02:56 +00:00
|
|
|
|
setFilterNew={filterNewHC}
|
|
|
|
|
setFilterDate={filterDateHC}
|
|
|
|
|
itemsTime={itemsTime}
|
|
|
|
|
itemsNews={itemsNews}
|
2024-01-21 22:09:26 +00:00
|
|
|
|
/>
|
2024-01-20 10:27:21 +00:00
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|