2023-12-16 14:55:56 +00:00
|
|
|
import {
|
|
|
|
Box,
|
|
|
|
Button,
|
|
|
|
ButtonBase,
|
|
|
|
Link,
|
|
|
|
Paper,
|
|
|
|
Typography,
|
|
|
|
useMediaQuery,
|
|
|
|
useTheme,
|
|
|
|
} from "@mui/material";
|
2023-12-17 13:22:21 +00:00
|
|
|
import YoutubeEmbedIframe from "./tools/YoutubeEmbedIframe";
|
2023-12-16 14:55:56 +00:00
|
|
|
import { QuizStartpageAlignType, QuizStartpageType } from "@model/quizSettings";
|
|
|
|
import { notReachable } from "../../utils/notReachable";
|
|
|
|
import { useUADevice } from "../../utils/hooks/useUADevice";
|
2023-12-17 13:22:21 +00:00
|
|
|
import { useQuestionsStore } from "@root/quizData/store";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
interface Props {
|
2023-12-17 13:22:21 +00:00
|
|
|
setVisualStartPage: (a: boolean) => void
|
2023-12-16 14:55:56 +00:00
|
|
|
}
|
|
|
|
|
2023-12-17 13:22:21 +00:00
|
|
|
export const StartPageViewPublication = ({ setVisualStartPage }: Props) => {
|
2023-12-16 14:55:56 +00:00
|
|
|
const theme = useTheme();
|
|
|
|
const { isMobileDevice } = useUADevice();
|
|
|
|
|
2023-12-17 13:22:21 +00:00
|
|
|
const { settings } = useQuestionsStore()
|
|
|
|
|
|
|
|
if (!settings) return null;
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
const handleCopyNumber = () => {
|
2023-12-17 18:15:59 +00:00
|
|
|
navigator.clipboard.writeText(settings?.cfg.info.phonenumber);
|
2023-12-16 14:55:56 +00:00
|
|
|
};
|
|
|
|
|
2023-12-17 18:15:59 +00:00
|
|
|
const background = settings?.cfg.startpage.background.type === "image"
|
|
|
|
? settings?.cfg.startpage.background.desktop
|
2023-12-16 14:55:56 +00:00
|
|
|
? (
|
|
|
|
<img
|
2023-12-17 18:15:59 +00:00
|
|
|
src={settings?.cfg.startpage.background.desktop}
|
2023-12-16 14:55:56 +00:00
|
|
|
alt=""
|
|
|
|
style={{
|
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
|
|
|
objectFit: "cover",
|
|
|
|
overflow: "hidden"
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
: null
|
2023-12-17 18:15:59 +00:00
|
|
|
: settings?.cfg.startpage.background.type === "video"
|
|
|
|
? settings?.cfg.startpage.background.video
|
2023-12-16 14:55:56 +00:00
|
|
|
? (
|
2023-12-17 18:15:59 +00:00
|
|
|
<YoutubeEmbedIframe videoUrl={settings?.cfg.startpage.background.video}
|
2023-12-16 14:55:56 +00:00
|
|
|
containerSX={{
|
2023-12-17 18:15:59 +00:00
|
|
|
width: settings?.cfg.startpageType === "centered" ? "550px" : settings?.cfg.startpageType === "expanded" ? "100vw" : "100%",
|
|
|
|
height: settings?.cfg.startpageType === "centered" ? "275px" : settings?.cfg.startpageType === "expanded" ? "100vh" : "100%",
|
|
|
|
borderRadius: settings?.cfg.startpageType === "centered" ? "10px" : "0",
|
2023-12-16 14:55:56 +00:00
|
|
|
overflow: "hidden",
|
|
|
|
"& iframe": {
|
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
2023-12-17 18:15:59 +00:00
|
|
|
transform: settings?.cfg.startpageType === "centered" ? "" : settings?.cfg.startpageType === "expanded" ? "scale(1.5)" : "scale(2.4)",
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
: null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Paper className="quiz-preview-draghandle"
|
|
|
|
sx={{
|
|
|
|
height: "100vh",
|
2023-12-17 18:15:59 +00:00
|
|
|
background: settings?.cfg.startpageType === "expanded" ?
|
|
|
|
settings?.cfg.startpage.position === "left" ? "linear-gradient(90deg,#272626,transparent)" :
|
|
|
|
settings?.cfg.startpage.position === "center" ? "linear-gradient(180deg,transparent,#272626)" :
|
2023-12-17 13:22:21 +00:00
|
|
|
"linear-gradient(270deg,#272626,transparent)"
|
|
|
|
: "",
|
2023-12-17 18:15:59 +00:00
|
|
|
color: settings?.cfg.startpageType === "expanded" ? "white" : "black"
|
2023-12-17 13:22:21 +00:00
|
|
|
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
}}>
|
|
|
|
<QuizPreviewLayoutByType
|
2023-12-17 13:22:21 +00:00
|
|
|
quizHeaderBlock={<Box
|
2023-12-17 18:15:59 +00:00
|
|
|
p={settings?.cfg.startpageType === "standard" ? "" : "16px"}
|
2023-12-16 14:55:56 +00:00
|
|
|
>
|
|
|
|
<Box sx={{
|
|
|
|
display: "flex",
|
|
|
|
alignItems: "center",
|
|
|
|
gap: "20px",
|
|
|
|
mb: "7px"
|
|
|
|
}}>
|
2023-12-17 18:15:59 +00:00
|
|
|
{settings?.cfg.startpage.logo && (
|
2023-12-16 14:55:56 +00:00
|
|
|
<img
|
2023-12-17 18:15:59 +00:00
|
|
|
src={settings?.cfg.startpage.logo}
|
2023-12-16 14:55:56 +00:00
|
|
|
style={{
|
|
|
|
height: "37px",
|
|
|
|
maxWidth: "43px",
|
|
|
|
objectFit: "cover",
|
|
|
|
}}
|
|
|
|
alt=""
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<Typography sx={{ fontSize: "14px" }}>
|
2023-12-17 18:15:59 +00:00
|
|
|
{settings?.cfg.info.orgname}
|
2023-12-16 14:55:56 +00:00
|
|
|
</Typography>
|
|
|
|
</Box>
|
2023-12-17 18:15:59 +00:00
|
|
|
<Link mb="16px" href={settings?.cfg.info.site}>
|
2023-12-16 14:55:56 +00:00
|
|
|
<Typography sx={{ fontSize: "16px", color: theme.palette.brightPurple.main }}>
|
2023-12-17 18:15:59 +00:00
|
|
|
{settings?.cfg.info.site}
|
2023-12-16 14:55:56 +00:00
|
|
|
</Typography>
|
|
|
|
</Link>
|
|
|
|
</Box>}
|
|
|
|
quizMainBlock={<>
|
|
|
|
<Box sx={{
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column",
|
|
|
|
justifyContent: "center",
|
2023-12-17 18:15:59 +00:00
|
|
|
alignItems: settings?.cfg.startpageType === "centered" ? "center" :
|
|
|
|
settings?.cfg.startpageType === "expanded"
|
|
|
|
? settings?.cfg.startpage.position === "center" ?
|
2023-12-17 13:22:21 +00:00
|
|
|
"center"
|
|
|
|
: "start" : "start",
|
2023-12-16 14:55:56 +00:00
|
|
|
mt: "28px",
|
|
|
|
width: "100%"
|
|
|
|
}}>
|
|
|
|
<Typography sx={{
|
|
|
|
fontWeight: "bold",
|
|
|
|
fontSize: "26px",
|
|
|
|
fontStyle: "normal",
|
|
|
|
fontStretch: "normal",
|
|
|
|
lineHeight: "1.2",
|
2023-12-17 13:22:21 +00:00
|
|
|
}}>{settings.name}</Typography>
|
2023-12-16 14:55:56 +00:00
|
|
|
<Typography sx={{
|
|
|
|
fontSize: "16px",
|
|
|
|
m: "16px 0"
|
|
|
|
}}>
|
2023-12-17 18:15:59 +00:00
|
|
|
{settings?.cfg.startpage.description}
|
2023-12-16 14:55:56 +00:00
|
|
|
</Typography>
|
2023-12-17 18:15:59 +00:00
|
|
|
<Box width={settings?.cfg.startpageType === "standard" ? "100%" : "auto"}>
|
2023-12-16 14:55:56 +00:00
|
|
|
<Button
|
|
|
|
variant="contained"
|
|
|
|
sx={{
|
|
|
|
fontSize: "16px",
|
|
|
|
padding: "10px 15px",
|
2023-12-17 18:15:59 +00:00
|
|
|
width: settings?.cfg.startpageType === "standard" ? "100%" : "auto"
|
2023-12-16 14:55:56 +00:00
|
|
|
}}
|
2023-12-17 13:22:21 +00:00
|
|
|
onClick={() => setVisualStartPage(false)}
|
2023-12-16 14:55:56 +00:00
|
|
|
>
|
2023-12-17 18:15:59 +00:00
|
|
|
{settings?.cfg.startpage.button.trim() ? settings?.cfg.startpage.button : "Пройти тест"}
|
2023-12-16 14:55:56 +00:00
|
|
|
</Button>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
mt: "46px"
|
|
|
|
}}
|
|
|
|
>
|
2023-12-17 18:15:59 +00:00
|
|
|
{settings?.cfg.info.clickable ? (
|
2023-12-16 14:55:56 +00:00
|
|
|
isMobileDevice ? (
|
2023-12-17 18:15:59 +00:00
|
|
|
<Link href={`tel:${settings?.cfg.info.phonenumber}`}>
|
2023-12-16 14:55:56 +00:00
|
|
|
<Typography sx={{ fontSize: "16px", color: theme.palette.brightPurple.main }}>
|
2023-12-17 18:15:59 +00:00
|
|
|
{settings?.cfg.info.phonenumber}
|
2023-12-16 14:55:56 +00:00
|
|
|
</Typography>
|
|
|
|
</Link>
|
|
|
|
) : (
|
|
|
|
<ButtonBase onClick={handleCopyNumber}>
|
|
|
|
<Typography sx={{ fontSize: "16px", color: theme.palette.brightPurple.main }}>
|
2023-12-17 18:15:59 +00:00
|
|
|
{settings?.cfg.info.phonenumber}
|
2023-12-16 14:55:56 +00:00
|
|
|
</Typography>
|
|
|
|
</ButtonBase>
|
|
|
|
)
|
|
|
|
) : (
|
|
|
|
<Typography sx={{ fontSize: "16px", color: theme.palette.brightPurple.main }}>
|
2023-12-17 18:15:59 +00:00
|
|
|
{settings?.cfg.info.phonenumber}
|
2023-12-16 14:55:56 +00:00
|
|
|
</Typography>
|
|
|
|
)}
|
|
|
|
<Typography sx={{ fontSize: "12px", textAlign: "end" }}>
|
2023-12-17 18:15:59 +00:00
|
|
|
{settings?.cfg.info.law}
|
2023-12-16 14:55:56 +00:00
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
</>}
|
|
|
|
backgroundBlock={background}
|
2023-12-17 18:15:59 +00:00
|
|
|
startpageType={settings?.cfg.startpageType}
|
|
|
|
alignType={settings?.cfg.startpage.position}
|
2023-12-16 14:55:56 +00:00
|
|
|
/>
|
|
|
|
</Paper>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function QuizPreviewLayoutByType({ quizHeaderBlock, quizMainBlock, backgroundBlock, startpageType, alignType }: {
|
|
|
|
quizHeaderBlock: JSX.Element;
|
|
|
|
quizMainBlock: JSX.Element;
|
|
|
|
backgroundBlock: JSX.Element | null;
|
|
|
|
startpageType: QuizStartpageType;
|
|
|
|
alignType: QuizStartpageAlignType;
|
|
|
|
}) {
|
|
|
|
const theme = useTheme();
|
|
|
|
const isTablet = useMediaQuery(theme.breakpoints.down(630));
|
|
|
|
|
|
|
|
switch (startpageType) {
|
|
|
|
case null:
|
|
|
|
case "standard": {
|
|
|
|
return (
|
|
|
|
<Box sx={{
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: alignType === "left" ? "row" : "row-reverse",
|
|
|
|
flexGrow: 1,
|
|
|
|
height: "100vh",
|
|
|
|
"&::-webkit-scrollbar": { width: 0 },
|
|
|
|
}}>
|
|
|
|
<Box sx={{
|
|
|
|
width: !isTablet ? "40%" : "100%",
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
alignItems: !isTablet ? "flex-start" : "center",
|
|
|
|
p: "25px"
|
|
|
|
}}>
|
|
|
|
{quizHeaderBlock}
|
|
|
|
{quizMainBlock}
|
|
|
|
</Box>
|
|
|
|
<Box sx={{
|
|
|
|
width: "60%",
|
|
|
|
overflow: "hidden"
|
|
|
|
}}>
|
|
|
|
{backgroundBlock}
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
case "expanded": {
|
|
|
|
return (
|
|
|
|
<Box sx={{
|
|
|
|
position: "relative",
|
|
|
|
display: "flex",
|
|
|
|
justifyContent: startpageAlignTypeToJustifyContent[alignType],
|
|
|
|
flexGrow: 1,
|
|
|
|
height: "100%",
|
|
|
|
"&::-webkit-scrollbar": { width: 0 },
|
|
|
|
}}>
|
|
|
|
<Box sx={{
|
|
|
|
width: "40%",
|
|
|
|
position: "relative",
|
|
|
|
padding: "16px",
|
|
|
|
zIndex: 2,
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
alignItems: alignType === "center" ? "center" : "start",
|
|
|
|
}}>
|
|
|
|
{quizHeaderBlock}
|
|
|
|
{quizMainBlock}
|
|
|
|
</Box>
|
|
|
|
<Box sx={{
|
|
|
|
position: "absolute",
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
height: "100%",
|
|
|
|
width: "100%",
|
|
|
|
zIndex: 1,
|
|
|
|
overflow: "hidden"
|
|
|
|
}}>
|
|
|
|
{backgroundBlock}
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
case "centered": {
|
|
|
|
return (
|
|
|
|
<Box sx={{
|
|
|
|
padding: "16px",
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column",
|
|
|
|
justifyContent: "center",
|
|
|
|
alignItems: "center",
|
|
|
|
height: "100%",
|
|
|
|
"&::-webkit-scrollbar": { width: 0 },
|
|
|
|
overflow: "hidden"
|
|
|
|
}}>
|
|
|
|
{quizHeaderBlock}
|
|
|
|
{backgroundBlock &&
|
|
|
|
<Box>
|
|
|
|
{backgroundBlock}
|
|
|
|
</Box>
|
|
|
|
}
|
|
|
|
{quizMainBlock}
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
default: notReachable(startpageType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const startpageAlignTypeToJustifyContent: Record<QuizStartpageAlignType, "start" | "center" | "end"> = {
|
|
|
|
left: "start",
|
|
|
|
center: "center",
|
|
|
|
right: "end",
|
|
|
|
};
|