import { FC, useEffect, useRef, useState } from "react"; import { Box, FormControl, IconButton, List, Popper, TextField, Typography, useMediaQuery, useTheme, } from "@mui/material"; import { People } from "@mui/icons-material"; import { SidebarModal } from "./SidebarModal"; import BackArrowIcon from "@icons/BackArrowIcon"; 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"; import Sidebar from "@ui_kit/Sidebar/Sidebar"; import { Link, useLocation, useNavigate } from "react-router-dom"; import { setCurrentStep, updateQuiz } from "@root/quizes/actions"; import { useCurrentQuiz } from "@root/quizes/hooks"; 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"; import CustomTextField from "@ui_kit/CustomTextField"; import PencilCircleIcon from "@icons/PencilCircleIcon"; import { quizSetupSteps } from "@model/quizSettings"; import React from "react"; import { updateNextStep } from "@root/uiTools/actions"; interface SidebarIconProps { height: string; width: string; color: string; } import { cleanAuthTicketData } from "@root/ticket"; interface Iprops { open: boolean; changePage: (step: number) => void; setHeightSitebar: any; } export const SidebarMobile: FC = ({ open, changePage, setHeightSitebar, }) => { const theme = useTheme(); const isWrappSidebar = useMediaQuery(theme.breakpoints.down(400)); const [anchorEl, setAnchorEl] = useState(null); const [inputOpen, setInputOpen] = useState(false); const quiz = useCurrentQuiz(); const [inputValue, setInputValue] = useState(quiz.name); const ref = useRef(null); const heightSidebar = useRef(null); const navigate = useNavigate(); const { pathname } = useLocation(); const observer = useRef( new ResizeObserver((entries) => { const { height } = entries[0].contentRect; setHeightSitebar(height); }), ); useEffect(() => { observer.current.observe(heightSidebar.current); }, [heightSidebar, observer]); const handleClick = (event) => { setAnchorEl(anchorEl ? null : event.currentTarget); }; async function handleLogoutClick() { const [, logoutError] = await logout(); if (logoutError) { return enqueueSnackbar(logoutError); } cleanAuthTicketData() clearAuthToken(); clearUserData(); navigate("/"); } const clickInput = (event) => { if (ref.current && !ref.current.contains(event.target)) setInputOpen(false); }; useEffect(() => { document.addEventListener("mousedown", clickInput); return () => { document.removeEventListener("mousedown", clickInput); }; }, []); const changeMenuItem = (index: number) => { if (!pathname.startsWith("/edit")) { navigate("/edit"); } updateNextStep(index); changePage(index); }; const openPopper = Boolean(anchorEl); const id = openPopper ? "simple-popper" : undefined; return ( Название {inputOpen ? ( { if (e.target.value.length <= 200) { setInputValue(e.target.value); } 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, }, }, }} /> ) : ( {quiz.name} )} setInputOpen(true)}> {quizSetupSteps.map(({ sidebarIcon }, index) => ( changeMenuItem(index)} sx={{ cursor: "pointer", width: isWrappSidebar ? "30px" : "36px", height: isWrappSidebar ? "30px" : "36px", background: "#262835", display: "flex", justifyContent: "center", alignItems: "center", borderRadius: "8px", }} > {React.createElement( sidebarIcon as React.FC, { height: isWrappSidebar ? "25px" : "32px", width: isWrappSidebar ? "25px" : "32px", color: `${theme.palette.brightPurple.main}`, }, )} ))} { navigate("/design"); setCurrentStep(15); }} sx={{ // ml: "4px", cursor: "pointer", width: isWrappSidebar ? "30px" : "36px", height: isWrappSidebar ? "30px" : "36px", background: "#262835", display: "flex", justifyContent: "center", alignItems: "center", borderRadius: "8px", }} > ); };