frontPanel/src/pages/QuizAnswersPage/CardAnswer.tsx

491 lines
16 KiB
TypeScript
Raw Normal View History

2024-01-20 10:27:21 +00:00
import { ArrowDownIcon } from "@icons/questionsPage/ArrowDownIcon";
import {
Box,
Button,
IconButton,
Link,
Modal,
Typography,
useMediaQuery,
useTheme,
} from "@mui/material";
2024-01-20 10:27:21 +00:00
import { FC, useState } from "react";
import { ContactIcon } from "./icons/ContactIcon";
import { MessageIcon } from "./icons/MessageIcon";
import { PhoneIcon } from "./icons/PhoneIcon";
import { DeleteIcon } from "@icons/questionsPage/deleteIcon";
import homeImg from "./images/home.png";
import videoFrame from "./images/videoFrame.png";
import { EyeIcon } from "./icons/EyeIcon";
import { deleteResult, obsolescenceResult } from "@root/results/actions";
import { resultApi } from "@api/result";
import { useQuizStore } from "@root/quizes/store";
import { useQuestionsStore } from "@root/questions/store";
import AddressIcon from "@icons/ContactFormIcon/AddressIcon";
interface Props {
isNew: boolean;
idResult: string;
onClick: () => void;
dayResult: string;
timeResult: string;
name?: string;
phone?: string;
email?: string;
address?: string;
onLossNew?: (id: string) => void;
}
2024-01-20 10:27:21 +00:00
export const CardAnswer = ({
name,
phone,
email,
address,
isNew = true,
idResult,
timeResult,
dayResult,
onLossNew,
}: Props) => {
2024-01-20 10:27:21 +00:00
const [isOpen, setIsOpen] = useState<boolean>(false);
const [openDelete, setOpenDelete] = useState<boolean>(false);
2024-01-20 10:27:21 +00:00
const theme = useTheme();
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
const [resultsAnswer, setResultsAnswer] = useState([]);
const [resultQuiz, setResultQuiz] = useState([]);
const [questionsResultState, setQuestionsResultState] = useState([]);
const { editQuizId } = useQuizStore();
const { questions } = useQuestionsStore();
return (
2024-01-20 10:27:21 +00:00
<Box
onClick={() => {
obsolescenceResult(idResult, editQuizId);
}}
2024-01-20 10:27:21 +00:00
sx={{
2024-01-21 22:09:26 +00:00
borderRadius: "12px",
2024-01-20 10:27:21 +00:00
maxWidth: isTablet ? "450px" : "auto",
width: "100%",
2024-01-21 22:09:26 +00:00
boxShadow:
"0px 2.767px 8.551px 0px rgba(210, 208, 225, 0.07), 0px 6.65px 20.549px 0px rgba(210, 208, 225, 0.10), 0px 12.522px 38.692px 0px rgba(210, 208, 225, 0.12), 0px 22.336px 69.019px 0px rgba(210, 208, 225, 0.14), 0px 41.778px 129.093px 0px rgba(210, 208, 225, 0.17), 0px 100px 309px 0px rgba(210, 208, 225, 0.24)",
2024-01-20 10:27:21 +00:00
}}
>
<Box
sx={{
width: "100%",
2024-01-21 22:09:26 +00:00
display: "flex",
justifyContent: "space-between",
flexDirection: isTablet ? "column" : "-moz-initial",
2024-01-20 10:27:21 +00:00
}}
>
<Box
sx={{
2024-01-21 22:09:26 +00:00
flexDirection: isTablet ? "column" : "-moz-initial",
cursor: "pointer",
p: "20px",
borderRadius: isTablet
? "12px 12px 0 0"
: isOpen
? "12px 0 0 0"
: "12px 0 0 12px",
2024-01-20 10:27:21 +00:00
display: "flex",
alignItems: "flex-start",
2024-01-21 22:09:26 +00:00
background: "#FFF",
width: "100%",
2024-01-20 10:27:21 +00:00
}}
>
2024-01-21 22:09:26 +00:00
<Box
2024-01-20 10:27:21 +00:00
sx={{
2024-01-21 22:09:26 +00:00
width: isTablet ? "100%" : "auto",
display: "flex",
alignItems: "flex-start",
flexDirection: isTablet ? "row-reverse" : "-moz-initial",
justifyContent: isTablet ? "space-between" : "-moz-initial",
pb: isTablet ? "20px" : "0",
mb: isTablet ? "20px" : "0",
borderBottom: isTablet
? "1px solid rgba(154, 154, 175, 0.50)"
: "0",
2024-01-20 10:27:21 +00:00
}}
>
2024-01-21 22:09:26 +00:00
<Box sx={{ display: "flex", alignItems: "center", gap: "6px" }}>
<Box
sx={{
display: "flex",
alignItems: "center",
justifyContent: "center",
width: "30px",
height: "30px",
borderRadius: "50%",
background: "#EEE4FC",
color: "#7E2AEA",
}}
>
{idResult}
2024-01-21 22:09:26 +00:00
</Box>
<IconButton
onClick={async () => {
setIsOpen(!isOpen);
if (!isOpen) {
let resAnswer = await resultApi.getAnswerList(
Number(idResult),
);
let resAnswerOnly = resAnswer.filter(
(res) => res.Result !== true,
);
let resQuiz = resAnswer.filter(
(res) => res.Result === true,
);
setResultQuiz(resQuiz);
setResultsAnswer(resAnswerOnly);
let idResults = resQuiz[0].question_id;
let questionsResult = questions.filter(
(q) => q.backendId === idResults,
);
setQuestionsResultState(questionsResult);
console.log("тут хранятся ответы", resAnswerOnly);
}
}}
>
<ArrowDownIcon
style={{
transform: isOpen ? "rotate(180deg)" : "rotate(360deg)",
}}
fontSize="10px"
/>
</IconButton>
2024-01-21 22:09:26 +00:00
</Box>
2024-01-20 10:27:21 +00:00
2024-01-21 22:09:26 +00:00
<Typography
sx={{
ml: isTablet ? "0" : "50px",
mr: isTablet ? "0" : "188px",
fontSize: "18px",
color: "#7E2AEA",
maxWidth: "143px",
width: "100%",
}}
>
{dayResult} в {timeResult}
2024-01-20 10:27:21 +00:00
</Typography>
</Box>
2024-01-21 22:09:26 +00:00
<Box sx={{ display: "flex", flexDirection: "column", gap: "10px" }}>
{name && (
<Box sx={{ display: "flex", alignItems: "center", gap: "13px" }}>
<ContactIcon />
<Typography sx={{ fontSize: "18px", color: "#4D4D4D" }}>
{name}
</Typography>
</Box>
)}
{email && (
<Box sx={{ display: "flex", alignItems: "center", gap: "13px" }}>
<MessageIcon />
<Typography sx={{ fontSize: "18px", color: "#4D4D4D" }}>
{email}
</Typography>
</Box>
)}
{phone && (
<Box sx={{ display: "flex", alignItems: "center", gap: "13px" }}>
<PhoneIcon />
<Typography sx={{ fontSize: "18px", color: "#4D4D4D" }}>
{phone}
</Typography>
</Box>
)}
{address && (
<Box sx={{ display: "flex", alignItems: "center", gap: "13px" }}>
<AddressIcon color={"#9A9AAF"} />
<Typography sx={{ fontSize: "18px", color: "#4D4D4D" }}>
{address}
</Typography>
</Box>
)}
2024-01-21 22:09:26 +00:00
</Box>
2024-01-20 10:27:21 +00:00
{!isTablet && isNew && (
2024-01-20 10:27:21 +00:00
<Typography
sx={{
2024-01-21 22:09:26 +00:00
ml: "auto",
2024-01-20 10:27:21 +00:00
display: "flex",
alignItems: "center",
justifyContent: "center",
background: "#FB5607",
borderRadius: "8px",
width: "77px",
height: "36px",
color: "white",
}}
>
Новая
</Typography>
2024-01-21 22:09:26 +00:00
)}
</Box>
<Box
sx={{
borderRadius: "8px",
p: isTablet ? "20px" : "0",
cursor: "pointer",
display: "flex",
alignItems: "center",
justifyContent: isTablet ? "space-between" : "center",
width: isTablet ? "100%" : "100px",
background: "#F2F3F7",
}}
>
{isTablet && isNew ? (
2024-01-21 22:09:26 +00:00
<>
<Typography
sx={{
display: "flex",
alignItems: "center",
justifyContent: "center",
background: "#FB5607",
borderRadius: "8px",
width: "77px",
height: "36px",
color: "white",
2024-01-20 10:27:21 +00:00
}}
2024-01-21 22:09:26 +00:00
>
Новая
</Typography>
<Box sx={{ display: "flex", alignItems: "center" }}>
<IconButton onClick={() => setOpenDelete(true)}>
<DeleteIcon color="#4D4D4D" fontSize="34px" />
</IconButton>
2024-01-21 22:09:26 +00:00
</Box>
</>
) : (
<IconButton onClick={() => setOpenDelete(true)}>
<DeleteIcon color="#4D4D4D" fontSize="34px" />
</IconButton>
2024-01-21 22:09:26 +00:00
)}
<Modal open={openDelete} onClose={() => setOpenDelete(false)}>
<Box
sx={{
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
padding: "30px",
borderRadius: "10px",
background: "#FFFFFF",
}}
>
<Typography variant="h6" sx={{ textAlign: "center" }}>
Вы уверены, что хотите удалить этот результат?
</Typography>
<Box
sx={{
marginTop: "30px",
display: "flex",
justifyContent: "center",
gap: "15px",
}}
>
<Button
variant="contained"
sx={{ minWidth: "150px" }}
onClick={() => setOpenDelete(false)}
>
Отмена
</Button>
<Button
variant="contained"
sx={{ minWidth: "150px" }}
onClick={() => {
deleteResult(Number(idResult));
setOpenDelete(false);
}}
>
Подтвердить
</Button>
</Box>
</Box>
</Modal>
2024-01-21 22:09:26 +00:00
</Box>
2024-01-20 10:27:21 +00:00
</Box>
{isOpen && (
<Box
sx={{
2024-01-21 22:09:26 +00:00
borderRadius: "12px",
2024-01-20 10:27:21 +00:00
maxWidth: isTablet ? "450px" : "auto",
width: "100%",
boxShadow:
"0px 2.767px 8.551px 0px rgba(210, 208, 225, 0.07), 0px 6.65px 20.549px 0px rgba(210, 208, 225, 0.10), 0px 12.522px 38.692px 0px rgba(210, 208, 225, 0.12), 0px 22.336px 69.019px 0px rgba(210, 208, 225, 0.14), 0px 41.778px 129.093px 0px rgba(210, 208, 225, 0.17), 0px 100px 309px 0px rgba(210, 208, 225, 0.24)",
}}
>
<Box
sx={{
p: "20px",
borderTop: "1px solid #F1F2F6",
background: "#FFF",
borderRadius: "0 0 12px 12px",
}}
>
<Typography sx={{ fontSize: "18px", color: "#9A9AAF" }}>
Ответы
</Typography>
</Box>
<Box
sx={{
display: "flex",
gap: isTablet ? "0" : "149px",
p: "20px",
flexDirection: isTablet ? "column" : "-moz-initial",
}}
>
<Box
sx={{
display: "flex",
flexDirection: "column",
gap: "15px",
mt: "20px",
}}
>
{resultsAnswer.map((answer, id) => {
let titleQuestion;
let typeOuestion;
let typeQuestionFile;
let quest = questions; //массив с вопросами
let i;
let idAnswer = answer.question_id; //айди вопроса у ответа
for (i in quest) {
if (quest[i].backendId === idAnswer) {
titleQuestion = quest[i].title;
typeOuestion = quest[i].type;
typeQuestionFile = quest[i].content.type;
}
}
return (
<Box
sx={{ display: "flex", alignItems: "center", gap: "13px" }}
>
<Typography sx={{ fontSize: "18px", color: "#9A9AAF" }}>
{id + 1}. {titleQuestion}.
</Typography>
{typeOuestion === "file" && (
<Link
download
href={answer.content}
style={{
color: "#7E2AEA",
display: "flex",
gap: "10px",
}}
>
{typeQuestionFile === "video" && (
<video
src={answer.content}
width={40}
height={40}
></video>
)}
{typeQuestionFile === "picture" && (
<img src={answer.content} width={40} height={40} />
)}
2024-02-14 02:24:25 +00:00
клик для скачивания
</Link>
)}
{(typeOuestion === "images" ||
typeOuestion === "varimg") && (
<>
<img
width={40}
height={40}
src={
answer.content
.split("<")[1]
.split('src="')[1]
.split('"/>')[0]
}
/>
<Typography sx={{ fontSize: "18px" }}>
{answer.content.split("<")[0]}
</Typography>
</>
)}
{!(
typeOuestion === "file" ||
typeOuestion === "images" ||
typeOuestion === "varimg"
) && (
<Typography sx={{ fontSize: "18px" }}>
{answer.content}
</Typography>
)}
</Box>
);
})}
2024-01-20 10:27:21 +00:00
</Box>
</Box>
<Box
sx={{
p: "20px",
borderTop: "1px solid #F1F2F6",
background: "#FFF",
borderRadius: "0 0 12px 12px",
}}
>
<Typography sx={{ fontSize: "18px", color: "#9A9AAF" }}>
Результаты
</Typography>
</Box>
{questionsResultState.map((res) => {
console.log(questionsResultState, "что за результат тут");
return (
<Box
sx={{
display: "flex",
flexDirection: "column",
gap: "15px",
p: "20px",
}}
>
<Typography
sx={{
fontSize: "18px",
fontWeight: "500",
wordBreak: "break-word",
}}
>
{res.description}
</Typography>
<Typography sx={{ fontSize: "18px", wordBreak: "break-word" }}>
{res.title}
</Typography>
{res.content.useImage &&
res.content.back &&
res.content.back !== " " && (
<img
src={res.content.back}
style={{ width: "40px", height: "40px" }}
alt={""}
/>
)}
{!res.content.useImage &&
res.content.back &&
res.content.back !== " " && (
<video
src={res.content.back}
style={{ width: "40px", height: "40px" }}
></video>
)}
</Box>
);
})}
2024-01-20 10:27:21 +00:00
</Box>
)}
</Box>
);
};