2023-11-13 18:04:51 +00:00
|
|
|
|
import { quizApi } from "@api/quiz";
|
|
|
|
|
import { devlog } from "@frontend/kitui";
|
2023-05-31 10:50:30 +00:00
|
|
|
|
import BackArrowIcon from "@icons/BackArrowIcon";
|
2023-11-13 18:04:51 +00:00
|
|
|
|
import { Burger } from "@icons/Burger";
|
2023-05-31 10:50:30 +00:00
|
|
|
|
import EyeIcon from "@icons/EyeIcon";
|
2023-11-13 18:04:51 +00:00
|
|
|
|
import { PenaLogoIcon } from "@icons/PenaLogoIcon";
|
|
|
|
|
import {
|
|
|
|
|
Box,
|
|
|
|
|
Button,
|
|
|
|
|
Container,
|
|
|
|
|
FormControl,
|
2023-12-05 22:59:15 +00:00
|
|
|
|
IconButton, Switch,
|
|
|
|
|
TextField, Typography,
|
2023-11-13 18:04:51 +00:00
|
|
|
|
useMediaQuery,
|
|
|
|
|
useTheme,
|
|
|
|
|
} from "@mui/material";
|
2023-11-14 14:22:10 +00:00
|
|
|
|
import { decrementCurrentStep, resetEditConfig, setQuizes } from "@root/quizes/actions";
|
2023-11-13 18:04:51 +00:00
|
|
|
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
|
|
|
|
import { useQuizStore } from "@root/quizes/store";
|
2023-05-31 10:50:30 +00:00
|
|
|
|
import CustomAvatar from "@ui_kit/Header/Avatar";
|
2023-11-13 18:04:51 +00:00
|
|
|
|
import NavMenuItem from "@ui_kit/Header/NavMenuItem";
|
|
|
|
|
import PenaLogo from "@ui_kit/PenaLogo";
|
2023-05-31 10:50:30 +00:00
|
|
|
|
import Sidebar from "@ui_kit/Sidebar";
|
2023-11-13 18:04:51 +00:00
|
|
|
|
import Stepper from "@ui_kit/Stepper";
|
|
|
|
|
import SwitchStepPages from "@ui_kit/switchStepPages";
|
|
|
|
|
import { isAxiosError } from "axios";
|
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
2023-11-14 14:22:10 +00:00
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
import { Link, useNavigate } from "react-router-dom";
|
2023-11-13 18:04:51 +00:00
|
|
|
|
import useSWR from "swr";
|
2023-09-21 07:00:08 +00:00
|
|
|
|
import { SidebarMobile } from "./Sidebar/SidebarMobile";
|
2023-12-05 22:59:15 +00:00
|
|
|
|
import {cleanQuestions, updateOpenBranchingPanel} from "@root/questions/actions";
|
|
|
|
|
import {BranchingPanel} from "../Questions/BranchingPanel";
|
|
|
|
|
import {useQuestionsStore} from "@root/questions/store";
|
2023-09-21 07:00:08 +00:00
|
|
|
|
|
2023-10-05 10:12:56 +00:00
|
|
|
|
|
2023-09-15 12:37:12 +00:00
|
|
|
|
export default function StartPage() {
|
2023-11-13 18:04:51 +00:00
|
|
|
|
useSWR("quizes", () => quizApi.getList(), {
|
|
|
|
|
onSuccess: setQuizes,
|
|
|
|
|
onError: error => {
|
|
|
|
|
const message = isAxiosError<string>(error) ? (error.response?.data ?? "") : "";
|
2023-09-21 07:00:08 +00:00
|
|
|
|
|
2023-11-14 16:43:21 +00:00
|
|
|
|
devlog("Error getting quiz list", error);
|
2023-11-13 18:04:51 +00:00
|
|
|
|
enqueueSnackbar(`Не удалось получить квизы. ${message}`);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
const theme = useTheme();
|
2023-11-14 14:22:10 +00:00
|
|
|
|
const navigate = useNavigate();
|
2023-11-27 23:07:24 +00:00
|
|
|
|
const editQuizId = useQuizStore(state => state.editQuizId);
|
|
|
|
|
const quiz = useCurrentQuiz();
|
2023-11-13 18:04:51 +00:00
|
|
|
|
const currentStep = useQuizStore(state => state.currentStep);
|
|
|
|
|
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
|
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(660));
|
|
|
|
|
const [mobileSidebar, setMobileSidebar] = useState<boolean>(false);
|
2023-12-05 22:59:15 +00:00
|
|
|
|
const {openBranchingPanel} = useQuestionsStore.getState()
|
2023-11-13 18:04:51 +00:00
|
|
|
|
const quizConfig = quiz?.config;
|
2023-03-03 23:54:19 +00:00
|
|
|
|
|
2023-11-14 14:22:10 +00:00
|
|
|
|
useEffect(() => {
|
2023-11-27 23:07:24 +00:00
|
|
|
|
if (editQuizId === null) navigate("/list");
|
|
|
|
|
}, [navigate, editQuizId]);
|
2023-11-14 14:22:10 +00:00
|
|
|
|
|
2023-11-29 13:49:52 +00:00
|
|
|
|
useEffect(() => () => {
|
|
|
|
|
resetEditConfig();
|
|
|
|
|
cleanQuestions();
|
|
|
|
|
}, []);
|
2023-11-14 14:22:10 +00:00
|
|
|
|
|
2023-11-13 18:04:51 +00:00
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{/*хедер*/}
|
|
|
|
|
<Container
|
|
|
|
|
component="nav"
|
|
|
|
|
maxWidth={false}
|
|
|
|
|
disableGutters
|
2023-10-05 10:12:56 +00:00
|
|
|
|
sx={{
|
2023-11-13 18:04:51 +00:00
|
|
|
|
px: "16px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
height: isMobile ? "51px" : "80px",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
bgcolor: isMobile ? "#333647" : "white",
|
|
|
|
|
borderBottom: "1px solid #E3E3E3",
|
|
|
|
|
zIndex: theme.zIndex.drawer + 1,
|
2023-10-05 10:12:56 +00:00
|
|
|
|
}}
|
2023-09-15 12:37:12 +00:00
|
|
|
|
>
|
2023-11-13 18:04:51 +00:00
|
|
|
|
<Link to="/" style={{ display: "flex" }}>
|
|
|
|
|
{isMobile ? (
|
|
|
|
|
<PenaLogoIcon style={{ fontSize: "39px", color: "white" }} />
|
|
|
|
|
) : (
|
|
|
|
|
<PenaLogo width={124} />
|
|
|
|
|
)}
|
|
|
|
|
</Link>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: isMobile ? "none" : "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
ml: "37px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<IconButton sx={{ p: "6px" }} onClick={decrementCurrentStep}>
|
|
|
|
|
<BackArrowIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<FormControl fullWidth variant="standard">
|
|
|
|
|
<TextField
|
|
|
|
|
fullWidth
|
|
|
|
|
id="project-name"
|
|
|
|
|
placeholder="Название проекта окно"
|
|
|
|
|
sx={{
|
|
|
|
|
width: "270px",
|
|
|
|
|
"& .MuiInputBase-root": {
|
|
|
|
|
height: "34px",
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
p: 0,
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
inputProps={{
|
|
|
|
|
sx: {
|
|
|
|
|
height: "20px",
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
fontSize: "16px",
|
|
|
|
|
lineHeight: "20px",
|
|
|
|
|
p: "7px",
|
|
|
|
|
color: "black",
|
|
|
|
|
"&::placeholder": {
|
|
|
|
|
opacity: 1,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</FormControl>
|
|
|
|
|
</Box>
|
|
|
|
|
{isTablet ? (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
ml: "auto",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{isMobile ? (
|
|
|
|
|
<Burger
|
|
|
|
|
onClick={() => setMobileSidebar(!mobileSidebar)}
|
|
|
|
|
style={{ fontSize: "30px", color: "white", cursor: "pointer" }}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<CustomAvatar
|
|
|
|
|
sx={{
|
|
|
|
|
ml: "11px",
|
|
|
|
|
backgroundColor: theme.palette.orange.main,
|
|
|
|
|
height: "36px",
|
|
|
|
|
width: "36px",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
gap: "30px",
|
|
|
|
|
overflow: "hidden",
|
|
|
|
|
ml: "20px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<NavMenuItem text="Редактировать" isActive />
|
|
|
|
|
<NavMenuItem text="Заявки" />
|
|
|
|
|
<NavMenuItem text="Аналитика" />
|
|
|
|
|
<NavMenuItem text="История" />
|
|
|
|
|
<NavMenuItem text="Помощь" />
|
|
|
|
|
</Box>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
ml: "auto",
|
|
|
|
|
gap: "15px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-03 10:48:00 +00:00
|
|
|
|
<a href={`/view`} target="_blank" rel="noreferrer" style={{ textDecoration: "none" }}>
|
2023-12-01 13:48:25 +00:00
|
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
sx={{
|
|
|
|
|
fontSize: "14px",
|
|
|
|
|
lineHeight: "18px",
|
|
|
|
|
height: "34px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Опубликовать
|
|
|
|
|
</Button>
|
|
|
|
|
</a>
|
2023-11-13 18:04:51 +00:00
|
|
|
|
<CustomAvatar
|
|
|
|
|
sx={{
|
|
|
|
|
ml: "11px",
|
|
|
|
|
backgroundColor: theme.palette.orange.main,
|
|
|
|
|
height: "36px",
|
|
|
|
|
width: "36px",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Container>
|
|
|
|
|
|
2023-09-15 12:37:12 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
2023-11-13 18:04:51 +00:00
|
|
|
|
display: isMobile ? "block" : "flex",
|
2023-09-15 12:37:12 +00:00
|
|
|
|
}}
|
2023-10-31 13:37:30 +00:00
|
|
|
|
>
|
2023-11-13 18:04:51 +00:00
|
|
|
|
{isMobile ? <SidebarMobile open={mobileSidebar} /> : <Sidebar />}
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
background: theme.palette.background.default,
|
|
|
|
|
width: "100%",
|
|
|
|
|
padding: isMobile ? "16px" : "25px",
|
|
|
|
|
height: "calc(100vh - 80px)",
|
|
|
|
|
overflow: "auto",
|
|
|
|
|
boxSizing: "border-box",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{quizConfig &&
|
|
|
|
|
<>
|
|
|
|
|
<Stepper activeStep={currentStep} />
|
|
|
|
|
<SwitchStepPages
|
|
|
|
|
activeStep={currentStep}
|
|
|
|
|
quizType={quizConfig.type}
|
2023-11-27 23:07:24 +00:00
|
|
|
|
quizResults={quizConfig.results}
|
|
|
|
|
quizStartPageType={quizConfig.startpageType}
|
2023-11-13 18:04:51 +00:00
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
</Box>
|
|
|
|
|
{isTablet && [1, 2, 3].includes(currentStep) && (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute",
|
2023-12-05 22:59:15 +00:00
|
|
|
|
left: 0,
|
2023-11-13 18:04:51 +00:00
|
|
|
|
bottom: 0,
|
2023-12-05 22:59:15 +00:00
|
|
|
|
width: "100%",
|
2023-11-13 18:04:51 +00:00
|
|
|
|
padding: "20px 40px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "flex-end",
|
|
|
|
|
gap: "15px",
|
|
|
|
|
background: "#FFF",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-05 22:59:15 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: openBranchingPanel ? "none" : "display",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
gap: "15px",
|
|
|
|
|
padding: "18px",
|
|
|
|
|
background: "#fff",
|
|
|
|
|
borderRadius: "12px",
|
|
|
|
|
boxShadow: "0px 10px 30px #e7e7e7",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Switch
|
|
|
|
|
value={openBranchingPanel}
|
|
|
|
|
onChange={(_, value) => {
|
|
|
|
|
updateOpenBranchingPanel(value)
|
|
|
|
|
}}
|
|
|
|
|
sx={{
|
|
|
|
|
width: 50,
|
|
|
|
|
height: 30,
|
|
|
|
|
padding: 0,
|
|
|
|
|
"& .MuiSwitch-switchBase": {
|
|
|
|
|
padding: 0,
|
|
|
|
|
margin: "2px",
|
|
|
|
|
transitionDuration: "300ms",
|
|
|
|
|
"&.Mui-checked": {
|
|
|
|
|
transform: "translateX(20px)",
|
|
|
|
|
color: theme.palette.brightPurple.main,
|
|
|
|
|
"& + .MuiSwitch-track": {
|
|
|
|
|
backgroundColor: "#E8DCF9",
|
|
|
|
|
opacity: 1,
|
|
|
|
|
border: 0,
|
|
|
|
|
},
|
|
|
|
|
"&.Mui-disabled + .MuiSwitch-track": { opacity: 0.5 },
|
|
|
|
|
},
|
|
|
|
|
"&.Mui-disabled .MuiSwitch-thumb": {
|
|
|
|
|
color:
|
|
|
|
|
theme.palette.mode === "light"
|
|
|
|
|
? theme.palette.grey[100]
|
|
|
|
|
: theme.palette.grey[600],
|
|
|
|
|
},
|
|
|
|
|
"&.Mui-disabled + .MuiSwitch-track": {
|
|
|
|
|
opacity: theme.palette.mode === "light" ? 0.7 : 0.3,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"& .MuiSwitch-thumb": {
|
|
|
|
|
boxSizing: "border-box",
|
|
|
|
|
width: 25,
|
|
|
|
|
height: 25,
|
|
|
|
|
},
|
|
|
|
|
"& .MuiSwitch-track": {
|
|
|
|
|
borderRadius: 13,
|
|
|
|
|
backgroundColor:
|
|
|
|
|
theme.palette.mode === "light" ? "#E9E9EA" : "#39393D",
|
|
|
|
|
opacity: 1,
|
|
|
|
|
transition: theme.transitions.create(["background-color"], {
|
|
|
|
|
duration: 500,
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Box>
|
|
|
|
|
<Typography sx={{ fontWeight: "bold", color: "#4D4D4D" }}>
|
|
|
|
|
Логика ветвления
|
|
|
|
|
</Typography>
|
|
|
|
|
<Typography sx={{ color: "#4D4D4D", fontSize: "12px" }}>
|
|
|
|
|
Настройте связи между вопросами
|
|
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
2023-11-13 18:04:51 +00:00
|
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
sx={{
|
|
|
|
|
fontSize: "14px",
|
|
|
|
|
lineHeight: "18px",
|
|
|
|
|
height: "34px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Опубликовать
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
</>
|
|
|
|
|
);
|
2023-09-15 12:37:12 +00:00
|
|
|
|
}
|