import * as React from "react"; import { getQuestionByContentId, updateQuestion, } from "@root/questions/actions"; import CustomTextField from "@ui_kit/CustomTextField"; import { Box, IconButton, Paper, Button, Typography, TextField, useMediaQuery, useTheme, FormControl, Popover, } from "@mui/material"; import MiniButtonSetting from "@ui_kit/MiniButtonSetting"; import ExpandLessIconBG from "@icons/ExpandLessIconBG"; import ExpandLessIcon from "@mui/icons-material/ExpandLess"; import Trash from "@icons/trash"; import Info from "@icons/Info"; import SettingIcon from "@icons/questionsPage/settingIcon"; import { QuizQuestionResult } from "@model/questionTypes/result"; import { MediaSelectionAndDisplay } from "@ui_kit/MediaSelectionAndDisplay"; interface Props { resultContract: boolean; resultData: QuizQuestionResult; } export const checkEmptyData = ({ resultData, }: { resultData: QuizQuestionResult; }) => { let check = true; if ( resultData.title?.length > 0 || resultData.description?.length > 0 || resultData.content.back?.length > 0 || resultData.content.originalBack?.length > 0 || resultData.content.innerName?.length > 0 || resultData.content.text?.length > 0 || resultData.content.video?.length > 0 || resultData.content.hint.text?.length > 0 ) check = false; return check; }; const InfoView = ({ resultData }: { resultData: QuizQuestionResult }) => { const checkEmpty = checkEmptyData({ resultData }); const question = getQuestionByContentId(resultData.content.rule.parentId); const [anchorEl, setAnchorEl] = React.useState( null ); const handleClick = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; const handleClose = () => { setAnchorEl(null); }; const open = Boolean(anchorEl); const id = open ? "simple-popover" : undefined; return ( <> {resultData?.content.rule.parentId === "line" ? "Единый результат в конце прохождения опросника без ветвления" : `Заголовок вопроса, после которого появится результат: "${ question?.title || "нет заголовка" }"`} {checkEmpty && ( Вы не заполнили этот результат никакими данными )} ); }; export const ResultCard = ({ resultContract, resultData }: Props) => { const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down(790)); const isTablet = useMediaQuery(theme.breakpoints.down(800)); const [expand, setExpand] = React.useState(true); const [resultCardSettings, setResultCardSettings] = React.useState(false); const [buttonPlus, setButtonPlus] = React.useState(true); const question = getQuestionByContentId(resultData.content.rule.parentId); React.useEffect(() => { setExpand(true); }, [resultContract]); return ( {resultData?.content.rule.parentId === "line" ? "Единый результат в конце прохождения опросника без ветвления" : `Заголовок вопроса, после которого появится результат: "${ question?.title || "нет заголовка" }"`} updateQuestion( resultData.id, (question) => (question.title = target.value) ) } sx={{ margin: isMobile ? "10px 0" : 0, "& .MuiInputBase-root": { color: "#000000", backgroundColor: expand ? theme.palette.background.default : "transparent", height: "48px", borderRadius: "10px", ".MuiOutlinedInput-notchedOutline": { borderWidth: "1px !important", border: !expand ? "none" : null, }, "& .MuiInputBase-input::placeholder": { color: "#4D4D4D", opacity: 0.8, }, }, }} inputProps={{ sx: { p: 0, fontSize: "18px", lineHeight: "21px", }, }} /> setExpand(!expand)} > {expand ? ( ) : ( )} {expand && ( <> updateQuestion( resultData.id, (question) => (question.title = target.value) ) } /> setExpand(!expand)} > updateQuestion( resultData.id, (question) => (question.description = target.value) ) } placeholder={"Заголовок пожирнее"} sx={{ borderRadius: "8px", height: "48px", width: "100%", }} /> updateQuestion( resultData.id, (question) => (question.content.text = target.value) ) } fullWidth placeholder="Описание" multiline rows={4} sx={{ "& .MuiInputBase-root": { backgroundColor: "#F2F3F7", width: "100%", height: "110px", borderRadius: "10px", }, }} inputProps={{ sx: { height: "85px", borderRadius: "10px", fontSize: "18px", lineHeight: "21px", py: 0, }, }} /> {buttonPlus ? ( ) : ( Призыв к действию { setButtonPlus(true); updateQuestion( resultData.id, (q) => (q.content.hint.text = "") ); }} > updateQuestion( resultData.id, (question) => (question.content.hint.text = target.value) ) } fullWidth placeholder="Например: узнать подробнее" sx={{ "& .MuiInputBase-root": { backgroundColor: "#F2F3F7", width: "409px", height: "48px", borderRadius: "8px", }, }} inputProps={{ sx: { height: "85px", borderRadius: "10px", fontSize: "18px", lineHeight: "21px", py: 0, }, }} /> )} { setResultCardSettings(!resultCardSettings); }} sx={{ backgroundColor: resultCardSettings ? theme.palette.brightPurple.main : "transparent", color: resultCardSettings ? "#ffffff" : theme.palette.grey3.main, "&:hover": { backgroundColor: resultCardSettings ? "#581CA7" : "#7E2AEA", color: "white", }, }} > {!isTablet && "Настройки"} {resultCardSettings && ( updateQuestion( resultData.id, (question) => (question.content.innerName = target.value) ) } /> )} )} ); };