2024-01-20 10:27:21 +00:00
|
|
|
|
import {
|
|
|
|
|
Box,
|
|
|
|
|
Typography,
|
|
|
|
|
useTheme,
|
|
|
|
|
useMediaQuery,
|
2024-02-06 02:00:38 +00:00
|
|
|
|
Skeleton,
|
2024-01-20 10:27:21 +00:00
|
|
|
|
} from "@mui/material";
|
|
|
|
|
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 { CardAnswer } from "./CardAnswer";
|
2024-02-20 11:54:08 +00:00
|
|
|
|
import { PrePaymentModal } from "./PrePaymentModal";
|
2024-01-21 22:09:26 +00:00
|
|
|
|
import { FilterModal } from "@ui_kit/Modal/FilterModal/FilterModal";
|
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";
|
2024-02-26 14:22:40 +00:00
|
|
|
|
import { ExportResults, 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-26 14:22:40 +00:00
|
|
|
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
2024-02-09 15:49:24 +00:00
|
|
|
|
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-02-20 11:54:08 +00:00
|
|
|
|
import { useUserStore } from "@root/user";
|
|
|
|
|
|
2024-02-21 21:16:10 +00:00
|
|
|
|
import CustomPagination from "@ui_kit/CustomPagination";
|
|
|
|
|
import SettingResults from "./SettingResults";
|
2024-02-26 14:22:40 +00:00
|
|
|
|
import { DateDefinition, parseFilters, TimeDefinition } from "./helper";
|
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-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-16 21:06:22 +00:00
|
|
|
|
const [page, setPage] = useState(1);
|
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>("За всё время");
|
2024-02-20 11:54:08 +00:00
|
|
|
|
const [prePaymentModalOpen, setPrePaymentModalOpen] =
|
|
|
|
|
useState<boolean>(false);
|
|
|
|
|
const { userAccount } = useUserStore();
|
|
|
|
|
|
2024-02-10 14:02:56 +00:00
|
|
|
|
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 quiz = useCurrentQuiz();
|
2024-02-09 15:49:24 +00:00
|
|
|
|
const { editQuizId } = useQuizStore();
|
2024-02-16 21:19:35 +00:00
|
|
|
|
const { results, total_count } = useResultStore();
|
|
|
|
|
|
2024-02-16 21:58:30 +00:00
|
|
|
|
console.log("Перерендер компонента ", results);
|
2024-02-16 21:19:35 +00:00
|
|
|
|
|
2024-02-16 21:06:22 +00:00
|
|
|
|
const countPagination = Math.ceil(total_count / 10);
|
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
|
|
|
|
|
2024-02-20 11:54:08 +00:00
|
|
|
|
useEffect(() => {
|
2024-02-21 10:26:06 +00:00
|
|
|
|
if (!userAccount) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
!Object.keys(userAccount.privileges || {}).length ||
|
|
|
|
|
userAccount.privileges?.[""]?.amount === 0
|
|
|
|
|
) {
|
2024-02-20 11:54:08 +00:00
|
|
|
|
setPrePaymentModalOpen(true);
|
2024-02-21 10:26:06 +00:00
|
|
|
|
|
|
|
|
|
return;
|
2024-02-20 11:54:08 +00:00
|
|
|
|
}
|
2024-02-21 10:26:06 +00:00
|
|
|
|
|
|
|
|
|
setPrePaymentModalOpen(false);
|
2024-02-20 11:54:08 +00:00
|
|
|
|
}, [userAccount]);
|
|
|
|
|
|
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-26 14:22:40 +00:00
|
|
|
|
const result = await resultApi.getList(
|
|
|
|
|
editQuizId,
|
|
|
|
|
0,
|
|
|
|
|
parseFilters(filterNew, filterDate),
|
|
|
|
|
);
|
2024-02-10 14:02:56 +00:00
|
|
|
|
setResults(result);
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-02-06 02:00:38 +00:00
|
|
|
|
|
2024-02-21 21:16:10 +00:00
|
|
|
|
const PaginationHC = async (e, value) => {
|
|
|
|
|
setPage(value);
|
|
|
|
|
const result = await resultApi.getList(
|
|
|
|
|
editQuizId,
|
|
|
|
|
value - 1,
|
2024-02-26 14:22:40 +00:00
|
|
|
|
parseFilters(filterNew, filterDate),
|
2024-02-21 21:16:10 +00:00
|
|
|
|
);
|
|
|
|
|
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-03-19 15:58:20 +00:00
|
|
|
|
<HeaderFull isRequest={true} sx={{ position: "fixed", zIndex: 9 }} />
|
2024-01-21 22:09:26 +00:00
|
|
|
|
<SectionWrapper
|
2024-03-19 15:58:20 +00:00
|
|
|
|
sx={{ padding: isMobile ? "115px 16px" : "115px 20px 20px" }}
|
2024-01-21 22:09:26 +00:00
|
|
|
|
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",
|
2024-03-19 15:58:20 +00:00
|
|
|
|
|
2024-02-11 19:21:12 +00:00
|
|
|
|
lineHeight: "normal",
|
2024-03-19 15:58:20 +00:00
|
|
|
|
wordBreak: "break-word",
|
2024-02-11 19:21:12 +00:00
|
|
|
|
}}
|
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%",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-02-21 21:16:10 +00:00
|
|
|
|
<SettingResults
|
2024-02-26 14:22:40 +00:00
|
|
|
|
onclickExport={() =>
|
|
|
|
|
ExportResults(
|
|
|
|
|
filterNew,
|
|
|
|
|
filterDate,
|
|
|
|
|
() => setPrePaymentModalOpen(true),
|
|
|
|
|
editQuizId,
|
|
|
|
|
)
|
|
|
|
|
}
|
2024-02-21 21:16:10 +00:00
|
|
|
|
onclickUpdate={async () => {
|
|
|
|
|
const result = await resultApi.getList(
|
|
|
|
|
editQuizId,
|
|
|
|
|
page - 1,
|
2024-02-26 14:22:40 +00:00
|
|
|
|
parseFilters(filterNew, filterDate),
|
2024-02-21 21:16:10 +00:00
|
|
|
|
);
|
|
|
|
|
setResults(result);
|
|
|
|
|
}}
|
|
|
|
|
onclickFilterTablet={() => setFilterModalOpen(true)}
|
|
|
|
|
onclickResetFilers={() => {
|
|
|
|
|
setFilterNew("Все заявки");
|
|
|
|
|
setFilterDate("За всё время");
|
|
|
|
|
}}
|
|
|
|
|
filterNewHC={filterNewHC}
|
|
|
|
|
filterDateHC={filterDateHC}
|
|
|
|
|
itemsTime={itemsTime}
|
|
|
|
|
itemsNews={itemsNews}
|
|
|
|
|
filterDate={filterDate}
|
|
|
|
|
filterNew={filterNew}
|
|
|
|
|
/>
|
2024-01-20 10:27:21 +00:00
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
2024-02-21 21:16:10 +00:00
|
|
|
|
<CustomPagination
|
|
|
|
|
countPagination={countPagination}
|
2024-02-16 21:06:22 +00:00
|
|
|
|
page={page}
|
2024-02-21 21:16:10 +00:00
|
|
|
|
onChange={PaginationHC}
|
2024-02-16 21:06:22 +00:00
|
|
|
|
/>
|
2024-01-20 10:27:21 +00:00
|
|
|
|
|
|
|
|
|
{!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-02-20 11:54:08 +00:00
|
|
|
|
openPrePaymentModal={() => setPrePaymentModalOpen(true)}
|
2024-02-06 02:00:38 +00:00
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})}
|
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-02-20 11:54:08 +00:00
|
|
|
|
<PrePaymentModal
|
|
|
|
|
open={prePaymentModalOpen}
|
|
|
|
|
setOpen={setPrePaymentModalOpen}
|
|
|
|
|
/>
|
2024-01-20 10:27:21 +00:00
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|