2024-01-04 15:18:29 +00:00
|
|
|
|
import { FC, useEffect, useRef, useState } from "react";
|
|
|
|
|
import {
|
|
|
|
|
Box,
|
|
|
|
|
FormControl,
|
|
|
|
|
IconButton,
|
|
|
|
|
Popper,
|
|
|
|
|
TextField,
|
|
|
|
|
Typography,
|
|
|
|
|
} from "@mui/material";
|
2023-12-29 13:32:57 +00:00
|
|
|
|
import { People } from "@mui/icons-material";
|
|
|
|
|
|
|
|
|
|
import { SidebarModal } from "./SidebarModal";
|
|
|
|
|
|
|
|
|
|
import BackArrowIcon from "@icons/BackArrowIcon";
|
2023-09-20 17:39:17 +00:00
|
|
|
|
import { ChartLineUp } from "./icons/ChartLineUp";
|
|
|
|
|
import { ReturnTime } from "./icons/ReturnTime";
|
|
|
|
|
import { Question } from "./icons/Question";
|
|
|
|
|
import { Settings } from "./icons/Settings";
|
|
|
|
|
import { Pencil } from "./icons/Pencil";
|
|
|
|
|
import { ArrowDown } from "./icons/ArrowDown";
|
2024-01-04 18:36:26 +00:00
|
|
|
|
import Sidebar from "@ui_kit/Sidebar/Sidebar";
|
2024-01-04 15:18:29 +00:00
|
|
|
|
import { Link, useNavigate } from "react-router-dom";
|
|
|
|
|
import { updateQuiz } from "@root/quizes/actions";
|
|
|
|
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
2024-01-04 18:36:26 +00:00
|
|
|
|
import { LogoutButton } from "@ui_kit/LogoutButton";
|
|
|
|
|
import { ToTariffsButton } from "@ui_kit/Toolbars/ToTariffsButton";
|
|
|
|
|
import { logout } from "@api/auth";
|
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
|
|
|
|
import { clearAuthToken } from "@frontend/kitui";
|
|
|
|
|
import { clearUserData } from "@root/user";
|
2023-09-20 17:39:17 +00:00
|
|
|
|
|
|
|
|
|
interface Iprops {
|
|
|
|
|
open: boolean;
|
2023-12-29 10:17:43 +00:00
|
|
|
|
changePage: (step: number) => void;
|
2024-02-15 01:19:03 +00:00
|
|
|
|
setHeightSitebar: any;
|
2023-09-20 17:39:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-29 10:17:43 +00:00
|
|
|
|
const quizSetupSteps = [
|
|
|
|
|
{ sidebarIcon: <Pencil style={{ color: "#974BFA", fontSize: "24px" }} /> },
|
|
|
|
|
{ sidebarIcon: <People style={{ color: "#974BFA", fontSize: "24px" }} /> },
|
|
|
|
|
{
|
|
|
|
|
sidebarIcon: <ChartLineUp style={{ color: "#974BFA", fontSize: "24px" }} />,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sidebarIcon: <ReturnTime style={{ color: "#974BFA", fontSize: "24px" }} />,
|
|
|
|
|
},
|
|
|
|
|
{ sidebarIcon: <Question style={{ color: "#974BFA", fontSize: "24px" }} /> },
|
|
|
|
|
] as const;
|
|
|
|
|
|
2024-02-15 01:19:03 +00:00
|
|
|
|
export const SidebarMobile: FC<Iprops> = ({
|
|
|
|
|
open,
|
|
|
|
|
changePage,
|
|
|
|
|
setHeightSitebar,
|
|
|
|
|
}) => {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
2024-01-04 15:18:29 +00:00
|
|
|
|
const [inputOpen, setInputOpen] = useState<boolean>(false);
|
|
|
|
|
const quiz = useCurrentQuiz();
|
|
|
|
|
const ref = useRef(null);
|
2024-02-15 01:19:03 +00:00
|
|
|
|
const heightSidebar = useRef(null);
|
2024-01-04 18:36:26 +00:00
|
|
|
|
const navigate = useNavigate();
|
2024-02-15 01:19:03 +00:00
|
|
|
|
|
|
|
|
|
const observer = useRef(
|
|
|
|
|
new ResizeObserver((entries) => {
|
|
|
|
|
const { height } = entries[0].contentRect;
|
|
|
|
|
setHeightSitebar(height);
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
observer.current.observe(heightSidebar.current);
|
|
|
|
|
}, [heightSidebar, observer]);
|
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const handleClick = (event) => {
|
|
|
|
|
setAnchorEl(anchorEl ? null : event.currentTarget);
|
|
|
|
|
};
|
2024-01-04 18:36:26 +00:00
|
|
|
|
async function handleLogoutClick() {
|
|
|
|
|
const [, logoutError] = await logout();
|
|
|
|
|
|
|
|
|
|
if (logoutError) {
|
|
|
|
|
return enqueueSnackbar(logoutError);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearAuthToken();
|
|
|
|
|
clearUserData();
|
|
|
|
|
navigate("/");
|
|
|
|
|
}
|
2023-09-20 17:39:17 +00:00
|
|
|
|
|
2024-01-04 15:18:29 +00:00
|
|
|
|
const clickInput = (event) => {
|
|
|
|
|
if (ref.current && !ref.current.contains(event.target)) setInputOpen(false);
|
|
|
|
|
};
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
document.addEventListener("mousedown", clickInput);
|
|
|
|
|
return () => {
|
|
|
|
|
document.removeEventListener("mousedown", clickInput);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const openPopper = Boolean(anchorEl);
|
|
|
|
|
const id = openPopper ? "simple-popper" : undefined;
|
2023-12-29 13:32:57 +00:00
|
|
|
|
return (
|
2023-09-20 17:39:17 +00:00
|
|
|
|
<Box
|
2024-02-15 01:19:03 +00:00
|
|
|
|
ref={heightSidebar}
|
2023-12-29 10:17:43 +00:00
|
|
|
|
sx={{
|
2023-12-29 13:32:57 +00:00
|
|
|
|
display: open ? "block" : "none",
|
|
|
|
|
minHeight: "134px",
|
|
|
|
|
padding: "20px 16px 16px 16px",
|
|
|
|
|
background: "#333647",
|
|
|
|
|
borderTop: "1px solid #9A9AAF",
|
|
|
|
|
borderBottomLeftRadius: "8px",
|
|
|
|
|
borderBottomRightRadius: "8px",
|
|
|
|
|
transitionDuration: "200ms",
|
2023-12-29 10:17:43 +00:00
|
|
|
|
}}
|
2023-09-20 17:39:17 +00:00
|
|
|
|
>
|
2023-12-29 13:32:57 +00:00
|
|
|
|
<Box sx={{ display: "flex", alignItems: "center", position: "relative" }}>
|
2024-01-04 15:18:29 +00:00
|
|
|
|
<Link to="/list">
|
|
|
|
|
<IconButton sx={{ p: "6px" }}>
|
|
|
|
|
<BackArrowIcon color={"white"} />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Link>
|
2023-12-29 13:32:57 +00:00
|
|
|
|
|
2024-01-04 15:18:29 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
ml: "15px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "end",
|
|
|
|
|
width: "100%",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-29 13:32:57 +00:00
|
|
|
|
<Box>
|
|
|
|
|
<Typography sx={{ fontSize: "12px", color: "#9A9AAF" }}>
|
|
|
|
|
Название
|
|
|
|
|
</Typography>
|
2024-01-04 15:18:29 +00:00
|
|
|
|
{inputOpen ? (
|
|
|
|
|
<FormControl fullWidth variant="standard">
|
|
|
|
|
<TextField
|
|
|
|
|
ref={ref}
|
|
|
|
|
value={quiz.name}
|
|
|
|
|
onChange={(e) =>
|
|
|
|
|
updateQuiz(quiz.id, (quiz) => {
|
|
|
|
|
quiz.name = e.target.value;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
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: "white",
|
|
|
|
|
"&::placeholder": {
|
|
|
|
|
opacity: 1,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</FormControl>
|
|
|
|
|
) : (
|
2024-02-15 01:19:03 +00:00
|
|
|
|
<Typography color={"white"} sx={{ wordBreak: "break-word" }}>
|
|
|
|
|
{quiz.name}
|
|
|
|
|
</Typography>
|
2024-01-04 15:18:29 +00:00
|
|
|
|
)}
|
2023-12-29 13:32:57 +00:00
|
|
|
|
</Box>
|
2024-01-04 15:18:29 +00:00
|
|
|
|
<IconButton onClick={() => setInputOpen(true)}>
|
|
|
|
|
<Pencil
|
|
|
|
|
style={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
right: "0",
|
|
|
|
|
color: "white",
|
|
|
|
|
fontSize: "24px",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</IconButton>
|
2023-12-29 13:32:57 +00:00
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
width: "100%",
|
2024-01-04 18:36:26 +00:00
|
|
|
|
justifyContent: "space-between",
|
2023-12-29 13:32:57 +00:00
|
|
|
|
display: "flex",
|
|
|
|
|
marginTop: "20px",
|
|
|
|
|
flexWrap: "wrap",
|
|
|
|
|
gap: "5px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-30 00:29:13 +00:00
|
|
|
|
{/*{quizSetupSteps.map(({ sidebarIcon }, index) => (*/}
|
|
|
|
|
{/* <Box*/}
|
|
|
|
|
{/* onClick={() => changePage(index)}*/}
|
|
|
|
|
{/* sx={{*/}
|
|
|
|
|
{/* cursor: "pointer",*/}
|
|
|
|
|
{/* width: "44px",*/}
|
|
|
|
|
{/* height: "44px",*/}
|
|
|
|
|
{/* background: "#262835",*/}
|
|
|
|
|
{/* display: "flex",*/}
|
|
|
|
|
{/* justifyContent: "center",*/}
|
|
|
|
|
{/* alignItems: "center",*/}
|
|
|
|
|
{/* borderRadius: "8px",*/}
|
|
|
|
|
{/* }}*/}
|
|
|
|
|
{/* >*/}
|
|
|
|
|
{/* {sidebarIcon}*/}
|
|
|
|
|
{/* </Box>*/}
|
|
|
|
|
{/*))}*/}
|
2024-01-04 18:36:26 +00:00
|
|
|
|
<Box sx={{ display: "flex" }}>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
ml: "auto",
|
|
|
|
|
gap: "15px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<LogoutButton
|
|
|
|
|
onClick={handleLogoutClick}
|
|
|
|
|
sx={{
|
|
|
|
|
backgroundColor: "transparent",
|
|
|
|
|
border: "1px solid #9A9AAF",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
2023-12-29 10:17:43 +00:00
|
|
|
|
<Box
|
2023-12-31 02:53:25 +00:00
|
|
|
|
aria-describedby={id}
|
2023-12-30 00:29:13 +00:00
|
|
|
|
onClick={handleClick}
|
2023-12-29 10:17:43 +00:00
|
|
|
|
sx={{
|
2023-12-29 13:32:57 +00:00
|
|
|
|
px: "10px",
|
|
|
|
|
width: "70px",
|
2023-12-29 10:17:43 +00:00
|
|
|
|
height: "44px",
|
|
|
|
|
background: "#262835",
|
|
|
|
|
display: "flex",
|
2023-12-29 13:32:57 +00:00
|
|
|
|
justifyContent: "space-between",
|
2023-12-29 10:17:43 +00:00
|
|
|
|
alignItems: "center",
|
|
|
|
|
borderRadius: "8px",
|
2023-12-29 13:32:57 +00:00
|
|
|
|
border: "1px solid #FFFFFF66",
|
|
|
|
|
marginLeft: "28px",
|
2023-12-29 10:17:43 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-29 13:32:57 +00:00
|
|
|
|
<Settings
|
|
|
|
|
style={{ color: "#974BFA", fontSize: "24px", marginLeft: "10px" }}
|
|
|
|
|
/>
|
|
|
|
|
<ArrowDown style={{ color: "#F2F3F7" }} />
|
2023-12-29 10:17:43 +00:00
|
|
|
|
</Box>
|
2023-09-20 17:39:17 +00:00
|
|
|
|
</Box>
|
2023-12-31 02:53:25 +00:00
|
|
|
|
<SidebarModal
|
|
|
|
|
open={openPopper}
|
|
|
|
|
anchorEl={anchorEl}
|
|
|
|
|
handleClick={handleClick}
|
|
|
|
|
id={id}
|
|
|
|
|
changePage={changePage}
|
|
|
|
|
/>
|
2023-09-20 17:39:17 +00:00
|
|
|
|
</Box>
|
2023-12-29 13:32:57 +00:00
|
|
|
|
);
|
|
|
|
|
};
|