Merge branch 'dev' into 'staging'

Dev

See merge request frontend/squzanswerer!115
This commit is contained in:
Nastya 2024-04-17 16:48:39 +00:00
commit a788c619fb
2 changed files with 723 additions and 696 deletions

@ -1,3 +1,4 @@
import { FC, useRef, useState, useEffect } from "react";
import AddressIcon from "@icons/ContactFormIcon/AddressIcon";
import EmailIcon from "@icons/ContactFormIcon/EmailIcon";
import NameIcon from "@icons/ContactFormIcon/NameIcon";
@ -11,11 +12,10 @@ import {
TextField as MuiTextField,
TextFieldProps,
Typography,
useTheme
useTheme,
} from "@mui/material";
import CustomCheckbox from "@ui_kit/CustomCheckbox";
import { FC, useRef, useState } from "react";
import { DESIGN_LIST } from "@/utils/designList";
import { sendFC } from "@api/quizRelase";
@ -27,9 +27,9 @@ import { quizThemes } from "@utils/themes/Publication/themePublication";
import { enqueueSnackbar } from "notistack";
import { useRootContainerSize } from "../../contexts/RootContainerWidthContext";
const TextField = MuiTextField as unknown as FC<TextFieldProps>; // temporary fix ts(2590)
const EMAIL_REGEXP = /^(([^<>()[\].,:\s@"]+(\.[^<>()[\].,:\s@"]+)*)|(".+"))@(([^<>()[\].,:\s@"]+\.)+[^<>()[\].,:\s@"]{2,})$/iu;
const EMAIL_REGEXP =
/^(([^<>()[\].,:\s@"]+(\.[^<>()[\].,:\s@"]+)*)|(".+"))@(([^<>()[\].,:\s@"]+\.)+[^<>()[\].,:\s@"]{2,})$/iu;
type Props = {
currentQuestion: AnyTypedQuizQuestion;
@ -46,13 +46,27 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
const [phone, setPhone] = useState("");
const [text, setText] = useState("");
const [adress, setAdress] = useState("");
const [screenHeight, setScreenHeight] = useState<number>(window.innerHeight);
const fireOnce = useRef(true);
const [fire, setFire] = useState(false);
const isMobile = useRootContainerSize() < 850;
const isTablet = useRootContainerSize() < 1000;
const resultQuestion = currentQuestion.type === "result"
useEffect(() => {
function handleResize() {
setScreenHeight(window.innerHeight);
}
window.addEventListener("resize", handleResize);
return () => {
window.removeEventListener("resize", handleResize);
};
}, []);
const resultQuestion =
currentQuestion.type === "result"
? currentQuestion
: questions.find((question): question is QuizQuestionResult => {
if (settings?.cfg.haveRoot) {
@ -62,7 +76,8 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
);
} else {
return (
question.type === "result" && question.content.rule.parentId === "line"
question.type === "result" &&
question.content.rule.parentId === "line"
);
}
});
@ -84,7 +99,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
questionId: currentQuestion.id,
body: body,
qid: quizId,
preview
preview,
});
const sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
@ -98,7 +113,8 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
}
};
const FCcopy: any = settings.cfg.formContact.fields || settings.cfg.formContact;
const FCcopy: any =
settings.cfg.formContact.fields || settings.cfg.formContact;
const filteredFC: any = {};
for (const i in FCcopy) {
@ -108,22 +124,21 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
}
}
async function handleShowResultsClick() {
const FC: any = settings.cfg.formContact.fields;
if (FC["email"].used !== EMAIL_REGEXP.test(email)) {
return enqueueSnackbar("введена некорректная почта");
}
if (fireOnce.current) {
if (
name.length === 0
&& email.length === 0
&& phone.length === 0
&& text.length === 0
&& adress.length === 0
) return enqueueSnackbar("Пожалуйста, заполните поля");
name.length === 0 &&
email.length === 0 &&
phone.length === 0 &&
text.length === 0 &&
adress.length === 0
)
return enqueueSnackbar("Пожалуйста, заполните поля");
//почта валидна, хоть одно поле заполнено
setFire(true);
@ -134,10 +149,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
localStorage.getItem("sessions") || "{}"
);
sessions[quizId] = Date.now();
localStorage.setItem(
"sessions",
JSON.stringify(sessions)
);
localStorage.setItem("sessions", JSON.stringify(sessions));
enqueueSnackbar("Данные успешно отправлены");
} catch (e) {
enqueueSnackbar("повторите попытку позже");
@ -145,7 +157,6 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
if (settings.cfg.resultInfo.showResultForm === "after") {
onShowResult();
}
}
setFire(false);
@ -158,7 +169,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
alignItems: "center",
justifyContent: "center",
backgroundColor: theme.palette.background.default,
height: "100%",
height: screenHeight > 500 ? "100%" : "auto",
overflow: "auto",
"&::-webkit-scrollbar": {
width: "0",
@ -169,10 +180,13 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
msOverflowStyle: "none",
backgroundPosition: "center",
backgroundSize: "cover",
backgroundImage: settings.cfg.design && !isMobile
backgroundImage:
settings.cfg.design && !isMobile
? quizThemes[settings.cfg.theme].isLight
? `url(${DESIGN_LIST[settings.cfg.theme]})`
: `linear-gradient(90deg, #272626, transparent), url(${DESIGN_LIST[settings.cfg.theme]})`
: `linear-gradient(90deg, #272626, transparent), url(${
DESIGN_LIST[settings.cfg.theme]
})`
: null,
}}
>
@ -180,10 +194,13 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
sx={{
width: !isMobile ? "100%" : isMobile ? undefined : "530px",
borderRadius: "4px",
height: "100%",
height: isMobile ? "100%" : "auto",
minHeight: "100%",
display: isMobile ? undefined : "flex",
background: settings.cfg.design && !isMobile ? undefined : theme.palette.background.default,
background:
settings.cfg.design && !isMobile
? undefined
: theme.palette.background.default,
}}
>
<Box
@ -194,7 +211,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
alignItems: "center",
justifyContent: "center",
borderRight: isMobile ? undefined : "1px solid #9A9AAF80",
margin: isMobile ? 0 : "40px 0"
margin: isMobile ? 0 : "40px 0",
}}
>
<Box
@ -205,7 +222,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
flexDirection: "column",
alignItems: "flex-start",
justifyContent: "center",
padding: isMobile ? "20px 20px 0 20px" : "0 0 0 40px"
padding: isMobile ? "20px 20px 0 20px" : "0 0 0 40px",
}}
>
<Typography
@ -216,7 +233,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
lineHeight: "normal",
fontWeight: 501,
color: theme.palette.text.primary,
wordBreak: "break-word"
wordBreak: "break-word",
}}
>
{settings.cfg.formContact.title ||
@ -228,14 +245,13 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
color: theme.palette.text.primary,
m: "20px 0",
fontSize: "18px",
wordBreak: "break-word"
wordBreak: "break-word",
}}
>
{settings.cfg.formContact.desc}
</Typography>
)}
</Box>
</Box>
<Box
@ -280,8 +296,8 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
border: `1px solid ${theme.palette.primary.main}`,
"&:disabled": {
border: "1px solid #9A9AAF",
color: "#9A9AAF"
}
color: "#9A9AAF",
},
}}
>
{settings.cfg.formContact?.button || "Получить результаты"}
@ -319,13 +335,13 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
&ensp;ознакомлен
</Typography>
</Box>
{show_badge &&
{show_badge && (
<Box
component={Link}
target={"_blank"}
href={
`https://${window.location.hostname.includes("s") ? "s" : ""}quiz.pena.digital/squiz/quiz/logo?q=${quizId}`
}
href={`https://${
window.location.hostname.includes("s") ? "s" : ""
}quiz.pena.digital/squiz/quiz/logo?q=${quizId}`}
sx={{
display: "flex",
alignItems: "center",
@ -338,21 +354,24 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
<NameplateLogo
style={{
fontSize: "23px",
color: quizThemes[settings.cfg.theme].isLight ? "#151515" : "#FFFFFF",
color: quizThemes[settings.cfg.theme].isLight
? "#151515"
: "#FFFFFF",
}}
/>
<Typography
sx={{
fontSize: "14px",
color: quizThemes[settings.cfg.theme].isLight ? "#4D4D4D" : "#F5F7FF",
color: quizThemes[settings.cfg.theme].isLight
? "#4D4D4D"
: "#F5F7FF",
whiteSpace: "nowrap",
}}
>
Сделано на PenaQuiz
</Typography>
</Box>
}
)}
</Box>
</Box>
</Box>
@ -388,7 +407,7 @@ const Inputs = ({
);
const Email = (
<CustomInput
onChange={({ target }) => setEmail(target.value.replaceAll(/\s/g, ''))}
onChange={({ target }) => setEmail(target.value.replaceAll(/\s/g, ""))}
id={email}
title={FC["email"].innerText || "Введите Email"}
desc={FC["email"].text || "Email"}
@ -444,11 +463,17 @@ const Inputs = ({
}
};
const CustomInput = ({ title, desc, Icon, onChange, id }: {
const CustomInput = ({
title,
desc,
Icon,
onChange,
id,
}: {
id: string;
title: string;
desc: string;
Icon: FC<{ color: string; backgroundColor: string; }>;
Icon: FC<{ color: string; backgroundColor: string }>;
onChange: TextFieldProps["onChange"];
}) => {
const theme = useTheme();
@ -467,24 +492,29 @@ const CustomInput = ({ title, desc, Icon, onChange, id }: {
backgroundColor: theme.palette.background.default,
"& .MuiOutlinedInput-notchedOutline": {
borderColor: "#9A9AAF80",
borderRadius: "12px"
borderRadius: "12px",
},
"& .MuiInputBase-root": {
paddingLeft: 0
paddingLeft: 0,
},
'& .MuiOutlinedInput-root': {
'&:hover fieldset': {
"& .MuiOutlinedInput-root": {
"&:hover fieldset": {
borderColor: theme.palette.primary.main,
},
}
},
}}
placeholder={desc}
InputProps={{
startAdornment: (
<InputAdornment position="start">
<Icon color="gray"
backgroundColor={quizThemes[settings.cfg.theme].isLight ? "#F2F3F7" : "#F2F3F71A"} />
<Icon
color="gray"
backgroundColor={
quizThemes[settings.cfg.theme].isLight
? "#F2F3F7"
: "#F2F3F71A"
}
/>
</InputAdornment>
),
}}

@ -1,9 +1,4 @@
import {
Box,
Button, Link,
Typography,
useTheme
} from "@mui/material";
import { Box, Button, Link, Typography, useTheme } from "@mui/material";
import { NameplateLogo } from "@icons/NameplateLogo";
import YoutubeEmbedIframe from "./tools/YoutubeEmbedIframe";
@ -24,7 +19,9 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
const isMobile = useRootContainerSize() < 650;
const isTablet = useRootContainerSize() < 1000;
const { settings, show_badge, quizId } = useQuizData();
const setCurrentQuizStep = useQuizViewStore(state => state.setCurrentQuizStep);
const setCurrentQuizStep = useQuizViewStore(
(state) => state.setCurrentQuizStep
);
const spec = settings.cfg.spec;
console.log(quizThemes[settings.cfg.theme].isLight);
@ -41,10 +38,10 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
backgroundColor: theme.palette.background.default,
backgroundPosition: "center",
backgroundSize: "cover",
backgroundImage: settings.cfg.design && !isMobile
backgroundImage:
settings.cfg.design && !isMobile
? `url(${DESIGN_LIST[settings.cfg.theme]})`
: null,
}}
>
<Box
@ -57,7 +54,8 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
width: "100%",
height: "100%",
overflow: "auto",
background: settings.cfg.design && !isMobile
background:
settings.cfg.design && !isMobile
? quizThemes[settings.cfg.theme].isLight
? "transparent"
: "linear-gradient(90deg,#272626, transparent)"
@ -77,7 +75,7 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
mb: "7px",
}}
>
{settings.cfg.startpage.logo &&
{settings.cfg.startpage.logo && (
<img
src={settings.cfg.startpage.logo}
style={{
@ -87,7 +85,7 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
}}
alt=""
/>
}
)}
<Typography
sx={{
fontSize: "14px",
@ -106,9 +104,10 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
width: "100%",
maxWidth: "844px",
padding: isMobile ? "0 16px" : isTablet ? "0 78px" : undefined,
}}>
{
!resultQuestion?.content.useImage && resultQuestion.content.video && (
}}
>
{!resultQuestion?.content.useImage &&
resultQuestion.content.video && (
<YoutubeEmbedIframe
videoUrl={resultQuestion.content.video}
containerSX={{
@ -117,11 +116,11 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
height: isMobile ? "100%" : "306px",
}}
/>
)
}
{
resultQuestion?.content.useImage && resultQuestion.content.back && (
<Box sx={{width: "100%", display: "flex", justifyContent: "center"}}>
)}
{resultQuestion?.content.useImage && resultQuestion.content.back && (
<Box
sx={{ width: "100%", display: "flex", justifyContent: "center" }}
>
<Box
component="img"
src={resultQuestion.content.back}
@ -134,9 +133,7 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
}}
/>
</Box>
)
}
)}
{resultQuestion.description !== "" &&
resultQuestion.description !== " " && (
<Typography
@ -145,7 +142,7 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
fontWeight: 700,
m: "20px 0",
color: theme.palette.text.primary,
wordBreak: "break-word"
wordBreak: "break-word",
}}
>
{resultQuestion.description}
@ -156,14 +153,13 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
sx={{
m: "20px 0",
color: theme.palette.text.primary,
wordBreak: "break-word"
wordBreak: "break-word",
}}
>
{resultQuestion.title}
</Typography>
{
resultQuestion.content.text !== "" &&
{resultQuestion.content.text !== "" &&
resultQuestion.content.text !== " " && (
<Typography
sx={{
@ -173,15 +169,11 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
color: theme.palette.text.primary,
}}
>
{
resultQuestion.content.text
}
{resultQuestion.content.text}
</Typography>
)
}
)}
</Box>
<Box width="100%">
<Box
sx={{
@ -191,40 +183,43 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
px: "20px",
}}
>
{show_badge &&
{show_badge && (
<Box
component={Link}
target={"_blank"}
href={
`https://${window.location.hostname.includes("s") ? "s" : ""}quiz.pena.digital/squiz/quiz/logo?q=${quizId}`
}
href={`https://${
window.location.hostname.includes("s") ? "s" : ""
}quiz.pena.digital/squiz/quiz/logo?q=${quizId}`}
sx={{
display: "flex",
alignItems: "center",
mt: "15px",
gap: "10px",
textDecoration: "none",
mb: "15px"
mb: "15px",
}}
>
<NameplateLogo
style={{
fontSize: "23px",
color: quizThemes[settings.cfg.theme].isLight ? "#000000" : "#F5F7FF",
color: quizThemes[settings.cfg.theme].isLight
? "#000000"
: "#F5F7FF",
}}
/>
<Typography
sx={{
fontSize: "14px",
color: quizThemes[settings.cfg.theme].isLight ? "#4D4D4D" : "#F5F7FF",
color: quizThemes[settings.cfg.theme].isLight
? "#4D4D4D"
: "#F5F7FF",
whiteSpace: "nowrap",
}}
>
Сделано на PenaQuiz
</Typography>
</Box>
}
)}
</Box>
<Box
@ -237,18 +232,16 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
alignItems: "center",
borderTop: "1px solid #9A9AAF80",
p:
(
settings.cfg.resultInfo.showResultForm === "before" &&
!settings.cfg.score
) ||
(
settings.cfg.resultInfo.showResultForm === "after" &&
resultQuestion.content.redirect
)
? "20px" : "0",
(settings.cfg.resultInfo.showResultForm === "before" &&
!settings.cfg.score) ||
(settings.cfg.resultInfo.showResultForm === "after" &&
resultQuestion.content.redirect)
? "20px"
: "0",
}}
>
{settings.cfg.resultInfo.showResultForm === "before" && !settings.cfg.score && (
{settings.cfg.resultInfo.showResultForm === "before" &&
!settings.cfg.score && (
<Button
onClick={() => setCurrentQuizStep("contactform")}
variant="contained"
@ -264,7 +257,11 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
{settings.cfg.resultInfo.showResultForm === "after" &&
resultQuestion.content.redirect && (
<Button
href={resultQuestion.content.redirect}
href={
resultQuestion.content.redirect.includes("https")
? resultQuestion.content.redirect
: `https://${resultQuestion.content.redirect}`
}
variant="contained"
sx={{ p: "10px 20px", width: "auto", height: "50px" }}
>