From 3d30563ddb2f4fe1f72296a9e955cb1e834ffa47 Mon Sep 17 00:00:00 2001 From: IlyaDoronin Date: Sat, 16 Dec 2023 12:36:35 +0300 Subject: [PATCH] fix: result and contact forms logic --- src/pages/ViewPublicationPage/ContactForm.tsx | 24 ++++++++--- src/pages/ViewPublicationPage/Footer.tsx | 14 ++---- src/pages/ViewPublicationPage/Question.tsx | 17 ++------ src/pages/ViewPublicationPage/ResultForm.tsx | 12 ++++++ .../ViewPublicationPage/ResultQuestion.tsx | 43 ------------------- 5 files changed, 38 insertions(+), 72 deletions(-) delete mode 100644 src/pages/ViewPublicationPage/ResultQuestion.tsx diff --git a/src/pages/ViewPublicationPage/ContactForm.tsx b/src/pages/ViewPublicationPage/ContactForm.tsx index 5bd41ebf..d511f671 100644 --- a/src/pages/ViewPublicationPage/ContactForm.tsx +++ b/src/pages/ViewPublicationPage/ContactForm.tsx @@ -1,33 +1,47 @@ import { Box, Typography, Button } from "@mui/material"; import { useCurrentQuiz } from "@root/quizes/hooks"; +import { useQuestionsStore } from "@root/questions/store"; + +import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared"; type ContactFormProps = { + currentQuestion: AnyTypedQuizQuestion; showResultForm: boolean; setShowContactForm: (show: boolean) => void; setShowResultForm: (show: boolean) => void; }; export const ContactForm = ({ + currentQuestion, showResultForm, setShowContactForm, setShowResultForm, }: ContactFormProps) => { const quiz = useCurrentQuiz(); + const { questions } = useQuestionsStore(); const followNextForm = () => { setShowContactForm(false); setShowResultForm(true); }; + const resultQuestion = questions.find( + (question) => + question.type === "result" && + question.content.rule.parentId === currentQuestion.content.id + ); + return ( Форма контактов - {!showResultForm && quiz?.config.resultInfo.when === "after" && ( - - )} + {!showResultForm && + resultQuestion && + quiz?.config.resultInfo.when === "after" && ( + + )} ); }; diff --git a/src/pages/ViewPublicationPage/Footer.tsx b/src/pages/ViewPublicationPage/Footer.tsx index 9cbef9fe..a6708f37 100644 --- a/src/pages/ViewPublicationPage/Footer.tsx +++ b/src/pages/ViewPublicationPage/Footer.tsx @@ -17,7 +17,6 @@ type FooterProps = { question: AnyTypedQuizQuestion; setShowContactForm: (show: boolean) => void; setShowResultForm: (show: boolean) => void; - setResultQuestion: (id: string) => void; }; export const Footer = ({ @@ -25,7 +24,6 @@ export const Footer = ({ question, setShowContactForm, setShowResultForm, - setResultQuestion, }: FooterProps) => { const [disablePreviousButton, setDisablePreviousButton] = useState(false); @@ -103,16 +101,10 @@ export const Footer = ({ type === "result" && content.rule.parentId === question.content.id ); - if (resultQuestion) { - setResultQuestion(resultQuestion.id); - - return; - } - - if (quiz?.config.resultInfo.when === "after") { - setShowContactForm(true); - } else { + if (quiz?.config.resultInfo.when !== "after" && resultQuestion) { setShowResultForm(true); + } else { + setShowContactForm(true); } }; diff --git a/src/pages/ViewPublicationPage/Question.tsx b/src/pages/ViewPublicationPage/Question.tsx index 9dd17654..5d05dbb2 100644 --- a/src/pages/ViewPublicationPage/Question.tsx +++ b/src/pages/ViewPublicationPage/Question.tsx @@ -18,7 +18,6 @@ import { Rating } from "./questions/Rating"; import { Footer } from "./Footer"; import { ContactForm } from "./ContactForm"; import { ResultForm } from "./ResultForm"; -import { ResultQuestion } from "./ResultQuestion"; import type { QuestionType } from "../../model/question/question"; import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared"; @@ -47,7 +46,6 @@ export const Question = ({ questions }: QuestionProps) => { useState(); const [showContactForm, setShowContactForm] = useState(false); const [showResultForm, setShowResultForm] = useState(false); - const [resultQuestion, setResultQuestion] = useState(""); useEffect(() => { const nextQuestion = getQuestionByContentId(quiz?.config.haveRoot || ""); @@ -77,19 +75,12 @@ export const Question = ({ questions }: QuestionProps) => { margin: "0 auto", }} > - {!showContactForm && !showResultForm && !resultQuestion && ( + {!showContactForm && !showResultForm && ( )} - {resultQuestion && ( - - )} {showContactForm && ( { )} {showResultForm && ( )} - {!showContactForm && !showResultForm && !resultQuestion && ( + {!showContactForm && !showResultForm && (