diff --git a/src/model/questionTypes/result.ts b/src/model/questionTypes/result.ts index 782ed0d..844c1d1 100644 --- a/src/model/questionTypes/result.ts +++ b/src/model/questionTypes/result.ts @@ -17,5 +17,6 @@ export interface QuizQuestionResult extends QuizQuestionBase { rule: QuestionBranchingRule, hint: QuestionHint; autofill: boolean; + redirect: string }; } diff --git a/src/model/quizSettings.ts b/src/model/quizSettings.ts index f57f310..f50c516 100644 --- a/src/model/quizSettings.ts +++ b/src/model/quizSettings.ts @@ -6,15 +6,34 @@ import MegaphoneIcon from "@icons/MegaphoneIcon"; import QuestionIcon from "@icons/QuestionIcon"; import QuestionsMapIcon from "@icons/QuestionsMapIcon"; - export const quizSetupSteps = [ - { stepperText: "Настройка стартовой страницы", sidebarText: "Стартовая страница", sidebarIcon: LayoutIcon }, - { stepperText: "Задайте вопросы", sidebarText: "Вопросы", sidebarIcon: QuestionIcon }, - { stepperText: "Настройте авторезультаты", sidebarText: "Результаты", sidebarIcon: ChartPieIcon }, - // { stepperText: "Оценка графа карты вопросов", sidebarText: "Карта вопросов", sidebarIcon: QuestionsMapIcon }, - { stepperText: "Настройте форму контактов", sidebarText: "Форма контактов", sidebarIcon: ContactBookIcon }, - { stepperText: "Установите квиз", sidebarText: "Установка квиза", sidebarIcon: FlowArrowIcon }, - // { stepperText: "Запустите рекламу", sidebarText: "Запуск рекламы", sidebarIcon: MegaphoneIcon }, + { + stepperText: "Настройка стартовой страницы", + sidebarText: "Стартовая страница", + sidebarIcon: LayoutIcon, + }, + { + stepperText: "Задайте вопросы", + sidebarText: "Вопросы", + sidebarIcon: QuestionIcon, + }, + { + stepperText: "Настройте авторезультаты", + sidebarText: "Результаты", + sidebarIcon: ChartPieIcon, + }, + // { stepperText: "Оценка графа карты вопросов", sidebarText: "Карта вопросов", sidebarIcon: QuestionsMapIcon }, + { + stepperText: "Настройте форму контактов", + sidebarText: "Форма контактов", + sidebarIcon: ContactBookIcon, + }, + { + stepperText: "Установите квиз", + sidebarText: "Установка квиза", + sidebarIcon: FlowArrowIcon, + }, + // { stepperText: "Запустите рекламу", sidebarText: "Запуск рекламы", sidebarIcon: MegaphoneIcon }, ] as const; export const maxQuizSetupSteps = quizSetupSteps.length; @@ -28,143 +47,156 @@ export type QuizType = "quiz" | "form" | null; export type QuizResultsType = true | null; export interface QuizConfig { - type: QuizType; - noStartPage: boolean; - startpageType: QuizStartpageType; - results: QuizResultsType; - haveRoot: string | null; - theme: "StandardTheme" | "StandardDarkTheme" | "PinkTheme" | "PinkDarkTheme" | "BlackWhiteTheme" | "OliveTheme" | "YellowTheme" | "GoldDarkTheme" | "PurpleTheme" | "BlueTheme" | "BlueDarkTheme"; - resultInfo: { - when: 'before' | 'after' | 'email', - share: true | false, - replay: true | false, - theme: string, - reply: string, - replname: string, - } - startpage: { - description: string; - button: string; - position: QuizStartpageAlignType; - favIcon: string | null; - logo: string | null; - originalLogo: string | null; - background: { - type: null | "image" | "video"; - desktop: string | null; - originalDesktop: string | null; - mobile: string | null; - originalMobile: string | null; - video: string | null; - cycle: boolean; - }; + type: QuizType; + noStartPage: boolean; + startpageType: QuizStartpageType; + results: QuizResultsType; + haveRoot: string | null; + theme: + | "StandardTheme" + | "StandardDarkTheme" + | "PinkTheme" + | "PinkDarkTheme" + | "BlackWhiteTheme" + | "OliveTheme" + | "YellowTheme" + | "GoldDarkTheme" + | "PurpleTheme" + | "BlueTheme" + | "BlueDarkTheme"; + resultInfo: { + when: "email" | ""; + share: true | false; + replay: true | false; + theme: string; + reply: string; + replname: string; + showResultForm: "before" | "after"; + }; + startpage: { + description: string; + button: string; + position: QuizStartpageAlignType; + favIcon: string | null; + logo: string | null; + originalLogo: string | null; + background: { + type: null | "image" | "video"; + desktop: string | null; + originalDesktop: string | null; + mobile: string | null; + originalMobile: string | null; + video: string | null; + cycle: boolean; }; - formContact: { - title: string; - desc: string; - name: FCField; - email: FCField; - phone: FCField; - text: FCField; - address: FCField; - button: string - }; - info: { - phonenumber: string; - clickable: boolean; - orgname: string; - site: string; - law?: string; - }; - meta: string; + }; + formContact: { + title: string; + desc: string; + name: FCField; + email: FCField; + phone: FCField; + text: FCField; + address: FCField; + button: string; + }; + info: { + phonenumber: string; + clickable: boolean; + orgname: string; + site: string; + law?: string; + }; + meta: string; } type FCField = { - text: string - innerText: string - key: string - required: boolean - used: boolean -} + text: string; + innerText: string; + key: string; + required: boolean; + used: boolean; +}; export const defaultQuizConfig: QuizConfig = { - type: null, - noStartPage: false, - startpageType: null, - results: null, - haveRoot: null, - theme: "StandardTheme", - resultInfo: { - when: 'after', - share: false, - replay: false, - theme: "", - reply: "", - replname: "", + type: null, + noStartPage: false, + startpageType: null, + results: null, + haveRoot: null, + theme: "StandardTheme", + resultInfo: { + when: "", + share: false, + replay: false, + theme: "", + reply: "", + replname: "", + showResultForm: "after", + }, + startpage: { + description: "", + button: "", + position: "left", + favIcon: null, + logo: null, + originalLogo: null, + background: { + type: null, + desktop: null, + originalDesktop: null, + mobile: null, + originalMobile: null, + video: null, + cycle: false, }, - startpage: { - description: "", - button: "", - position: "left", - favIcon: null, - logo: null, - originalLogo: null, - background: { - type: null, - desktop: null, - originalDesktop: null, - mobile: null, - originalMobile: null, - video: null, - cycle: false, - }, + }, + info: { + phonenumber: "", + clickable: false, + orgname: "", + site: "", + law: "", + }, + formContact: { + title: "", + desc: "", + name: { + text: "", + innerText: "", + key: "", + required: false, + used: true, }, - info: { - phonenumber: "", - clickable: false, - orgname: "", - site: "", - law: "", + email: { + text: "", + innerText: "", + key: "", + required: false, + used: true, }, - formContact: { - title: "", - desc: "", - name: { - text: "", - innerText: "", - key: "", - required: false, - used: true - }, - email: { - text: "", - innerText: "", - key: "", - required: false, - used: true - }, - phone: { - text: "", - innerText: "", - key: "", - required: false, - used: true - }, - text: { - text: "", - innerText: "", - key: "", - required: false, - used: false - }, - address: { - text: "", - innerText: "", - key: "", - required: false, - used: false - }, - button: "" + phone: { + text: "", + innerText: "", + key: "", + required: false, + used: true, }, - meta: "", + text: { + text: "", + innerText: "", + key: "", + required: false, + used: false, + }, + address: { + text: "", + innerText: "", + key: "", + required: false, + used: false, + }, + button: "", + }, + meta: "", }; diff --git a/src/model/settingsData.ts b/src/model/settingsData.ts index 90f7ba6..7568888 100644 --- a/src/model/settingsData.ts +++ b/src/model/settingsData.ts @@ -9,8 +9,6 @@ export type QuizType = "quiz" | "form"; export type QuizResultsType = true | null; -export type QuizResultInfoWhen = 'before' | 'after' | 'email'; - export type FCField = { text: string innerText: string @@ -61,12 +59,13 @@ export interface QuizConfig { haveRoot: string; theme: "StandardTheme" | "StandardDarkTheme" | "PinkTheme" | "PinkDarkTheme" | "BlackWhiteTheme" | "OliveTheme" | "YellowTheme" | "GoldDarkTheme" | "PurpleTheme" | "BlueTheme" | "BlueDarkTheme"; resultInfo: { - when: QuizResultInfoWhen; + when: "email" | ""; share: boolean; replay: boolean; theme: string; reply: string; replname: string; + showResultForm: "before" | "after"; }; startpage: { description: string; diff --git a/src/pages/ViewPublicationPage/ContactForm.tsx b/src/pages/ViewPublicationPage/ContactForm.tsx index 97c6311..30a2f33 100644 --- a/src/pages/ViewPublicationPage/ContactForm.tsx +++ b/src/pages/ViewPublicationPage/ContactForm.tsx @@ -241,7 +241,7 @@ export const ContactForm = ({ enqueueSnackbar("повторите попытку позже") } - if ((settings?.cfg.resultInfo.when === "after" || settings?.cfg.resultInfo.when === "email") && !checkEmptyData({ resultData: resultQuestion })) { + if ((settings?.cfg.resultInfo.showResultForm === "after" || settings?.cfg.resultInfo.when === "email") && !checkEmptyData({ resultData: resultQuestion })) { setShowContactForm(false) setShowResultForm(true) } diff --git a/src/pages/ViewPublicationPage/Footer.tsx b/src/pages/ViewPublicationPage/Footer.tsx index 219f4e6..9d00ce3 100644 --- a/src/pages/ViewPublicationPage/Footer.tsx +++ b/src/pages/ViewPublicationPage/Footer.tsx @@ -12,6 +12,8 @@ import { NameplateLogoFQDark } from "@icons/NameplateLogoFQDark"; import { modes } from "../../utils/themes/Publication/themePublication"; import { checkEmptyData } from "./tools/checkEmptyData"; +import type { QuizQuestionResult } from "@model/questionTypes/result"; + type FooterProps = { setCurrentQuestion: (step: AnyTypedQuizQuestion) => void; question: AnyTypedQuizQuestion; @@ -85,17 +87,12 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh } }, [question, answers]); - const showResult = (nextQuestion: any) => { - if (nextQuestion && settings?.cfg.resultInfo.when === "email") { - setShowContactForm(true); - return; - } - + const showResult = (nextQuestion: QuizQuestionResult) => { const isEmpty = checkEmptyData({ resultData: nextQuestion }) console.log("isEmpty", isEmpty) if (nextQuestion) { - if (nextQuestion && settings?.cfg.resultInfo.when === "before") { + if (nextQuestion && settings?.cfg.resultInfo.showResultForm === "before") { if (isEmpty) { setShowContactForm(true); //до+пустая = кидать на ФК @@ -104,7 +101,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh } } - if (nextQuestion && (settings?.cfg.resultInfo.when === "after" || settings?.cfg.resultInfo.when === "email")) { + if (nextQuestion && settings?.cfg.resultInfo.showResultForm === "after") { if (isEmpty) { setShowContactForm(true); //после+пустая diff --git a/src/pages/ViewPublicationPage/Question.tsx b/src/pages/ViewPublicationPage/Question.tsx index a3fc084..ea43450 100644 --- a/src/pages/ViewPublicationPage/Question.tsx +++ b/src/pages/ViewPublicationPage/Question.tsx @@ -103,7 +103,7 @@ export const Question = ({ questions }: QuestionProps) => { )} )} - {showResultForm && settings?.cfg.resultInfo.when === "before" && ( + {showResultForm && settings?.cfg.resultInfo.showResultForm === "before" && ( { setShowResultForm={setShowResultForm} /> )} - {showResultForm && (settings?.cfg.resultInfo.when === "after" || settings?.cfg.resultInfo.when === "email") && ( + {showResultForm && settings?.cfg.resultInfo.showResultForm === "after" && ( { const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down(650)); - const { settings, items } = useQuestionsStore() + const { settings, items } = useQuestionsStore(); const mode = modes; - const searchResult = () => { + const searchResult = (): QuizQuestionResult => { if (Boolean(settings?.cfg.haveRoot)) { //ищём для ветвления return (items.find( (question) => question.type === "result" && - question.content.rule.parentId === currentQuestion.content.id, + question.content.rule.parentId === currentQuestion.content.id ) || - items.find( + items.find( (question) => question.type === "result" && - question.content.rule.parentId === "line", - )) + question.content.rule.parentId === "line" + )) as QuizQuestionResult; } else { return items.find( (question) => question.type === "result" && - question.content.rule.parentId === "line", - ) + question.content.rule.parentId === "line" + ) as QuizQuestionResult; } }; const resultQuestion = searchResult(); @@ -52,14 +58,11 @@ export const ResultForm = ({ setShowResultForm(false); setShowContactForm(true); }; - console.log(resultQuestion) + console.log(resultQuestion); if (resultQuestion === null || resultQuestion === undefined) { - - followNextForm() - return <> - + followNextForm(); + return <>; } else { - return ( { //@ts-ignore - !resultQuestion?.content.useImage && resultQuestion.content.video && ( - - )} + !resultQuestion?.content.useImage && + resultQuestion.content.video && ( + + ) + } { //@ts-ignore resultQuestion?.content.useImage && resultQuestion.content.back && ( @@ -105,7 +110,8 @@ export const ResultForm = ({ height: isMobile ? "100%" : "280px", }} > - )} + ) + } {resultQuestion.description !== "" && resultQuestion.description !== " " && ( - { - //@ts-ignore - resultQuestion.content.text} - - )} + //@ts-ignore + resultQuestion.content.text !== " " && ( + + { + //@ts-ignore + resultQuestion.content.text + } + + ) + } @@ -165,12 +173,12 @@ export const ResultForm = ({ gap: "10px", }} > - + - {settings?.cfg.resultInfo.when === "before" && ( - <> - + {settings?.cfg.resultInfo.showResultForm === "before" && ( + + )} + {settings?.cfg.resultInfo.showResultForm === "after" && + resultQuestion.content.redirect && ( - - - )} + )} + ); - } -}; \ No newline at end of file +}; diff --git a/src/pages/ViewPublicationPage/index.tsx b/src/pages/ViewPublicationPage/index.tsx index 37260fd..891080a 100644 --- a/src/pages/ViewPublicationPage/index.tsx +++ b/src/pages/ViewPublicationPage/index.tsx @@ -18,7 +18,7 @@ const QID = process.env.NODE_ENV === "production" ? window.location.pathname.replace(/\//g, '') : - "2363ad2c-0c19-4f51-80c0-ed2242daa0c4" + "0bed8483-3016-4bca-b8e0-a72c3146f18b" export const ViewPage = () => { diff --git a/src/pages/ViewPublicationPage/questions/Page.tsx b/src/pages/ViewPublicationPage/questions/Page.tsx index b78d148..700fdcd 100644 --- a/src/pages/ViewPublicationPage/questions/Page.tsx +++ b/src/pages/ViewPublicationPage/questions/Page.tsx @@ -31,6 +31,7 @@ export const Page = ({ currentQuestion }: PageProps) => { currentQuestion.content.useImage ? ( { {currentQuestion.content.back && currentQuestion.content.back !== " " && ( (object: T): T => { - if (Array.isArray(object)) { - return object.map(replaceSpacesToEmptyLines) as T; + if (Array.isArray(object)) { + return object.map(replaceSpacesToEmptyLines) as T; + } + + if (!object || typeof object !== "object") { + return object; + } + + const result: Record = {}; + + for (const [key, value] of Object.entries(object)) { + if (typeof value === "string") { + result[key] = value.replace(" ", "").replace(/\" \"/g, '""'); + + continue; } - - if (!object || typeof object !== "object") { - return object; + + if (typeof value === "object") { + result[key] = replaceSpacesToEmptyLines(value); + + continue; } - - const result: Record = {}; - - for (const [key, value] of Object.entries(object)) { - if (typeof value === "string") { - result[key] = value.replace(/\" \"/g, '""'); - - continue; - } - - if (typeof value === "object") { - result[key] = replaceSpacesToEmptyLines(value); - - continue; - } - - result[key] = value; - } - - return result as T; - }; - \ No newline at end of file + + result[key] = value; + } + + return result as T; +};