у линейной публикации показываются шаги

This commit is contained in:
Nastya 2023-12-23 18:29:33 +03:00
parent 1a430a338d
commit 1ca17853e9
3 changed files with 78 additions and 43 deletions

@ -12,6 +12,7 @@ import { useState } from "react";
import { useQuestionsStore } from "@root/questions/store"; import { useQuestionsStore } from "@root/questions/store";
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared"; import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
import { enqueueSnackbar } from "notistack";
type ContactFormProps = { type ContactFormProps = {
currentQuestion: AnyTypedQuizQuestion; currentQuestion: AnyTypedQuizQuestion;
@ -155,28 +156,53 @@ export const ContactForm = ({
); );
}; };
const Inputs = () => { const Inputs = (currentQuestion: any) => {
const quiz = useCurrentQuiz(); const quiz = useCurrentQuiz();
const { questions } = useQuestionsStore()
let someUsed = []
const Icons = icons.map((data) => { const [name, setName] = useState("")
const FC = quiz?.config.formContact[data.type] const [email, setEmail] = useState("")
if (FC.used) someUsed.push(<CustomInput title={FC.innerText || data.defaultText} desc={FC.text || data.defaultTitle} Icon={data.icon} />) const [phone, setPhone] = useState("")
return <CustomInput title={FC.innerText || data.defaultText} desc={FC.text || data.defaultTitle} Icon={data.icon} /> const [text, setText] = useState("")
}) const [adress, setAdress] = useState("")
if (someUsed.length) { //@ts-ignore
return <>{someUsed}</> const FC: any = quiz?.config.formContact.fields
console.log(FC)
//@ts-ignore
const Name = <CustomInput onChange={({ target }) => setName(target.value)} id={name} title={FC["name"].innerText || "Введите имя"} desc={FC["name"].text || "имя"} Icon={NameIcon} />
//@ts-ignore
const Email = <CustomInput onChange={({ target }) => setEmail(target.value)} id={email} title={FC["email"].innerText || "Введите Email"} desc={FC["email"].text || "Email"} Icon={EmailIcon} />
//@ts-ignore
const Phone = <CustomInput onChange={({ target }) => setPhone(target.value)} id={phone} title={FC["phone"].innerText || "Введите номер телефона"} desc={FC["phone"].text || "номер телефона"} Icon={PhoneIcon} />
//@ts-ignore
const Text = <CustomInput onChange={({ target }) => setText(target.value)} id={text} title={FC["text"].innerText || "Введите фамилию"} desc={FC["text"].text || "фамилию"} Icon={TextIcon} />
//@ts-ignore
const Adress = <CustomInput onChange={({ target }) => setAdress(target.value)} id={adress} title={FC["address"].innerText || "Введите адрес"} desc={FC["address"].text || "адрес"} Icon={AddressIcon} />
//@ts-ignore
if (questions.some((data) => data.used)) {
return <>
{FC["name"].used ? Name : <></>}
{FC["email"].used ? Email : <></>}
{FC["phone"].used ? Phone : <></>}
{FC["text"].used ? Text : <></>}
{FC["address"].used ? Adress : <></>}
</>
} else { } else {
return <> return <>
{Icons[0]} {Name}
{Icons[1]} {Email}
{Icons[2]} {Phone}
</> </>
} }
} }
const CustomInput = ({ title, desc, Icon }: any) => { const CustomInput = ({ title, desc, Icon }: any) => {
return <Box m="15px 0"> return <Box m="15px 0">
<Typography mb="7px">{title}</Typography> <Typography mb="7px">{title}</Typography>

@ -20,6 +20,7 @@ type FooterProps = {
export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setShowResultForm }: FooterProps) => { export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setShowResultForm }: FooterProps) => {
const [disablePreviousButton, setDisablePreviousButton] = useState<boolean>(false); const [disablePreviousButton, setDisablePreviousButton] = useState<boolean>(false);
const [disableNextButton, setDisableNextButton] = useState<boolean>(false); const [disableNextButton, setDisableNextButton] = useState<boolean>(false);
const [stepNumber, setStepNumber] = useState(1);
const quiz = useCurrentQuiz(); const quiz = useCurrentQuiz();
const { answers } = useQuizViewStore(); const { answers } = useQuizViewStore();
const questions = useQuestionsStore().questions as AnyTypedQuizQuestion[]; const questions = useQuestionsStore().questions as AnyTypedQuizQuestion[];
@ -123,6 +124,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
const followPreviousStep = () => { const followPreviousStep = () => {
if (linear) { if (linear) {
setStepNumber(q=>q-1)
const questionIndex = questions.findIndex(({ id }) => id === question.id); const questionIndex = questions.findIndex(({ id }) => id === question.id);
const previousQuestion = questions[questionIndex - 1]; const previousQuestion = questions[questionIndex - 1];
@ -150,6 +152,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
if (linear) { if (linear) {
setStepNumber(q=>q+1)
const questionIndex = questions.findIndex(({ id }) => id === question.id); const questionIndex = questions.findIndex(({ id }) => id === question.id);
const nextQuestion = questions[questionIndex + 1]; const nextQuestion = questions[questionIndex + 1];
@ -205,37 +208,41 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
gap: "10px", gap: "10px",
}} }}
> >
<NameplateLogoFQ style={{ fontSize: "34px", width:"200px", height:"auto" }} /> <NameplateLogoFQ style={{ fontSize: "34px", width: "200px", height: "auto" }} />
<Box {linear &&
sx={{ <>
display: "flex", <Box
alignItems: "center", sx={{
gap: "10px", display: "flex",
marginRight: "auto", alignItems: "center",
color: theme.palette.grey1.main, gap: "10px",
}} marginRight: "auto",
> color: theme.palette.grey1.main,
{/* <Typography>Шаг</Typography> }}
<Typography >
sx={{ <Typography>Шаг</Typography>
display: "flex", <Typography
justifyContent: "center", sx={{
alignItems: "center", display: "flex",
fontWeight: "bold", justifyContent: "center",
borderRadius: "50%", alignItems: "center",
width: "30px", fontWeight: "bold",
height: "30px", borderRadius: "50%",
color: "#FFF", width: "30px",
background: theme.palette.brightPurple.main, height: "30px",
}} color: "#FFF",
> background: theme.palette.brightPurple.main,
{stepNumber} */} }}
{/* </Typography> */} >
{/* <Typography>Из</Typography> {stepNumber}
<Typography sx={{ fontWeight: "bold" }}> </Typography>
{questions.length} <Typography>Из</Typography>
</Typography> */} <Typography sx={{ fontWeight: "bold" }}>
</Box> {questions.filter(q=>q.type !== "result").length}
</Typography>
</Box>
</>
}
<Button <Button
disabled={disablePreviousButton} disabled={disablePreviousButton}
variant="contained" variant="contained"

@ -24,6 +24,8 @@ export const ViewPage = () => {
const { editQuizId } = useQuizStore(); const { editQuizId } = useQuizStore();
const { questions } = useQuestionsStore(); const { questions } = useQuestionsStore();
console.log("quiz ", quiz)
useEffect(() => { useEffect(() => {
const getData = async () => { const getData = async () => {
const quizes = await quizApi.getList(); const quizes = await quizApi.getList();