Merge branch 'dev' into 'staging'

Dev

See merge request frontend/squzanswerer!158
This commit is contained in:
Nastya 2024-06-03 01:06:13 +00:00
commit cecfa8bbdd
9 changed files with 91 additions and 79 deletions

@ -78,7 +78,7 @@ export async function getData(quizId: string): Promise<{
error?: AxiosError; error?: AxiosError;
}> { }> {
try { try {
const { data, headers } = await axios<GetQuizDataResponse>(domain + `/answer/settings`, { const { data, headers } = await axios<GetQuizDataResponse>(domain + `/answer/settings${window.location.search}`, {
method: "POST", method: "POST",
headers: { headers: {
"X-Sessionkey": SESSIONS, "X-Sessionkey": SESSIONS,
@ -160,7 +160,7 @@ export function sendAnswer({ questionId, body, qid, preview }: SendAnswerProps)
formData.append("qid", qid); formData.append("qid", qid);
return publicationMakeRequest({ return publicationMakeRequest({
url: domain + `/answer/answer`, url: domain + `/answer/v1.0.0/answer`,
body: formData, body: formData,
method: "POST", method: "POST",
}); });
@ -199,7 +199,7 @@ export function sendFile({ questionId, body, qid }: SendFileParams) {
formData.append("qid", qid); formData.append("qid", qid);
return publicationMakeRequest({ return publicationMakeRequest({
url: domain + `/answer/answer`, url: domain + `/answer/v1.0.0/answer`,
body: formData, body: formData,
method: "POST", method: "POST",
}); });
@ -242,7 +242,7 @@ export function sendFC({ questionId, body, qid, preview }: SendFCParams) {
formData.append("qid", qid); formData.append("qid", qid);
return publicationMakeRequest({ return publicationMakeRequest({
url: domain + `/answer/answer`, url: domain + `/answer/v1.0.0/answer`,
body: formData, body: formData,
method: "POST", method: "POST",
}); });

@ -310,7 +310,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
target={"_blank"} target={"_blank"}
href={`https://${ href={`https://${
window.location.hostname.includes("s") ? "s" : "" window.location.hostname.includes("s") ? "s" : ""
}quiz.pena.digital/squiz/quiz/logo?q=${quizId}`} }quiz.pena.digital/answer/v1.0.0/logo?q=${quizId}`}
sx={{ sx={{
display: "flex", display: "flex",
alignItems: "center", alignItems: "center",

@ -40,7 +40,7 @@ export const Question = ({
questionSelect, questionSelect,
}: Props) => { }: Props) => {
const theme = useTheme(); const theme = useTheme();
const { settings, show_badge } = useQuizSettings(); const { settings, show_badge, quizId } = useQuizSettings();
return ( return (
<Box <Box
@ -95,7 +95,7 @@ export const Question = ({
{show_badge && ( {show_badge && (
<Link <Link
target="_blank" target="_blank"
href="https://quiz.pena.digital" href={`https://${window.location.hostname.includes("s") ? "s" : ""}quiz.pena.digital/answer/v1.0.0/logo?q=${quizId}`}
sx={{ sx={{
mt: "20px", mt: "20px",
alignSelf: "end", alignSelf: "end",

@ -34,7 +34,7 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
useEffect(() => { useEffect(() => {
vkMetrics.resultIdShown(resultQuestion.id); vkMetrics.resultIdShown(resultQuestion.id);
yandexMetrics.resultIdShown(resultQuestion.id); yandexMetrics.resultIdShown(resultQuestion.id);
}, []); }, [resultQuestion.id, vkMetrics, yandexMetrics]);
return ( return (
<Box <Box
@ -195,7 +195,7 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
target={"_blank"} target={"_blank"}
href={`https://${ href={`https://${
window.location.hostname.includes("s") ? "s" : "" window.location.hostname.includes("s") ? "s" : ""
}quiz.pena.digital/squiz/quiz/logo?q=${quizId}`} }quiz.pena.digital/answer/v1.0.0/logo?q=${quizId}`}
sx={{ sx={{
display: "flex", display: "flex",
alignItems: "center", alignItems: "center",
@ -229,19 +229,21 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
bottom: 0, bottom: 0,
}} }}
> >
{settings.cfg.resultInfo.showResultForm === "before" && !settings.cfg.score && ( {settings.cfg.resultInfo.showResultForm === "before" &&
<Button settings.cfg.showfc !== false &&
onClick={() => setCurrentQuizStep("contactform")} !settings.cfg.score && (
variant="contained" <Button
sx={{ onClick={() => setCurrentQuizStep("contactform")}
p: "10px 20px", variant="contained"
width: "auto", sx={{
height: "50px", p: "10px 20px",
}} width: "auto",
> height: "50px",
{resultQuestion.content.hint.text || "Узнать подробнее"} }}
</Button> >
)} {resultQuestion.content.hint.text || "Узнать подробнее"}
</Button>
)}
{settings.cfg.resultInfo.showResultForm === "after" && resultQuestion.content.redirect && ( {settings.cfg.resultInfo.showResultForm === "after" && resultQuestion.content.redirect && (
<Button <Button
onClick={() => { onClick={() => {

@ -136,7 +136,7 @@ export const StartPageViewPublication = () => {
<Box <Box
component={Link} component={Link}
target={"_blank"} 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/answer/v1.0.0/logo?q=${quizId}`}
sx={{ sx={{
display: "flex", display: "flex",
alignItems: "center", alignItems: "center",

@ -110,10 +110,10 @@ export interface QuizConfig {
law?: string; law?: string;
}; };
meta: string; meta: string;
antifraud: boolean; antifraud?: boolean;
showfc: boolean; showfc?: boolean;
yandexMetricsNumber: number | undefined; yandexMetricsNumber?: number;
vkMetricsNumber: number | undefined; vkMetricsNumber?: number;
} }
export type FormContactFieldName = "name" | "email" | "phone" | "text" | "address"; export type FormContactFieldName = "name" | "email" | "phone" | "text" | "address";

@ -1,4 +1,5 @@
import type { MetricsMessengers } from "@model/metrics"; import type { MetricsMessengers } from "@model/metrics";
import { useMemo } from "react";
type MetricsGoal = { type MetricsGoal = {
type: "reachGoal"; type: "reachGoal";
@ -19,28 +20,31 @@ const sendMetrics = (vkPixelId: number | undefined, goal: string) => {
}; };
export const useVkMetricsGoals = (vkId: number | undefined) => { export const useVkMetricsGoals = (vkId: number | undefined) => {
return { return useMemo(
// Посетитель открыл квиз () => ({
quizOpened: () => sendMetrics(vkId, "penaquiz-start"), // Посетитель открыл квиз
// Посетитель нажал на кнопку стартовой страницы quizOpened: () => sendMetrics(vkId, "penaquiz-start"),
firstPageOpened: () => sendMetrics(vkId, "penaquiz-startquiz"), // Посетитель нажал на кнопку стартовой страницы
// Посетитель кликнул по номеру телефона на стартовой странице firstPageOpened: () => sendMetrics(vkId, "penaquiz-startquiz"),
phoneNumberOpened: () => sendMetrics(vkId, "penaquiz-phone"), // Посетитель кликнул по номеру телефона на стартовой странице
// Посетитель кликнул по email на стартовой странице phoneNumberOpened: () => sendMetrics(vkId, "penaquiz-phone"),
emailOpened: () => sendMetrics(vkId, "penaquiz-email"), // Посетитель кликнул по email на стартовой странице
// Посетитель увидел определенный результат (id - айдишник вопроса с типом result) emailOpened: () => sendMetrics(vkId, "penaquiz-email"),
resultIdShown: (resultId: string) => sendMetrics(vkId, `penaquiz-result-${resultId}`), // Посетитель увидел определенный результат (id - айдишник вопроса с типом result)
// Посетитель нажал на ссылку в результате resultIdShown: (resultId: string) => sendMetrics(vkId, `penaquiz-result-${resultId}`),
resultLink: () => sendMetrics(vkId, `penaquiz-resultlink`), // Посетитель нажал на ссылку в результате
// Посетитель дошёл до формы контактов resultLink: () => sendMetrics(vkId, `penaquiz-resultlink`),
contactsFormOpened: () => sendMetrics(vkId, "penaquiz-form"), // Посетитель дошёл до формы контактов
// Посетитель заполнил форму контактов contactsFormOpened: () => sendMetrics(vkId, "penaquiz-form"),
contactsFormFilled: () => sendMetrics(vkId, "penaquiz-contacts"), // Посетитель заполнил форму контактов
// Посетитель заполнил поле формы контактов contactsFormFilled: () => sendMetrics(vkId, "penaquiz-contacts"),
contactsFormField: (field: string) => sendMetrics(vkId, `penaquiz-formfield-${field}`), // Посетитель заполнил поле формы контактов
// Посетитель отправил заявку с мессенджером contactsFormField: (field: string) => sendMetrics(vkId, `penaquiz-formfield-${field}`),
messengerRequestSended: (messenger: MetricsMessengers) => sendMetrics(vkId, `penaquiz-messengers-${messenger}`), // Посетитель отправил заявку с мессенджером
// Посетитель прошёл вопрос messengerRequestSended: (messenger: MetricsMessengers) => sendMetrics(vkId, `penaquiz-messengers-${messenger}`),
questionPassed: (questionId: string) => sendMetrics(vkId, `penaquiz-step${questionId}`), // Посетитель прошёл вопрос
}; questionPassed: (questionId: string) => sendMetrics(vkId, `penaquiz-step${questionId}`),
}),
[vkId]
);
}; };

@ -1,4 +1,5 @@
import type { MetricsMessengers } from "@model/metrics"; import type { MetricsMessengers } from "@model/metrics";
import { useMemo } from "react";
type ExtendedWindow = Window & { type ExtendedWindow = Window & {
ym?: (id: number, type: string, goal: string) => void; ym?: (id: number, type: string, goal: string) => void;
@ -11,28 +12,31 @@ const sendMetrics = (yandexMetricsId: number | undefined, goal: string) => {
}; };
export const useYandexMetricsGoals = (id: number | undefined) => { export const useYandexMetricsGoals = (id: number | undefined) => {
return { return useMemo(
// Посетитель открыл квиз () => ({
quizOpened: () => sendMetrics(id, "penaquiz-start"), // Посетитель открыл квиз
// Посетитель нажал на кнопку стартовой страницы quizOpened: () => sendMetrics(id, "penaquiz-start"),
firstPageOpened: () => sendMetrics(id, "penaquiz-startquiz"), // Посетитель нажал на кнопку стартовой страницы
// Посетитель кликнул по номеру телефона на стартовой странице firstPageOpened: () => sendMetrics(id, "penaquiz-startquiz"),
phoneNumberOpened: () => sendMetrics(id, "penaquiz-phone"), // Посетитель кликнул по номеру телефона на стартовой странице
// Посетитель кликнул по email на стартовой странице phoneNumberOpened: () => sendMetrics(id, "penaquiz-phone"),
emailOpened: () => sendMetrics(id, "penaquiz-email"), // Посетитель кликнул по email на стартовой странице
// Посетитель увидел определенный результат (id - айдишник вопроса с типом result) emailOpened: () => sendMetrics(id, "penaquiz-email"),
resultIdShown: (resultId: string) => sendMetrics(id, `penaquiz-result-${resultId}`), // Посетитель увидел определенный результат (id - айдишник вопроса с типом result)
// Посетитель нажал на ссылку в результате resultIdShown: (resultId: string) => sendMetrics(id, `penaquiz-result-${resultId}`),
resultLink: () => sendMetrics(id, `penaquiz-resultlink`), // Посетитель нажал на ссылку в результате
// Посетитель дошёл до формы контактов resultLink: () => sendMetrics(id, `penaquiz-resultlink`),
contactsFormOpened: () => sendMetrics(id, "penaquiz-form"), // Посетитель дошёл до формы контактов
// Посетитель заполнил форму контактов contactsFormOpened: () => sendMetrics(id, "penaquiz-form"),
contactsFormFilled: () => sendMetrics(id, "penaquiz-contacts"), // Посетитель заполнил форму контактов
// Посетитель заполнил поле формы контактов contactsFormFilled: () => sendMetrics(id, "penaquiz-contacts"),
contactsFormField: (field: string) => sendMetrics(id, `penaquiz-formfield-${field}`), // Посетитель заполнил поле формы контактов
// Посетитель отправил заявку с мессенджером contactsFormField: (field: string) => sendMetrics(id, `penaquiz-formfield-${field}`),
messengerRequestSended: (messenger: MetricsMessengers) => sendMetrics(id, `penaquiz-messengers-${messenger}`), // Посетитель отправил заявку с мессенджером
// Посетитель прошёл вопрос messengerRequestSended: (messenger: MetricsMessengers) => sendMetrics(id, `penaquiz-messengers-${messenger}`),
questionPassed: (questionId: string) => sendMetrics(id, `penaquiz-step${questionId}`), // Посетитель прошёл вопрос
}; questionPassed: (questionId: string) => sendMetrics(id, `penaquiz-step${questionId}`),
}),
[id]
);
}; };

@ -23,7 +23,6 @@ export function useQuestionFlowControl() {
const yandexMetrics = useYandexMetricsGoals(settings.cfg.yandexMetricsNumber); const yandexMetrics = useYandexMetricsGoals(settings.cfg.yandexMetricsNumber);
const currentQuestion = sortedQuestions.find((question) => question.id === currentQuestionId) ?? sortedQuestions[0]; const currentQuestion = sortedQuestions.find((question) => question.id === currentQuestionId) ?? sortedQuestions[0];
console.log("currentQuestion", currentQuestion);
const linearQuestionIndex = const linearQuestionIndex =
currentQuestion && sortedQuestions.every(({ content }) => content.rule.parentId !== "root") // null when branching enabled currentQuestion && sortedQuestions.every(({ content }) => content.rule.parentId !== "root") // null when branching enabled
@ -131,9 +130,12 @@ export function useQuestionFlowControl() {
if (nextQuestion?.type !== "result") throw new Error("Current question is not result"); if (nextQuestion?.type !== "result") throw new Error("Current question is not result");
setCurrentQuestionId(nextQuestion.id); setCurrentQuestionId(nextQuestion.id);
if (settings.cfg.resultInfo.showResultForm === "after" || isResultQuestionEmpty(nextQuestion)) if (
settings.cfg.showfc !== false &&
(settings.cfg.resultInfo.showResultForm === "after" || isResultQuestionEmpty(nextQuestion))
)
setCurrentQuizStep("contactform"); setCurrentQuizStep("contactform");
}, [nextQuestion, setCurrentQuizStep, settings.cfg.resultInfo.showResultForm]); }, [nextQuestion, setCurrentQuizStep, settings.cfg.resultInfo.showResultForm, settings.cfg.showfc]);
const showResultAfterContactForm = useCallback(() => { const showResultAfterContactForm = useCallback(() => {
if (currentQuestion?.type !== "result") throw new Error("Current question is not result"); if (currentQuestion?.type !== "result") throw new Error("Current question is not result");
@ -161,7 +163,7 @@ export function useQuestionFlowControl() {
if (nextQuestion.type === "result") return showResult(); if (nextQuestion.type === "result") return showResult();
setCurrentQuestionId(nextQuestion.id); setCurrentQuestionId(nextQuestion.id);
}, [currentQuestion, nextQuestion, showResult]); }, [currentQuestion.id, nextQuestion, showResult, vkMetrics, yandexMetrics]);
const setQuestion = useCallback( const setQuestion = useCallback(
(questionId: string) => { (questionId: string) => {