Compare commits
2 Commits
main
...
send_image
Author | SHA1 | Date | |
---|---|---|---|
8e0d066970 | |||
15434027ba |
34
.gitea/workflows/deploy.yml
Normal file
34
.gitea/workflows/deploy.yml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
name: Deploy
|
||||||
|
run-name: ${{ gitea.actor }} build image and push to container registry
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "main"
|
||||||
|
- "staging"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
CreateImage:
|
||||||
|
runs-on: [frontstaging]
|
||||||
|
uses: http://gitea.pena/PenaDevops/actions.git/.gitea/workflows/build-image.yml@v1.1.6-p
|
||||||
|
with:
|
||||||
|
runner: frontstaging
|
||||||
|
secrets:
|
||||||
|
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
||||||
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
DeployService:
|
||||||
|
runs-on: [frontstaging]
|
||||||
|
container:
|
||||||
|
image: gitea.pena:3000/penadevops/container-images/node-compose:main
|
||||||
|
env:
|
||||||
|
GITHUB_RUN_NUMBER: "${{ inputs.actionid }}"
|
||||||
|
volumes:
|
||||||
|
- /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: http://gitea.pena:3000/PenaDevops/actions.git/checkout@v1
|
||||||
|
- run: printenv
|
||||||
|
- run: GITHUB_RUN_NUMBER=${{ gitea.run_id }} compose -f deployments/${{ gitea.ref_name }}/docker-compose.yaml up -d
|
||||||
|
# uses: http://gitea.pena/PenaDevops/actions.git/.gitea/workflows/deploy.yml@v1.1.6-p
|
||||||
|
# with:
|
||||||
|
# runner: frontstaging
|
@ -2,29 +2,23 @@ name: Deploy
|
|||||||
run-name: ${{ gitea.actor }} build image and push to container registry
|
run-name: ${{ gitea.actor }} build image and push to container registry
|
||||||
|
|
||||||
on:
|
on:
|
||||||
registry_package:
|
push:
|
||||||
types: [published]
|
branches:
|
||||||
#package_name: "gitea.pena/squiz/frontanswerer/main:latest"
|
- "main"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# CreateImage:
|
CreateImage:
|
||||||
# runs-on: [skeris]
|
runs-on: [skeris]
|
||||||
# uses: https://gitea.pena/PenaDevops/actions.git/.gitea/workflows/build-image.yml@v1.1.6-p
|
uses: https://gitea.pena/PenaDevops/actions.git/.gitea/workflows/build-image.yml@v1.1.6-p
|
||||||
# with:
|
with:
|
||||||
# runner: skeris
|
runner: skeris
|
||||||
# secrets:
|
secrets:
|
||||||
# REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
||||||
# REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
DeployService:
|
DeployService:
|
||||||
if: contains(github.event.package.name, 'main')
|
|
||||||
runs-on: [frontprod]
|
runs-on: [frontprod]
|
||||||
container:
|
needs: CreateImage
|
||||||
image: gitea.pena/penadevops/container-images/node-compose:main
|
uses: https://gitea.pena/PenaDevops/actions.git/.gitea/workflows/deploy.yml@v1.1.4-p7
|
||||||
env:
|
with:
|
||||||
GITHUB_RUN_NUMBER: "${{ inputs.actionid }}"
|
runner: hubprod
|
||||||
volumes:
|
actionid: ${{ gitea.run_id }}
|
||||||
- /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock
|
|
||||||
steps:
|
|
||||||
- name: Check out repository code
|
|
||||||
uses: http://gitea.pena/PenaDevops/actions.git/checkout@v1
|
|
||||||
- run: compose -f deployments/main/docker-compose.yaml up -d
|
|
||||||
|
@ -2,28 +2,23 @@ name: Deploy
|
|||||||
run-name: ${{ gitea.actor }} build image and push to container registry
|
run-name: ${{ gitea.actor }} build image and push to container registry
|
||||||
|
|
||||||
on:
|
on:
|
||||||
registry_package:
|
push:
|
||||||
types: [published]
|
branches:
|
||||||
|
- "staging"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# CreateImage:
|
CreateImage:
|
||||||
# runs-on: [skeris]
|
runs-on: [skeris]
|
||||||
# uses: http://gitea.pena/PenaDevops/actions.git/.gitea/workflows/build-image.yml@v1.1.6-p
|
uses: http://gitea.pena/PenaDevops/actions.git/.gitea/workflows/build-image.yml@v1.1.6-p
|
||||||
# with:
|
with:
|
||||||
# runner: hubstaging
|
runner: hubstaging
|
||||||
# secrets:
|
secrets:
|
||||||
# REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
||||||
# REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
DeployService:
|
DeployService:
|
||||||
if: contains(github.event.package.name, 'staging')
|
|
||||||
runs-on: [frontstaging]
|
runs-on: [frontstaging]
|
||||||
container:
|
needs: CreateImage
|
||||||
image: gitea.pena:3000/penadevops/container-images/node-compose:main
|
uses: http://gitea.pena/PenaDevops/actions.git/.gitea/workflows/deploy.yml@v1.1.4-p7
|
||||||
env:
|
with:
|
||||||
GITHUB_RUN_NUMBER: "${{ inputs.actionid }}"
|
runner: frontstaging
|
||||||
volumes:
|
actionid: ${{ gitea.run_id }}
|
||||||
- /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock
|
|
||||||
steps:
|
|
||||||
- name: Check out repository code
|
|
||||||
uses: http://gitea.pena:3000/PenaDevops/actions.git/checkout@v1
|
|
||||||
- run: compose -f deployments/staging/docker-compose.yaml up -d
|
|
||||||
|
@ -2,7 +2,6 @@ services:
|
|||||||
respondent:
|
respondent:
|
||||||
container_name: respondent
|
container_name: respondent
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
image: gitea.pena/squiz/frontanswerer/main:latest
|
image: gitea.pena/squiz/frontanswerer/main:$GITHUB_RUN_NUMBER
|
||||||
hostname: respondent
|
hostname: respondent
|
||||||
tty: true
|
tty: true
|
||||||
pull_policy: always
|
|
||||||
|
@ -2,7 +2,9 @@ services:
|
|||||||
respondent:
|
respondent:
|
||||||
container_name: respondent
|
container_name: respondent
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
image: gitea.pena/squiz/frontanswerer/staging:latest
|
labels:
|
||||||
|
com.pena.domains: s.hbpn.link
|
||||||
|
com.pena.front_headers: "Access-Control-Allow-Origin $$http_origin always"
|
||||||
|
image: gitea.pena:3000/squiz/frontanswerer/staging:$GITHUB_RUN_NUMBER
|
||||||
hostname: respondent
|
hostname: respondent
|
||||||
tty: true
|
tty: true
|
||||||
pull_policy: always
|
|
||||||
|
@ -1,99 +1,11 @@
|
|||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
import { getAndParceData } from "./quizRelase";
|
import { getQuizData } from "./quizRelase";
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
import { initDataManager, statusOfQuiz } from "@/utils/hooks/useQuestionFlowControl";
|
|
||||||
import { addQuestions, changeNextLoading, setQuizData, useQuizStore } from "@/stores/useQuizStore";
|
|
||||||
|
|
||||||
/*
|
|
||||||
У хука есть три режмиа работы: "line" | "branch" | "ai"
|
|
||||||
Для branch и line единовременно запрашиваются ВСЕ данные (пока что это количество на 100 штук. Позже нужно впилить доп запросы чтобы получить все вопросы.)
|
|
||||||
Для ai идёт последовательный запрос данных. При первом попадании на result - блокируется возможность запрашивать новые данные
|
|
||||||
*/
|
|
||||||
|
|
||||||
export function useQuizData(quizId: string, preview: boolean = false) {
|
export function useQuizData(quizId: string, preview: boolean = false) {
|
||||||
const { quizStep, questions } = useQuizStore();
|
return useSWR(preview ? null : ["quizData", quizId], (params) => getQuizData({ quizId: params[1] }), {
|
||||||
|
|
||||||
const [page, setPage] = useState(0);
|
|
||||||
const [needFullLoad, setNeedFullLoad] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (quizStep > page) setPage(quizStep);
|
|
||||||
}, [quizStep]);
|
|
||||||
|
|
||||||
return useSWR(
|
|
||||||
preview ? null : ["quizData", quizId, page, needFullLoad],
|
|
||||||
async ([, id, currentPage, fullLoad]) => {
|
|
||||||
// Первый запрос - получаем статус
|
|
||||||
if (currentPage === 0 && !fullLoad) {
|
|
||||||
const firstData = await getAndParceData({
|
|
||||||
quizId: id,
|
|
||||||
limit: 1,
|
|
||||||
page: currentPage,
|
|
||||||
needConfig: true,
|
|
||||||
});
|
|
||||||
//firstData.settings.status = "ai";
|
|
||||||
|
|
||||||
initDataManager({
|
|
||||||
status: firstData.settings.status,
|
|
||||||
haveRoot: firstData.settings.cfg.haveRoot,
|
|
||||||
});
|
|
||||||
setQuizData(firstData);
|
|
||||||
|
|
||||||
if (!["ai"].includes(firstData.settings.status)) {
|
|
||||||
setNeedFullLoad(true); // Триггерит новый запрос через изменение ключа
|
|
||||||
return firstData;
|
|
||||||
}
|
|
||||||
return firstData;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Полная загрузка для line/branch
|
|
||||||
if (fullLoad) {
|
|
||||||
const data = await getAndParceData({
|
|
||||||
quizId: id,
|
|
||||||
limit: 100,
|
|
||||||
page: 0,
|
|
||||||
needConfig: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
addQuestions(data.questions.slice(1));
|
|
||||||
|
|
||||||
// Возвращаем полную структуру данных с настройками из store
|
|
||||||
const currentState = useQuizStore.getState();
|
|
||||||
return {
|
|
||||||
...currentState,
|
|
||||||
questions: [...currentState.questions, ...data.questions.slice(1)],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentPage >= questions.length) {
|
|
||||||
try {
|
|
||||||
// Для AI режима - последовательная загрузка
|
|
||||||
const data = await getAndParceData({
|
|
||||||
quizId: id,
|
|
||||||
page: currentPage,
|
|
||||||
limit: 1,
|
|
||||||
needConfig: false,
|
|
||||||
});
|
|
||||||
addQuestions(data.questions);
|
|
||||||
changeNextLoading(false);
|
|
||||||
|
|
||||||
// Возвращаем полную структуру данных с настройками из store
|
|
||||||
const currentState = useQuizStore.getState();
|
|
||||||
return {
|
|
||||||
...currentState,
|
|
||||||
questions: [...currentState.questions, ...data.questions],
|
|
||||||
};
|
|
||||||
} catch (p) {
|
|
||||||
setPage(questions.length);
|
|
||||||
changeNextLoading(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
revalidateOnFocus: false,
|
revalidateOnFocus: false,
|
||||||
revalidateOnReconnect: false,
|
revalidateOnReconnect: false,
|
||||||
shouldRetryOnError: false,
|
shouldRetryOnError: false,
|
||||||
refreshInterval: 0,
|
refreshInterval: 0,
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import { replaceSpacesToEmptyLines } from "../components/ViewPublicationPage/too
|
|||||||
import { QuizSettings } from "@model/settingsData";
|
import { QuizSettings } from "@model/settingsData";
|
||||||
import * as Bowser from "bowser";
|
import * as Bowser from "bowser";
|
||||||
import { domain } from "../utils/defineDomain";
|
import { domain } from "../utils/defineDomain";
|
||||||
import { statusOfQuiz } from "@/utils/hooks/useQuestionFlowControl";
|
|
||||||
let SESSIONS = "";
|
let SESSIONS = "";
|
||||||
|
|
||||||
const md = new MobileDetect(window.navigator.userAgent);
|
const md = new MobileDetect(window.navigator.userAgent);
|
||||||
@ -58,9 +57,6 @@ type PublicationMakeRequestParams = {
|
|||||||
method: "POST";
|
method: "POST";
|
||||||
};
|
};
|
||||||
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
const paudParam = urlParams.get("_paud");
|
|
||||||
|
|
||||||
export const publicationMakeRequest = ({ url, body }: PublicationMakeRequestParams) => {
|
export const publicationMakeRequest = ({ url, body }: PublicationMakeRequestParams) => {
|
||||||
return axios(url, {
|
return axios(url, {
|
||||||
data: body,
|
data: body,
|
||||||
@ -80,31 +76,11 @@ export const publicationMakeRequest = ({ url, body }: PublicationMakeRequestPara
|
|||||||
let globalStatus: string | null = null;
|
let globalStatus: string | null = null;
|
||||||
let isFirstRequest = true;
|
let isFirstRequest = true;
|
||||||
|
|
||||||
/*
|
export async function getData({ quizId }: { quizId: string }): Promise<{
|
||||||
если запросить 0 вопросов - придёт items: null
|
|
||||||
если не запрашивать конфиг - поле конфига вообще не придёт
|
|
||||||
*/
|
|
||||||
|
|
||||||
interface GetDataProps {
|
|
||||||
quizId: string;
|
|
||||||
limit: number;
|
|
||||||
page: number;
|
|
||||||
needConfig: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getData({ quizId, limit, page, needConfig }: GetDataProps): Promise<{
|
|
||||||
data: GetQuizDataResponse | null;
|
data: GetQuizDataResponse | null;
|
||||||
isRecentlyCompleted: boolean;
|
isRecentlyCompleted: boolean;
|
||||||
error?: AxiosError;
|
error?: AxiosError;
|
||||||
}> {
|
}> {
|
||||||
const body = {
|
|
||||||
quiz_id: quizId,
|
|
||||||
limit,
|
|
||||||
page,
|
|
||||||
need_config: needConfig,
|
|
||||||
} as any;
|
|
||||||
if (paudParam) body.auditory = Number(paudParam);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data, headers } = await axios<GetQuizDataResponse>(
|
const { data, headers } = await axios<GetQuizDataResponse>(
|
||||||
domain + `/answer/v1.0.0/settings${window.location.search}`,
|
domain + `/answer/v1.0.0/settings${window.location.search}`,
|
||||||
@ -118,18 +94,18 @@ export async function getData({ quizId, limit, page, needConfig }: GetDataProps)
|
|||||||
OS: OSDevice,
|
OS: OSDevice,
|
||||||
Browser: userAgent,
|
Browser: userAgent,
|
||||||
},
|
},
|
||||||
data: body,
|
data: {
|
||||||
|
quiz_id: quizId,
|
||||||
|
limit: 100,
|
||||||
|
page: 0,
|
||||||
|
need_config: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
|
const sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
|
||||||
|
|
||||||
//Тут ещё проверка на антифрод без парса конфига. Нам не интересно время если не нужно запрещать проходить чаще чем в сутки
|
//Тут ещё проверка на антифрод без парса конфига. Нам не интересно время если не нужно запрещать проходить чаще чем в сутки
|
||||||
if (
|
if (typeof sessions[quizId] === "number" && data.settings.cfg.includes('antifraud":true')) {
|
||||||
needConfig &&
|
|
||||||
data?.settings !== undefined &&
|
|
||||||
typeof sessions[quizId] === "number" &&
|
|
||||||
data.settings.cfg.includes('antifraud":true')
|
|
||||||
) {
|
|
||||||
// unix время. Если меньше суток прошло - выводить ошибку, иначе пустить дальше
|
// unix время. Если меньше суток прошло - выводить ошибку, иначе пустить дальше
|
||||||
if (Date.now() - sessions[quizId] < 86400000) {
|
if (Date.now() - sessions[quizId] < 86400000) {
|
||||||
return { data, isRecentlyCompleted: true };
|
return { data, isRecentlyCompleted: true };
|
||||||
@ -145,11 +121,114 @@ export async function getData({ quizId, limit, page, needConfig }: GetDataProps)
|
|||||||
return { data: null, isRecentlyCompleted: false, error: error };
|
return { data: null, isRecentlyCompleted: false, error: error };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export async function getDataSingle({ quizId, page }: { quizId: string; page?: number }): Promise<{
|
||||||
|
data: GetQuizDataResponse | null;
|
||||||
|
isRecentlyCompleted: boolean;
|
||||||
|
error?: AxiosError;
|
||||||
|
}> {
|
||||||
|
try {
|
||||||
|
// Первый запрос: 1 вопрос + конфиг
|
||||||
|
if (isFirstRequest) {
|
||||||
|
const { data, headers } = await axios<GetQuizDataResponse>(
|
||||||
|
domain + `/answer/v1.0.0/settings${window.location.search}`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"X-Sessionkey": SESSIONS,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
DeviceType: DeviceType,
|
||||||
|
Device: Device,
|
||||||
|
OS: OSDevice,
|
||||||
|
Browser: userAgent,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
quiz_id: quizId,
|
||||||
|
limit: 1,
|
||||||
|
page: 0,
|
||||||
|
need_config: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
export async function getAndParceData(props: GetDataProps) {
|
globalStatus = data.settings.status;
|
||||||
if (!props.quizId) throw new Error("No quiz id");
|
isFirstRequest = false;
|
||||||
|
SESSIONS = headers["x-sessionkey"] || SESSIONS;
|
||||||
|
|
||||||
const response = await getData(props);
|
// Проверка антифрода
|
||||||
|
const sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
|
||||||
|
if (typeof sessions[quizId] === "number" && data.settings.cfg.includes('antifraud":true')) {
|
||||||
|
if (Date.now() - sessions[quizId] < 86400000) {
|
||||||
|
return { data, isRecentlyCompleted: true };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Если статус не AI - сразу делаем запрос за всеми вопросами
|
||||||
|
if (globalStatus !== "ai") {
|
||||||
|
const secondResponse = await axios<GetQuizDataResponse>(
|
||||||
|
domain + `/answer/v1.0.0/settings${window.location.search}`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"X-Sessionkey": SESSIONS,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
DeviceType: DeviceType,
|
||||||
|
Device: Device,
|
||||||
|
OS: OSDevice,
|
||||||
|
Browser: userAgent,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
quiz_id: quizId,
|
||||||
|
limit: 100,
|
||||||
|
page: 0,
|
||||||
|
need_config: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
data: { ...data, items: secondResponse.data.items },
|
||||||
|
isRecentlyCompleted: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return { data, isRecentlyCompleted: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Последующие запросы
|
||||||
|
const response = await axios<GetQuizDataResponse>(domain + `/answer/v1.0.0/settings${window.location.search}`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"X-Sessionkey": SESSIONS,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
DeviceType: DeviceType,
|
||||||
|
Device: Device,
|
||||||
|
OS: OSDevice,
|
||||||
|
Browser: userAgent,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
quiz_id: quizId,
|
||||||
|
limit: 1,
|
||||||
|
page: page,
|
||||||
|
need_config: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: response.data,
|
||||||
|
isRecentlyCompleted: false,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
data: null,
|
||||||
|
isRecentlyCompleted: false,
|
||||||
|
error: error as AxiosError,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getQuizData({ quizId, status = "" }: { quizId: string; status?: string }) {
|
||||||
|
if (!quizId) throw new Error("No quiz id");
|
||||||
|
|
||||||
|
const response = await getData({ quizId });
|
||||||
const quizDataResponse = response.data;
|
const quizDataResponse = response.data;
|
||||||
|
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
@ -167,9 +246,8 @@ export async function getAndParceData(props: GetDataProps) {
|
|||||||
throw new Error("Quiz not found");
|
throw new Error("Quiz not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Парсим строки в строках
|
|
||||||
const quizSettings = replaceSpacesToEmptyLines(parseQuizData(quizDataResponse));
|
const quizSettings = replaceSpacesToEmptyLines(parseQuizData(quizDataResponse));
|
||||||
//Единоразово стрингифаим ВСЁ распаршенное и удаляем лишние пробелы
|
|
||||||
const res = JSON.parse(
|
const res = JSON.parse(
|
||||||
JSON.stringify({ data: quizSettings })
|
JSON.stringify({ data: quizSettings })
|
||||||
.replaceAll(/\\" \\"/g, '""')
|
.replaceAll(/\\" \\"/g, '""')
|
||||||
@ -179,6 +257,124 @@ export async function getAndParceData(props: GetDataProps) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let page = 1;
|
||||||
|
|
||||||
|
export async function getQuizDataAI(quizId: string) {
|
||||||
|
console.log("[getQuizDataAI] Starting with quizId:", quizId); // Добавлено
|
||||||
|
let maxRetries = 50;
|
||||||
|
|
||||||
|
if (!quizId) {
|
||||||
|
console.error("[getQuizDataAI] Error: No quiz id provided");
|
||||||
|
throw new Error("No quiz id");
|
||||||
|
}
|
||||||
|
|
||||||
|
let lastError: Error | null = null;
|
||||||
|
let responseData: any = null;
|
||||||
|
|
||||||
|
// Первый цикл - обработка result вопросов
|
||||||
|
console.log("[getQuizDataAI] Starting result retries loop"); // Добавлено
|
||||||
|
let resultRetryCount = 0;
|
||||||
|
while (resultRetryCount < maxRetries) {
|
||||||
|
try {
|
||||||
|
console.log(`[getQuizDataAI] Attempt ${resultRetryCount + 1} for result questions, page: ${page}`);
|
||||||
|
const response = await getData({ quizId, page });
|
||||||
|
console.log("[getQuizDataAI] Response from getData:", response);
|
||||||
|
|
||||||
|
if (response.error) {
|
||||||
|
console.error("[getQuizDataAI] Error in response:", response.error);
|
||||||
|
throw response.error;
|
||||||
|
}
|
||||||
|
if (!response.data) {
|
||||||
|
console.error("[getQuizDataAI] Error: Quiz not found");
|
||||||
|
throw new Error("Quiz not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasAiResult = response.data.items.some((item) => item.typ === "result");
|
||||||
|
console.log("[getQuizDataAI] Has AI result:", hasAiResult);
|
||||||
|
|
||||||
|
if (hasAiResult) {
|
||||||
|
page++;
|
||||||
|
resultRetryCount++;
|
||||||
|
console.log(`[getQuizDataAI] Found result question, incrementing page to ${page}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
responseData = response;
|
||||||
|
console.log("[getQuizDataAI] Found non-result questions, breaking loop");
|
||||||
|
break;
|
||||||
|
} catch (error) {
|
||||||
|
lastError = error as Error;
|
||||||
|
resultRetryCount++;
|
||||||
|
console.error(`[getQuizDataAI] Error in attempt ${resultRetryCount}:`, error);
|
||||||
|
|
||||||
|
if (resultRetryCount >= maxRetries) {
|
||||||
|
console.error("[getQuizDataAI] Max retries reached for result questions");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const delay = 1500 * resultRetryCount;
|
||||||
|
console.log(`[getQuizDataAI] Waiting ${delay}ms before next retry`);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!responseData) {
|
||||||
|
console.error("[getQuizDataAI] Failed after result retries, throwing error");
|
||||||
|
throw lastError || new Error("Failed to get quiz data after result retries");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Второй цикл - обработка пустого массива
|
||||||
|
console.log("[getQuizDataAI] Starting empty items retry loop"); // Добавлено
|
||||||
|
let isEmpty = !responseData.data?.items.length;
|
||||||
|
let emptyRetryCount = 0;
|
||||||
|
|
||||||
|
while (isEmpty && emptyRetryCount < maxRetries) {
|
||||||
|
try {
|
||||||
|
console.log(`[getQuizDataAI] Empty items retry ${emptyRetryCount + 1}`);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
const response = await getData({ quizId, page });
|
||||||
|
|
||||||
|
if (response.error) {
|
||||||
|
console.error("[getQuizDataAI] Error in empty items check:", response.error);
|
||||||
|
throw response.error;
|
||||||
|
}
|
||||||
|
if (!response.data) {
|
||||||
|
console.error("[getQuizDataAI] Error: Quiz not found in empty check");
|
||||||
|
throw new Error("Quiz not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
isEmpty = !response.data.items.length;
|
||||||
|
console.log("[getQuizDataAI] Is items empty:", isEmpty);
|
||||||
|
|
||||||
|
if (!isEmpty) {
|
||||||
|
responseData = response;
|
||||||
|
console.log("[getQuizDataAI] Found non-empty items, updating responseData");
|
||||||
|
}
|
||||||
|
emptyRetryCount++;
|
||||||
|
} catch (error) {
|
||||||
|
lastError = error as Error;
|
||||||
|
emptyRetryCount++;
|
||||||
|
console.error(`[getQuizDataAI] Error in empty check attempt ${emptyRetryCount}:`, error);
|
||||||
|
|
||||||
|
if (emptyRetryCount >= maxRetries) {
|
||||||
|
console.error("[getQuizDataAI] Max empty retries reached");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isEmpty) {
|
||||||
|
console.error("[getQuizDataAI] Items still empty after retries");
|
||||||
|
throw new Error("Items array is empty after maximum retries");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Финальная обработка
|
||||||
|
console.log("[getQuizDataAI] Processing final response data");
|
||||||
|
|
||||||
|
console.log("[getQuizDataAI] Final response before return:", responseData);
|
||||||
|
return responseData.data.items;
|
||||||
|
}
|
||||||
|
|
||||||
type SendAnswerProps = {
|
type SendAnswerProps = {
|
||||||
questionId: string;
|
questionId: string;
|
||||||
body: string | string[];
|
body: string | string[];
|
||||||
@ -187,14 +383,15 @@ type SendAnswerProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function sendAnswer({ questionId, body, qid, preview = false }: SendAnswerProps) {
|
export function sendAnswer({ questionId, body, qid, preview = false }: SendAnswerProps) {
|
||||||
|
console.log("qid");
|
||||||
|
console.log(qid);
|
||||||
if (preview) return;
|
if (preview) return;
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
const answers = [
|
const answers = [
|
||||||
{
|
{
|
||||||
question_id: questionId,
|
question_id: questionId,
|
||||||
//Для АИ квизов нельзя слать пустые строки
|
content: body, //тут массив с ответом
|
||||||
content: statusOfQuiz != "ai" ? body : body.length ? body : "-", //тут массив с ответом
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
formData.append("answers", JSON.stringify(answers));
|
formData.append("answers", JSON.stringify(answers));
|
||||||
|
77
lib/api/useQuizGetNext.ts
Normal file
77
lib/api/useQuizGetNext.ts
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { getQuizDataAI } from "./quizRelase";
|
||||||
|
import { addQuestion, useQuizStore } from "@/stores/useQuizStore";
|
||||||
|
import { AnyTypedQuizQuestion } from "..";
|
||||||
|
|
||||||
|
function qparse(q: { desc: string; id: string; req: boolean; title: string; typ: string }) {
|
||||||
|
return {
|
||||||
|
description: q.desc,
|
||||||
|
id: q.id,
|
||||||
|
required: q.req,
|
||||||
|
title: q.title,
|
||||||
|
type: q.typ,
|
||||||
|
page: 0,
|
||||||
|
content: {
|
||||||
|
answerType: "single",
|
||||||
|
autofill: false,
|
||||||
|
back: "",
|
||||||
|
hint: { text: "", video: "" },
|
||||||
|
id: "",
|
||||||
|
innerName: "",
|
||||||
|
innerNameCheck: false,
|
||||||
|
onlyNumbers: false,
|
||||||
|
originalBack: "",
|
||||||
|
placeholder: "",
|
||||||
|
required: false,
|
||||||
|
rule: {
|
||||||
|
children: [],
|
||||||
|
default: "",
|
||||||
|
main: [],
|
||||||
|
parentId: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useQuizGetNext = () => {
|
||||||
|
const { quizId, settings } = useQuizStore();
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [error, setError] = useState<Error | null>(null);
|
||||||
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
|
|
||||||
|
const loadMoreQuestions = async () => {
|
||||||
|
console.log("STATUS loadMoreQuestions");
|
||||||
|
console.log(settings);
|
||||||
|
console.log(settings.status);
|
||||||
|
if (settings.status === "ai") {
|
||||||
|
console.log("STATUS after IF");
|
||||||
|
setIsLoading(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log("STATUS after TRY TRY TRY");
|
||||||
|
const data = await getQuizDataAI(quizId);
|
||||||
|
console.log("data");
|
||||||
|
console.log(data);
|
||||||
|
const newQuestion = qparse(data[0]);
|
||||||
|
console.log("newQuestion");
|
||||||
|
console.log(newQuestion);
|
||||||
|
if (newQuestion) {
|
||||||
|
newQuestion.page = currentPage;
|
||||||
|
//@ts-ignore
|
||||||
|
addQuestion(newQuestion as AnyTypedQuizQuestion);
|
||||||
|
setCurrentPage((old) => old++);
|
||||||
|
console.log("newQuestion + page");
|
||||||
|
console.log(newQuestion);
|
||||||
|
return newQuestion;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
setError(err as Error);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return { loadMoreQuestions, isLoading, error, currentPage };
|
||||||
|
};
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,21 +1,7 @@
|
|||||||
import { FC, SVGProps } from "react";
|
import { FC, SVGProps } from "react";
|
||||||
|
import { useLocation } from "react-router-dom";
|
||||||
// Fallback функция для получения языка, когда React Router недоступен
|
|
||||||
const getLanguageFromUrlFallback = (): string => {
|
|
||||||
const path = window.location.pathname;
|
|
||||||
const langMatch = path.match(/^\/(en|ru|uz)(\/|$)/i);
|
|
||||||
if (langMatch) {
|
|
||||||
return langMatch[1].toLowerCase();
|
|
||||||
}
|
|
||||||
return "ru";
|
|
||||||
};
|
|
||||||
|
|
||||||
export const NameplateLogoFQ: FC<SVGProps<SVGSVGElement>> = (props) => {
|
export const NameplateLogoFQ: FC<SVGProps<SVGSVGElement>> = (props) => {
|
||||||
let lang = "ru"; // fallback
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Пытаемся использовать React Router
|
|
||||||
const { useLocation } = require("react-router-dom");
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const pathname = location.pathname;
|
const pathname = location.pathname;
|
||||||
|
|
||||||
@ -29,11 +15,7 @@ export const NameplateLogoFQ: FC<SVGProps<SVGSVGElement>> = (props) => {
|
|||||||
return "ru";
|
return "ru";
|
||||||
};
|
};
|
||||||
|
|
||||||
lang = getLanguageFromUrl();
|
const lang = getLanguageFromUrl(); // Оптимизация - вызываем функцию один раз
|
||||||
} catch (error) {
|
|
||||||
// Если React Router недоступен (в виджете), используем fallback
|
|
||||||
lang = getLanguageFromUrlFallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lang === "ru") return <RU {...props} />;
|
if (lang === "ru") return <RU {...props} />;
|
||||||
if (lang === "en") return <EN {...props} />;
|
if (lang === "en") return <EN {...props} />;
|
||||||
|
@ -1,21 +1,7 @@
|
|||||||
import { FC, SVGProps } from "react";
|
import { FC, SVGProps } from "react";
|
||||||
|
import { useLocation } from "react-router-dom";
|
||||||
// Fallback функция для получения языка, когда React Router недоступен
|
|
||||||
const getLanguageFromUrlFallback = (): string => {
|
|
||||||
const path = window.location.pathname;
|
|
||||||
const langMatch = path.match(/^\/(en|ru|uz)(\/|$)/i);
|
|
||||||
if (langMatch) {
|
|
||||||
return langMatch[1].toLowerCase();
|
|
||||||
}
|
|
||||||
return "ru";
|
|
||||||
};
|
|
||||||
|
|
||||||
export const NameplateLogoFQDark: FC<SVGProps<SVGSVGElement>> = (props) => {
|
export const NameplateLogoFQDark: FC<SVGProps<SVGSVGElement>> = (props) => {
|
||||||
let lang = "ru"; // fallback
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Пытаемся использовать React Router
|
|
||||||
const { useLocation } = require("react-router-dom");
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const pathname = location.pathname;
|
const pathname = location.pathname;
|
||||||
|
|
||||||
@ -29,11 +15,7 @@ export const NameplateLogoFQDark: FC<SVGProps<SVGSVGElement>> = (props) => {
|
|||||||
return "ru";
|
return "ru";
|
||||||
};
|
};
|
||||||
|
|
||||||
lang = getLanguageFromUrl();
|
const lang = getLanguageFromUrl(); // Оптимизация - вызываем функцию один раз
|
||||||
} catch (error) {
|
|
||||||
// Если React Router недоступен (в виджете), используем fallback
|
|
||||||
lang = getLanguageFromUrlFallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lang === "ru") return <RU {...props} />;
|
if (lang === "ru") return <RU {...props} />;
|
||||||
if (lang === "en") return <EN {...props} />;
|
if (lang === "en") return <EN {...props} />;
|
||||||
|
@ -21,8 +21,6 @@ import { HelmetProvider } from "react-helmet-async";
|
|||||||
|
|
||||||
import "moment/dist/locale/ru";
|
import "moment/dist/locale/ru";
|
||||||
import { useQuizStore, setQuizData, addquizid } from "@/stores/useQuizStore";
|
import { useQuizStore, setQuizData, addquizid } from "@/stores/useQuizStore";
|
||||||
import { initDataManager, statusOfQuiz } from "@/utils/hooks/useQuestionFlowControl";
|
|
||||||
|
|
||||||
moment.locale("ru");
|
moment.locale("ru");
|
||||||
const localeText = ruRU.components.MuiLocalizationProvider.defaultProps.localeText;
|
const localeText = ruRU.components.MuiLocalizationProvider.defaultProps.localeText;
|
||||||
|
|
||||||
@ -34,7 +32,16 @@ type Props = {
|
|||||||
className?: string;
|
className?: string;
|
||||||
disableGlobalCss?: boolean;
|
disableGlobalCss?: boolean;
|
||||||
};
|
};
|
||||||
|
function isQuizSettingsValid(data: any): data is QuizSettings {
|
||||||
|
return (
|
||||||
|
data &&
|
||||||
|
Array.isArray(data.questions) &&
|
||||||
|
data.settings &&
|
||||||
|
typeof data.cnt === "number" &&
|
||||||
|
typeof data.recentlyCompleted === "boolean" &&
|
||||||
|
typeof data.show_badge === "boolean"
|
||||||
|
);
|
||||||
|
}
|
||||||
function QuizAnswererInner({
|
function QuizAnswererInner({
|
||||||
quizSettings,
|
quizSettings,
|
||||||
quizId,
|
quizId,
|
||||||
@ -51,13 +58,18 @@ function QuizAnswererInner({
|
|||||||
const yandexMetrics = useYandexMetricsGoals(quizSettings?.settings.cfg.yandexMetricsNumber);
|
const yandexMetrics = useYandexMetricsGoals(quizSettings?.settings.cfg.yandexMetricsNumber);
|
||||||
const r = useQuizStore();
|
const r = useQuizStore();
|
||||||
const { settings, questions } = useQuizStore();
|
const { settings, questions } = useQuizStore();
|
||||||
console.log("settings", settings);
|
|
||||||
console.log("questions", questions);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
addquizid(quizId);
|
addquizid(quizId);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log(settings);
|
||||||
|
console.log(questions);
|
||||||
|
console.log("r");
|
||||||
|
console.log(r);
|
||||||
|
}, [questions, settings]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
vkMetrics.quizOpened();
|
vkMetrics.quizOpened();
|
||||||
@ -66,15 +78,17 @@ function QuizAnswererInner({
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
//Хук на случай если данные переданы нам сразу, а не "нам нужно их запросить"
|
console.log("got data");
|
||||||
if (quizSettings !== undefined) {
|
console.log(quizSettings);
|
||||||
setQuizData(quizSettings);
|
console.log(data);
|
||||||
initDataManager({
|
const quiz = quizSettings || data;
|
||||||
status: quizSettings.settings.status,
|
console.log("quiz");
|
||||||
haveRoot: quizSettings.settings.cfg.haveRoot,
|
console.log(quiz);
|
||||||
});
|
if (quiz !== undefined) {
|
||||||
|
console.log("is not undefined");
|
||||||
|
setQuizData(quiz);
|
||||||
}
|
}
|
||||||
}, [quizSettings]);
|
}, [quizSettings, data]);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (rootContainerRef.current) setRootContainerWidth(rootContainerRef.current.clientWidth);
|
if (rootContainerRef.current) setRootContainerWidth(rootContainerRef.current.clientWidth);
|
||||||
@ -93,26 +107,16 @@ function QuizAnswererInner({
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (isLoading && !questions.length) {
|
console.log("settings");
|
||||||
return <LoadingSkeleton />;
|
console.log(settings);
|
||||||
}
|
if (isLoading) return <LoadingSkeleton />;
|
||||||
if (error) {
|
if (error) return <ApologyPage error={error} />;
|
||||||
return <ApologyPage error={error} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Object.keys(settings).length == 0) {
|
if (Object.keys(settings).length == 0) return <ApologyPage error={new Error("quiz data is null")} />;
|
||||||
return <ApologyPage error={new Error("quiz data is null")} />;
|
if (questions.length === 0) return <ApologyPage error={new Error("No questions found")} />;
|
||||||
}
|
|
||||||
if (questions.length === 0) {
|
|
||||||
return <ApologyPage error={new Error("No questions found")} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (questions.length === 1 && settings.cfg.noStartPage && statusOfQuiz != "ai") {
|
if (questions.length === 1 && settings.cfg.noStartPage) return <ApologyPage error={new Error("quiz is empty")} />;
|
||||||
return <ApologyPage error={new Error("quiz is empty")} />;
|
if (!quizId) return <ApologyPage error={new Error("no quiz id")} />;
|
||||||
}
|
|
||||||
if (!quizId) {
|
|
||||||
return <ApologyPage error={new Error("no quiz id")} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
const quizContainer = (
|
const quizContainer = (
|
||||||
<Box
|
<Box
|
||||||
|
@ -5,8 +5,12 @@ import { useTranslation } from "react-i18next";
|
|||||||
type Props = Partial<FallbackProps>;
|
type Props = Partial<FallbackProps>;
|
||||||
|
|
||||||
export const ApologyPage = ({ error }: Props) => {
|
export const ApologyPage = ({ error }: Props) => {
|
||||||
let message = error.message || error.response?.data || " ";
|
let message = error.message || error.response?.data;
|
||||||
|
console.log("message");
|
||||||
|
console.log(message.toLowerCase());
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
console.log("t");
|
||||||
|
console.log(t(message.toLowerCase()));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
|
@ -26,7 +26,7 @@ import type { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
|||||||
import { isProduction } from "@/utils/defineDomain";
|
import { isProduction } from "@/utils/defineDomain";
|
||||||
import { useQuizStore } from "@/stores/useQuizStore";
|
import { useQuizStore } from "@/stores/useQuizStore";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { NameplateLogoDark } from "@/assets/icons/NameplateLogoDark";
|
import { isNeftyanka } from "@/ui_kit/neftyankacrutch";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
currentQuestion: AnyTypedQuizQuestion;
|
currentQuestion: AnyTypedQuizQuestion;
|
||||||
@ -46,8 +46,6 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
|
|||||||
const [text, setText] = useState("");
|
const [text, setText] = useState("");
|
||||||
const [adress, setAdress] = useState("");
|
const [adress, setAdress] = useState("");
|
||||||
const [screenHeight, setScreenHeight] = useState<number>(window.innerHeight);
|
const [screenHeight, setScreenHeight] = useState<number>(window.innerHeight);
|
||||||
const [emailError, setEmailError] = useState("");
|
|
||||||
const [phoneError, setPhoneError] = useState("");
|
|
||||||
|
|
||||||
const fireOnce = useRef(true);
|
const fireOnce = useRef(true);
|
||||||
const [fire, setFire] = useState(false);
|
const [fire, setFire] = useState(false);
|
||||||
@ -123,23 +121,13 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
|
|||||||
async function handleShowResultsClick() {
|
async function handleShowResultsClick() {
|
||||||
const FC = settings.cfg.formContact.fields;
|
const FC = settings.cfg.formContact.fields;
|
||||||
|
|
||||||
// Проверяем email только если поле отображается
|
if (!isDisableEmail && FC["email"].used !== EMAIL_REGEXP.test(email)) {
|
||||||
if (isEmailFieldVisible && !EMAIL_REGEXP.test(email)) {
|
|
||||||
return enqueueSnackbar("Incorrect email entered");
|
return enqueueSnackbar("Incorrect email entered");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fireOnce.current) {
|
if (fireOnce.current) {
|
||||||
// Проверяем, что хотя бы одно видимое поле заполнено
|
if (name.length === 0 && email.length === 0 && phone.length === 0 && text.length === 0 && adress.length === 0)
|
||||||
const hasVisibleFieldsFilled =
|
|
||||||
(isNameFieldVisible() && name.length > 0) ||
|
|
||||||
(isEmailFieldVisible && email.length > 0) ||
|
|
||||||
(isPhoneFieldVisible() && phone.length > 0) ||
|
|
||||||
(isTextFieldVisible() && text.length > 0) ||
|
|
||||||
(isAddressFieldVisible() && adress.length > 0);
|
|
||||||
|
|
||||||
if (!hasVisibleFieldsFilled) {
|
|
||||||
return enqueueSnackbar(t("Please fill in the fields"));
|
return enqueueSnackbar(t("Please fill in the fields"));
|
||||||
}
|
|
||||||
|
|
||||||
//почта валидна, хоть одно поле заполнено
|
//почта валидна, хоть одно поле заполнено
|
||||||
setFire(true);
|
setFire(true);
|
||||||
@ -190,115 +178,6 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Функция валидации телефона
|
|
||||||
const validatePhone = (phoneValue: string) => {
|
|
||||||
// Убираем все нецифровые символы и считаем только цифры
|
|
||||||
const digitsOnly = phoneValue.replace(/\D/g, "");
|
|
||||||
|
|
||||||
// Для российских номеров (начинающихся с +7) нужно 11 цифр
|
|
||||||
// Для остальных стран - минимум 10 цифр
|
|
||||||
const isRussianNumber = phoneValue.startsWith("+7");
|
|
||||||
const minDigits = isRussianNumber ? 11 : 10;
|
|
||||||
|
|
||||||
// Если есть какие-то символы в инпуте, но цифр меньше минимума - это ошибка
|
|
||||||
if (phoneValue.trim().length > 0 && digitsOnly.length < minDigits) {
|
|
||||||
return t("Please complete the phone number");
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
};
|
|
||||||
|
|
||||||
// Проверяем валидность телефона при каждом изменении
|
|
||||||
const digitsOnly = phone.replace(/\D/g, "");
|
|
||||||
const isRussianNumber = phone.startsWith("+7");
|
|
||||||
const minDigits = isRussianNumber ? 11 : 10;
|
|
||||||
const isPhoneValid = phone.trim().length === 0 || digitsOnly.length >= minDigits;
|
|
||||||
|
|
||||||
// Проверяем валидность email - должен быть заполнен и соответствовать формату
|
|
||||||
const validateEmail = (emailValue: string) => {
|
|
||||||
if (emailValue.trim().length === 0) return false;
|
|
||||||
|
|
||||||
// Проверяем наличие @ и .
|
|
||||||
const atIndex = emailValue.indexOf("@");
|
|
||||||
const dotIndex = emailValue.lastIndexOf(".");
|
|
||||||
|
|
||||||
if (atIndex === -1 || dotIndex === -1) return false;
|
|
||||||
|
|
||||||
// Точка должна быть после @
|
|
||||||
if (dotIndex <= atIndex) return false;
|
|
||||||
|
|
||||||
// Между @ и . должно быть минимум 3 символа
|
|
||||||
const domainPart = emailValue.substring(atIndex + 1, dotIndex);
|
|
||||||
if (domainPart.length < 3) return false;
|
|
||||||
|
|
||||||
// После точки должно быть минимум 2 символа
|
|
||||||
const tldPart = emailValue.substring(dotIndex + 1);
|
|
||||||
if (tldPart.length < 2) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const isEmailValid = validateEmail(email);
|
|
||||||
|
|
||||||
// Определяем, отображается ли поле email
|
|
||||||
const isEmailFieldVisible = settings.cfg.formContact.fields?.email?.used && !isDisableEmail;
|
|
||||||
|
|
||||||
// Функции для определения видимости полей
|
|
||||||
const isNameFieldVisible = () => {
|
|
||||||
const FC = settings.cfg.formContact.fields;
|
|
||||||
return Object.values(FC).some((data) => data.used) ? FC["name"].used : true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const isPhoneFieldVisible = () => {
|
|
||||||
const FC = settings.cfg.formContact.fields;
|
|
||||||
return Object.values(FC).some((data) => data.used) ? FC["phone"].used : true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const isTextFieldVisible = () => {
|
|
||||||
const FC = settings.cfg.formContact.fields;
|
|
||||||
return Object.values(FC).some((data) => data.used) ? FC["text"].used : false;
|
|
||||||
};
|
|
||||||
|
|
||||||
const isAddressFieldVisible = () => {
|
|
||||||
const FC = settings.cfg.formContact.fields;
|
|
||||||
return Object.values(FC).some((data) => data.used) ? FC["address"].used : false;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Обработчик изменения телефона
|
|
||||||
const handlePhoneChange = (newPhone: string) => {
|
|
||||||
setPhone(newPhone);
|
|
||||||
// Очищаем ошибку если поле стало пустым
|
|
||||||
if (newPhone.trim().length === 0) {
|
|
||||||
setPhoneError("");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Обработчик изменения email
|
|
||||||
const handleEmailChange = (newEmail: string) => {
|
|
||||||
setEmail(newEmail);
|
|
||||||
// Очищаем ошибку если поле стало пустым
|
|
||||||
if (newEmail.trim().length === 0) {
|
|
||||||
setEmailError("");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Обработчик потери фокуса для email
|
|
||||||
const handleEmailBlur = () => {
|
|
||||||
if (email.trim().length > 0 && !validateEmail(email)) {
|
|
||||||
setEmailError(t("Please enter a valid email"));
|
|
||||||
} else {
|
|
||||||
setEmailError("");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Обработчик потери фокуса для телефона
|
|
||||||
const handlePhoneBlur = () => {
|
|
||||||
if (phone.trim().length > 0 && !isPhoneValid) {
|
|
||||||
setPhoneError(t("Please enter a valid phone number"));
|
|
||||||
} else {
|
|
||||||
setPhoneError("");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@ -372,17 +251,13 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
|
|||||||
name={name}
|
name={name}
|
||||||
setName={setName}
|
setName={setName}
|
||||||
email={email}
|
email={email}
|
||||||
setEmail={handleEmailChange}
|
setEmail={setEmail}
|
||||||
phone={phone}
|
phone={phone}
|
||||||
setPhone={handlePhoneChange}
|
setPhone={setPhone}
|
||||||
text={text}
|
text={text}
|
||||||
setText={setText}
|
setText={setText}
|
||||||
adress={adress}
|
adress={adress}
|
||||||
setAdress={setAdress}
|
setAdress={setAdress}
|
||||||
emailError={emailError}
|
|
||||||
phoneError={phoneError}
|
|
||||||
onEmailBlur={handleEmailBlur}
|
|
||||||
onPhoneBlur={handlePhoneBlur}
|
|
||||||
crutch={{
|
crutch={{
|
||||||
disableEmail: isDisableEmail,
|
disableEmail: isDisableEmail,
|
||||||
}}
|
}}
|
||||||
@ -430,7 +305,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
|
|||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
disabled={!(ready && !fire && isPhoneValid && (isEmailFieldVisible ? isEmailValid : true))}
|
disabled={!(ready && !fire)}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={handleShowResultsClick}
|
onClick={handleShowResultsClick}
|
||||||
sx={{
|
sx={{
|
||||||
@ -444,7 +319,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{settings.cfg.formContact?.button || t("Get results")}
|
{isNeftyanka ? t("neftyanka button") : settings.cfg.formContact?.button || t("Get results")}
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
{show_badge && (
|
{show_badge && (
|
||||||
@ -462,7 +337,12 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
|
|||||||
margitTop: "auto",
|
margitTop: "auto",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{quizThemes[settings.cfg.theme].isLight ? <NameplateLogoDark /> : <NameplateLogo />}
|
<NameplateLogo
|
||||||
|
style={{
|
||||||
|
fontSize: "20px",
|
||||||
|
color: quizThemes[settings.cfg.theme].isLight ? "#151515" : "#FFFFFF",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
|
@ -3,6 +3,7 @@ import { useRootContainerSize } from "@contexts/RootContainerWidthContext.ts";
|
|||||||
import { QuizSettingsConfig } from "@model/settingsData.ts";
|
import { QuizSettingsConfig } from "@model/settingsData.ts";
|
||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { isNeftyanka } from "@/ui_kit/neftyankacrutch";
|
||||||
|
|
||||||
type ContactTextBlockProps = {
|
type ContactTextBlockProps = {
|
||||||
settings: QuizSettingsConfig;
|
settings: QuizSettingsConfig;
|
||||||
@ -47,7 +48,9 @@ export const ContactTextBlock: FC<ContactTextBlockProps> = ({ settings }) => {
|
|||||||
wordBreak: "break-word",
|
wordBreak: "break-word",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{settings.cfg.formContact.title || t("Fill out the form to receive your test results")}
|
{isNeftyanka
|
||||||
|
? t("neftyanka FK")
|
||||||
|
: settings.cfg.formContact.title || t("Fill out the form to receive your test results")}
|
||||||
</Typography>
|
</Typography>
|
||||||
{settings.cfg.formContact.desc && (
|
{settings.cfg.formContact.desc && (
|
||||||
<Typography
|
<Typography
|
||||||
|
@ -17,8 +17,6 @@ type InputProps = {
|
|||||||
isPhone?: boolean;
|
isPhone?: boolean;
|
||||||
type?: HTMLInputTypeAttribute;
|
type?: HTMLInputTypeAttribute;
|
||||||
value?: string;
|
value?: string;
|
||||||
onBlur?: () => void;
|
|
||||||
error?: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const TextField = MuiTextField as unknown as FC<TextFieldProps>;
|
const TextField = MuiTextField as unknown as FC<TextFieldProps>;
|
||||||
@ -36,18 +34,7 @@ function phoneChange(e: ChangeEvent<HTMLInputElement>, mask: string) {
|
|||||||
return a || "";
|
return a || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CustomInput = ({
|
export const CustomInput = ({ title, desc, Icon, onChange, onChangePhone, isPhone, type, value }: InputProps) => {
|
||||||
title,
|
|
||||||
desc,
|
|
||||||
Icon,
|
|
||||||
onChange,
|
|
||||||
onChangePhone,
|
|
||||||
isPhone,
|
|
||||||
type,
|
|
||||||
value,
|
|
||||||
onBlur,
|
|
||||||
error,
|
|
||||||
}: InputProps) => {
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isMobile = useRootContainerSize() < 600;
|
const isMobile = useRootContainerSize() < 600;
|
||||||
const { settings } = useQuizStore();
|
const { settings } = useQuizStore();
|
||||||
@ -70,11 +57,8 @@ export const CustomInput = ({
|
|||||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||||
isPhone ? onChangePhone?.(phoneChange(e, mask)) : onChange?.(e)
|
isPhone ? onChangePhone?.(phoneChange(e, mask)) : onChange?.(e)
|
||||||
}
|
}
|
||||||
onBlur={onBlur}
|
|
||||||
type={isPhone ? "tel" : type}
|
type={isPhone ? "tel" : type}
|
||||||
value={value}
|
value={value}
|
||||||
error={!!error}
|
|
||||||
helperText={error}
|
|
||||||
sx={{
|
sx={{
|
||||||
width: isMobile ? "100%" : "390px",
|
width: isMobile ? "100%" : "390px",
|
||||||
backgroundColor: theme.palette.background.default,
|
backgroundColor: theme.palette.background.default,
|
||||||
|
@ -13,17 +13,13 @@ type InputsProps = {
|
|||||||
name: string;
|
name: string;
|
||||||
setName: Dispatch<SetStateAction<string>>;
|
setName: Dispatch<SetStateAction<string>>;
|
||||||
email: string;
|
email: string;
|
||||||
setEmail: (email: string) => void;
|
setEmail: Dispatch<SetStateAction<string>>;
|
||||||
phone: string;
|
phone: string;
|
||||||
setPhone: (phone: string) => void;
|
setPhone: Dispatch<SetStateAction<string>>;
|
||||||
text: string;
|
text: string;
|
||||||
setText: Dispatch<SetStateAction<string>>;
|
setText: Dispatch<SetStateAction<string>>;
|
||||||
adress: string;
|
adress: string;
|
||||||
setAdress: Dispatch<SetStateAction<string>>;
|
setAdress: Dispatch<SetStateAction<string>>;
|
||||||
emailError?: string;
|
|
||||||
phoneError?: string;
|
|
||||||
onEmailBlur?: () => void;
|
|
||||||
onPhoneBlur?: () => void;
|
|
||||||
crutch: {
|
crutch: {
|
||||||
disableEmail: boolean;
|
disableEmail: boolean;
|
||||||
};
|
};
|
||||||
@ -43,10 +39,6 @@ export const Inputs = ({
|
|||||||
setText,
|
setText,
|
||||||
adress,
|
adress,
|
||||||
setAdress,
|
setAdress,
|
||||||
emailError,
|
|
||||||
phoneError,
|
|
||||||
onEmailBlur,
|
|
||||||
onPhoneBlur,
|
|
||||||
crutch,
|
crutch,
|
||||||
}: InputsProps) => {
|
}: InputsProps) => {
|
||||||
const { settings } = useQuizStore();
|
const { settings } = useQuizStore();
|
||||||
@ -72,13 +64,11 @@ export const Inputs = ({
|
|||||||
onChange={({ target }) => {
|
onChange={({ target }) => {
|
||||||
setEmail(target.value.replaceAll(/\s/g, ""));
|
setEmail(target.value.replaceAll(/\s/g, ""));
|
||||||
}}
|
}}
|
||||||
onBlur={onEmailBlur}
|
|
||||||
id={email}
|
id={email}
|
||||||
title={FC["email"].innerText || `${t("Enter")} Email`}
|
title={FC["email"].innerText || `${t("Enter")} Email`}
|
||||||
desc={FC["email"].text || "Email"}
|
desc={FC["email"].text || "Email"}
|
||||||
Icon={EmailIcon}
|
Icon={EmailIcon}
|
||||||
type="email"
|
type="email"
|
||||||
error={emailError}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
const Phone = (
|
const Phone = (
|
||||||
@ -87,14 +77,12 @@ export const Inputs = ({
|
|||||||
onChangePhone={(phone: string) => {
|
onChangePhone={(phone: string) => {
|
||||||
setPhone(phone);
|
setPhone(phone);
|
||||||
}}
|
}}
|
||||||
onBlur={onPhoneBlur}
|
|
||||||
value={phone}
|
value={phone}
|
||||||
id={phone}
|
id={phone}
|
||||||
title={FC["phone"].innerText || `${t("Enter")} ${t("Phone number").toLowerCase()}`}
|
title={FC["phone"].innerText || `${t("Enter")} ${t("Phone number").toLowerCase()}`}
|
||||||
desc={FC["phone"].text || t("Phone number")}
|
desc={FC["phone"].text || t("Phone number")}
|
||||||
Icon={PhoneIcon}
|
Icon={PhoneIcon}
|
||||||
isPhone={true}
|
isPhone={true}
|
||||||
error={phoneError}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
const Text = (
|
const Text = (
|
||||||
|
@ -15,7 +15,7 @@ export const Footer = ({ stepNumber, nextButton, prevButton }: FooterProps) => {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { questions, settings } = useQuizStore();
|
const { questions, settings } = useQuizStore();
|
||||||
const questionsAmount = questions.filter(({ type }) => type !== "result").length;
|
const questionsAmount = questions.filter(({ type }) => type !== "result").length;
|
||||||
const { t, i18n } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
|
@ -6,23 +6,6 @@ import { AnyTypedQuizQuestion, QuizQuestionVariant } from "@/index";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useQuizStore } from "@/stores/useQuizStore";
|
import { useQuizStore } from "@/stores/useQuizStore";
|
||||||
|
|
||||||
const dinocrutch = window.location.pathname === "/413b9e24-996a-400e-9076-c158f64b9bd7";
|
|
||||||
|
|
||||||
// Функция для определения вопроса "спасибо"
|
|
||||||
const isThankYouQuestion = (question: QuizQuestionVariant): boolean => {
|
|
||||||
// Проверяем что у вопроса только один вариант ответа
|
|
||||||
if (question.content.variants.length !== 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Проверяем что текст варианта полностью состоит из слова "спасибо"
|
|
||||||
const variant = question.content.variants[0];
|
|
||||||
const answerText = variant.answer.toLowerCase().trim();
|
|
||||||
|
|
||||||
// Проверяем точное совпадение со словом "спасибо"
|
|
||||||
return answerText === "далее";
|
|
||||||
};
|
|
||||||
|
|
||||||
export const PointSystemResultList = () => {
|
export const PointSystemResultList = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { questions } = useQuizStore();
|
const { questions } = useQuizStore();
|
||||||
@ -33,12 +16,7 @@ export const PointSystemResultList = () => {
|
|||||||
(q: AnyTypedQuizQuestion): q is QuizQuestionVariant => q.type === "variant"
|
(q: AnyTypedQuizQuestion): q is QuizQuestionVariant => q.type === "variant"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Фильтруем вопросы "спасибо" только для указанного квиза
|
return questionsWothoutResult.map((currentQuestion) => {
|
||||||
const filteredQuestions = dinocrutch
|
|
||||||
? questionsWothoutResult.filter((q) => !isThankYouQuestion(q))
|
|
||||||
: questionsWothoutResult;
|
|
||||||
|
|
||||||
return filteredQuestions.map((currentQuestion, index) => {
|
|
||||||
let answerIndex = 0;
|
let answerIndex = 0;
|
||||||
let currentVariants = currentQuestion.content.variants;
|
let currentVariants = currentQuestion.content.variants;
|
||||||
|
|
||||||
@ -75,7 +53,7 @@ export const PointSystemResultList = () => {
|
|||||||
color: theme.palette.grey[500],
|
color: theme.palette.grey[500],
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{index + 1}.
|
{currentQuestion.page + 1}.
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography
|
<Typography
|
||||||
sx={{
|
sx={{
|
||||||
|
@ -12,7 +12,6 @@ import { quizThemes } from "@utils/themes/Publication/themePublication";
|
|||||||
import { NameplateLogo } from "@icons/NameplateLogo";
|
import { NameplateLogo } from "@icons/NameplateLogo";
|
||||||
|
|
||||||
import type { QuizQuestionResult } from "@/model/questionTypes/result";
|
import type { QuizQuestionResult } from "@/model/questionTypes/result";
|
||||||
import type { QuizQuestionVariant } from "@/model/questionTypes/variant";
|
|
||||||
import QuizVideo from "@/ui_kit/VideoIframe/VideoIframe";
|
import QuizVideo from "@/ui_kit/VideoIframe/VideoIframe";
|
||||||
import { TextAccordion } from "./tools/TextAccordion";
|
import { TextAccordion } from "./tools/TextAccordion";
|
||||||
import { PointSystemResultList } from "./PointSystemResultList";
|
import { PointSystemResultList } from "./PointSystemResultList";
|
||||||
@ -21,27 +20,11 @@ import { sendFC, sendResult } from "@/api/quizRelase";
|
|||||||
import { isProduction } from "@/utils/defineDomain";
|
import { isProduction } from "@/utils/defineDomain";
|
||||||
import { useQuizStore } from "@/stores/useQuizStore";
|
import { useQuizStore } from "@/stores/useQuizStore";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { NameplateLogoDark } from "@/assets/icons/NameplateLogoDark";
|
|
||||||
|
|
||||||
type ResultFormProps = {
|
type ResultFormProps = {
|
||||||
resultQuestion: QuizQuestionResult;
|
resultQuestion: QuizQuestionResult;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Функция для определения вопроса "спасибо"
|
|
||||||
const isThankYouQuestion = (question: QuizQuestionVariant): boolean => {
|
|
||||||
// Проверяем что у вопроса только один вариант ответа
|
|
||||||
if (question.content.variants.length !== 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Проверяем что текст варианта полностью состоит из слова "спасибо"
|
|
||||||
const variant = question.content.variants[0];
|
|
||||||
const answerText = variant.answer.toLowerCase().trim();
|
|
||||||
|
|
||||||
// Проверяем точное совпадение со словом "спасибо"
|
|
||||||
return answerText === "далее";
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
|
export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isMobile = useRootContainerSize() < 650;
|
const isMobile = useRootContainerSize() < 650;
|
||||||
@ -55,22 +38,6 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
|
|||||||
const yandexMetrics = useYandexMetricsGoals(settings.cfg.yandexMetricsNumber);
|
const yandexMetrics = useYandexMetricsGoals(settings.cfg.yandexMetricsNumber);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
// Проверяем, является ли это квизом с костылем
|
|
||||||
const dinocrutch = window.location.pathname === "/413b9e24-996a-400e-9076-c158f64b9bd7";
|
|
||||||
|
|
||||||
// Вычисляем общее количество вопросов с учетом фильтрации
|
|
||||||
const totalQuestions = useMemo(() => {
|
|
||||||
if (dinocrutch) {
|
|
||||||
// Для квиза с костылем: исключаем вопросы "спасибо" и вопросы типа "result"
|
|
||||||
const variantQuestions = questions.filter((e) => e.type === "variant") as QuizQuestionVariant[];
|
|
||||||
const filteredQuestions = variantQuestions.filter((q) => !isThankYouQuestion(q));
|
|
||||||
return filteredQuestions.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Для обычных квизов: исключаем только вопросы типа "result"
|
|
||||||
return questions.filter((e) => e.type !== "result").length;
|
|
||||||
}, [questions, dinocrutch]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
vkMetrics.resultIdShown(resultQuestion.id);
|
vkMetrics.resultIdShown(resultQuestion.id);
|
||||||
yandexMetrics.resultIdShown(resultQuestion.id);
|
yandexMetrics.resultIdShown(resultQuestion.id);
|
||||||
@ -292,7 +259,7 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
|
|||||||
fontWeight: 600,
|
fontWeight: 600,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{pointsSum} {t("of")} {totalQuestions}
|
{pointsSum} {t("of")} {questions.filter((e) => e.type != "result").length}
|
||||||
</Typography>
|
</Typography>
|
||||||
<TextAccordion
|
<TextAccordion
|
||||||
headerText={
|
headerText={
|
||||||
@ -341,7 +308,12 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
|
|||||||
bottom: "90px",
|
bottom: "90px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{quizThemes[settings.cfg.theme].isLight ? <NameplateLogoDark /> : <NameplateLogo />}
|
<NameplateLogo
|
||||||
|
style={{
|
||||||
|
fontSize: "23px",
|
||||||
|
color: quizThemes[settings.cfg.theme].isLight ? "#000000" : "#F5F7FF",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
<Box
|
<Box
|
||||||
|
@ -9,7 +9,6 @@ import { useUADevice } from "@utils/hooks/useUADevice";
|
|||||||
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
||||||
|
|
||||||
import { NameplateLogo } from "@icons/NameplateLogo";
|
import { NameplateLogo } from "@icons/NameplateLogo";
|
||||||
import { NameplateLogoDark } from "@icons/NameplateLogoDark";
|
|
||||||
import { useQuizViewStore } from "@/stores/quizView";
|
import { useQuizViewStore } from "@/stores/quizView";
|
||||||
import { DESIGN_LIST } from "@/utils/designList";
|
import { DESIGN_LIST } from "@/utils/designList";
|
||||||
|
|
||||||
@ -154,13 +153,17 @@ export const StartPageViewPublication = () => {
|
|||||||
: undefined,
|
: undefined,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{settings.cfg.startpageType === "expanded" ? (
|
<NameplateLogo
|
||||||
<NameplateLogo />
|
style={{
|
||||||
) : quizThemes[settings.cfg.theme].isLight ? (
|
fontSize: "23px",
|
||||||
<NameplateLogoDark />
|
color:
|
||||||
) : (
|
settings.cfg.startpageType === "expanded"
|
||||||
<NameplateLogo />
|
? "#FFFFFF"
|
||||||
)}
|
: quizThemes[settings.cfg.theme].isLight
|
||||||
|
? "#151515"
|
||||||
|
: "#FFFFFF",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import { useYandexMetrics } from "@/utils/hooks/metrics/useYandexMetrics";
|
|||||||
import { sendQuestionAnswer } from "@/utils/sendQuestionAnswer";
|
import { sendQuestionAnswer } from "@/utils/sendQuestionAnswer";
|
||||||
import { ThemeProvider, Typography } from "@mui/material";
|
import { ThemeProvider, Typography } from "@mui/material";
|
||||||
import { useQuizViewStore } from "@stores/quizView";
|
import { useQuizViewStore } from "@stores/quizView";
|
||||||
import { statusOfQuiz, useQuestionFlowControl } from "@utils/hooks/useQuestionFlowControl";
|
import { useQuestionFlowControl } from "@utils/hooks/useQuestionFlowControl";
|
||||||
import { notReachable } from "@utils/notReachable";
|
import { notReachable } from "@utils/notReachable";
|
||||||
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
||||||
import { enqueueSnackbar } from "notistack";
|
import { enqueueSnackbar } from "notistack";
|
||||||
@ -18,10 +18,7 @@ import { StartPageViewPublication } from "./StartPageViewPublication";
|
|||||||
import NextButton from "./tools/NextButton";
|
import NextButton from "./tools/NextButton";
|
||||||
import PrevButton from "./tools/PrevButton";
|
import PrevButton from "./tools/PrevButton";
|
||||||
import unscreen from "@/ui_kit/unscreen";
|
import unscreen from "@/ui_kit/unscreen";
|
||||||
import { changeNextLoading, useQuizStore } from "@/stores/useQuizStore";
|
import { useQuizStore } from "@/stores/useQuizStore";
|
||||||
import { polyfillCountryFlagEmojis } from "country-flag-emoji-polyfill";
|
|
||||||
|
|
||||||
polyfillCountryFlagEmojis();
|
|
||||||
|
|
||||||
export default function ViewPublicationPage() {
|
export default function ViewPublicationPage() {
|
||||||
const { settings, recentlyCompleted, quizId, preview, changeFaviconAndTitle } = useQuizStore();
|
const { settings, recentlyCompleted, quizId, preview, changeFaviconAndTitle } = useQuizStore();
|
||||||
@ -70,7 +67,7 @@ export default function ViewPublicationPage() {
|
|||||||
if (settings.cfg.antifraud && recentlyCompleted) throw new Error("Quiz already completed");
|
if (settings.cfg.antifraud && recentlyCompleted) throw new Error("Quiz already completed");
|
||||||
if (currentQuizStep === "startpage" && settings.cfg.noStartPage) currentQuizStep = "question";
|
if (currentQuizStep === "startpage" && settings.cfg.noStartPage) currentQuizStep = "question";
|
||||||
|
|
||||||
if (!currentQuestion) {
|
if (!currentQuestion)
|
||||||
return (
|
return (
|
||||||
<ThemeProvider theme={quizThemes[settings.cfg.theme || "StandardTheme"].theme}>
|
<ThemeProvider theme={quizThemes[settings.cfg.theme || "StandardTheme"].theme}>
|
||||||
<Typography
|
<Typography
|
||||||
@ -81,7 +78,6 @@ export default function ViewPublicationPage() {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
const currentAnswer = answers.find(({ questionId }) => questionId === currentQuestion.id);
|
const currentAnswer = answers.find(({ questionId }) => questionId === currentQuestion.id);
|
||||||
|
|
||||||
@ -112,7 +108,6 @@ export default function ViewPublicationPage() {
|
|||||||
<NextButton
|
<NextButton
|
||||||
isNextButtonEnabled={settings.status === "ai" || isNextButtonEnabled}
|
isNextButtonEnabled={settings.status === "ai" || isNextButtonEnabled}
|
||||||
moveToNextQuestion={async () => {
|
moveToNextQuestion={async () => {
|
||||||
if (statusOfQuiz == "ai") changeNextLoading(true);
|
|
||||||
if (!preview) {
|
if (!preview) {
|
||||||
await sendQuestionAnswer(quizId, currentQuestion, currentAnswer, ownVariants)?.catch((e) => {
|
await sendQuestionAnswer(quizId, currentQuestion, currentAnswer, ownVariants)?.catch((e) => {
|
||||||
enqueueSnackbar("Ошибка при отправке ответа");
|
enqueueSnackbar("Ошибка при отправке ответа");
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
import EmojiPickerOriginal from "@emoji-mart/react";
|
|
||||||
import { Box } from "@mui/material";
|
|
||||||
|
|
||||||
type Emoji = {
|
|
||||||
emoticons: string[];
|
|
||||||
id: string;
|
|
||||||
keywords: string[];
|
|
||||||
name: string;
|
|
||||||
native: string;
|
|
||||||
shortcodes: string;
|
|
||||||
unified: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type EmojiPickerProps = {
|
|
||||||
onEmojiSelect: (emoji: Emoji) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const EmojiPicker = ({ onEmojiSelect }: EmojiPickerProps) => (
|
|
||||||
<Box sx={{ minWidth: "352px" }}>
|
|
||||||
<EmojiPickerOriginal
|
|
||||||
onEmojiSelect={onEmojiSelect}
|
|
||||||
theme="light"
|
|
||||||
locale="ru"
|
|
||||||
exceptEmojis={ignoreEmojis}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
|
|
||||||
const ignoreEmojis = [
|
|
||||||
"two_men_holding_hands",
|
|
||||||
"two_women_holding_hands",
|
|
||||||
"man-kiss-man",
|
|
||||||
"woman-kiss-woman",
|
|
||||||
"man-heart-man",
|
|
||||||
"woman-heart-woman",
|
|
||||||
"man-man-boy",
|
|
||||||
"man-man-girl",
|
|
||||||
"man-man-girl-boy",
|
|
||||||
"man-man-girl-girl",
|
|
||||||
"man-man-boy-boy",
|
|
||||||
"woman-woman-boy",
|
|
||||||
"woman-woman-girl",
|
|
||||||
"woman-woman-girl-boy",
|
|
||||||
"woman-woman-girl-girl",
|
|
||||||
"woman-woman-boy-boy",
|
|
||||||
"rainbow-flag",
|
|
||||||
"transgender_flag",
|
|
||||||
"transgender_symbol",
|
|
||||||
];
|
|
@ -1,6 +1,5 @@
|
|||||||
import type { QuestionVariant } from "@/model/questionTypes/shared";
|
import type { QuestionVariant } from "@/model/questionTypes/shared";
|
||||||
import { useQuizStore } from "@/stores/useQuizStore";
|
import { useQuizStore } from "@/stores/useQuizStore";
|
||||||
import { useQuizViewStore, type OwnVariant } from "@stores/quizView";
|
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Checkbox,
|
Checkbox,
|
||||||
@ -12,14 +11,13 @@ import {
|
|||||||
Typography,
|
Typography,
|
||||||
useTheme,
|
useTheme,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
|
import { useQuizViewStore } from "@stores/quizView";
|
||||||
import RadioCheck from "@ui_kit/RadioCheck";
|
import RadioCheck from "@ui_kit/RadioCheck";
|
||||||
import RadioIcon from "@ui_kit/RadioIcon";
|
import RadioIcon from "@ui_kit/RadioIcon";
|
||||||
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
||||||
import { polyfillCountryFlagEmojis } from "country-flag-emoji-polyfill";
|
import { polyfillCountryFlagEmojis } from "country-flag-emoji-polyfill";
|
||||||
import type { MouseEvent } from "react";
|
import type { MouseEvent } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useEffect } from "react";
|
|
||||||
import { OwnEmojiPicker } from "./OwnEmojiPicker";
|
|
||||||
|
|
||||||
polyfillCountryFlagEmojis();
|
polyfillCountryFlagEmojis();
|
||||||
|
|
||||||
@ -45,7 +43,7 @@ const OwnInput = ({ questionId, variant, largeCheck, ownPlaceholder }: OwnInputP
|
|||||||
const ownVariants = useQuizViewStore((state) => state.ownVariants);
|
const ownVariants = useQuizViewStore((state) => state.ownVariants);
|
||||||
const { updateOwnVariant } = useQuizViewStore((state) => state);
|
const { updateOwnVariant } = useQuizViewStore((state) => state);
|
||||||
|
|
||||||
const ownAnswer = ownVariants[ownVariants.findIndex((v: OwnVariant) => v.id === variant.id)]?.variant.answer || "";
|
const ownAnswer = ownVariants[ownVariants.findIndex((v) => v.id === variant.id)]?.variant.answer || "";
|
||||||
|
|
||||||
return largeCheck ? (
|
return largeCheck ? (
|
||||||
<Box sx={{ overflow: "auto" }}>
|
<Box sx={{ overflow: "auto" }}>
|
||||||
@ -108,52 +106,41 @@ export const EmojiVariant = ({
|
|||||||
ownPlaceholder,
|
ownPlaceholder,
|
||||||
}: EmojiVariantProps) => {
|
}: EmojiVariantProps) => {
|
||||||
const { settings } = useQuizStore();
|
const { settings } = useQuizStore();
|
||||||
const { updateAnswer, deleteAnswer, updateOwnVariant, ownVariants } = useQuizViewStore((state) => state);
|
const answers = useQuizViewStore((state) => state.answers);
|
||||||
|
const { updateAnswer, deleteAnswer } = useQuizViewStore((state) => state);
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const customEmoji = ownVariants.find((v: OwnVariant) => v.id === variant.id)?.variant.extendedText || "";
|
|
||||||
|
|
||||||
const onVariantClick = async (event: MouseEvent<HTMLDivElement>) => {
|
const onVariantClick = async (event: MouseEvent<HTMLDivElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const variantId = variant.id;
|
|
||||||
|
|
||||||
|
const variantId = variant.id;
|
||||||
if (isMulti) {
|
if (isMulti) {
|
||||||
const currentAnswer = Array.isArray(answer) ? answer : [];
|
const currentAnswer = typeof answer !== "string" ? answer || [] : [];
|
||||||
const newAnswer = currentAnswer.includes(variantId)
|
|
||||||
? currentAnswer.filter((item) => item !== variantId)
|
return updateAnswer(
|
||||||
: [...currentAnswer, variantId];
|
questionId,
|
||||||
updateAnswer(questionId, newAnswer, variant.points || 0);
|
currentAnswer.includes(variantId)
|
||||||
} else {
|
? currentAnswer?.filter((item) => item !== variantId)
|
||||||
|
: [...currentAnswer, variantId],
|
||||||
|
variant.points || 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateAnswer(questionId, variant.id, variant.points || 0);
|
||||||
|
|
||||||
if (answer === variant.id) {
|
if (answer === variant.id) {
|
||||||
deleteAnswer(questionId);
|
deleteAnswer(questionId);
|
||||||
} else {
|
|
||||||
updateAnswer(questionId, variant.id, variant.points || 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEmojiSelect = (emoji: string) => {
|
|
||||||
// We store custom emoji in ownVariants store, with a specific field to differentiate
|
|
||||||
const currentOwnAnswer = ownVariants.find((v: OwnVariant) => v.id === variant.id)?.variant.answer || "";
|
|
||||||
updateOwnVariant(variant.id, currentOwnAnswer, emoji);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleEmojiRemove = () => {
|
|
||||||
// Сохраняем текущий answer, очищаем только extendedText (эмодзи)
|
|
||||||
const currentOwnAnswer = ownVariants.find((v: OwnVariant) => v.id === variant.id)?.variant.answer || "";
|
|
||||||
updateOwnVariant(variant.id, currentOwnAnswer, "");
|
|
||||||
};
|
|
||||||
|
|
||||||
const isSelected = isMulti ? Array.isArray(answer) && answer.includes(variant.id) : answer === variant.id;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormControl
|
<FormControl
|
||||||
key={index}
|
key={index}
|
||||||
sx={{
|
sx={{
|
||||||
borderRadius: "12px",
|
borderRadius: "12px",
|
||||||
border: `1px solid`,
|
border: `1px solid`,
|
||||||
borderColor: isSelected ? theme.palette.primary.main : "#9A9AAF",
|
borderColor: answer?.includes(variant.id) ? theme.palette.primary.main : "#9A9AAF",
|
||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
maxWidth: "317px",
|
maxWidth: "317px",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
@ -166,6 +153,7 @@ export const EmojiVariant = ({
|
|||||||
: "transparent",
|
: "transparent",
|
||||||
"&:hover": { borderColor: theme.palette.primary.main },
|
"&:hover": { borderColor: theme.palette.primary.main },
|
||||||
}}
|
}}
|
||||||
|
// value={index}
|
||||||
onClick={onVariantClick}
|
onClick={onVariantClick}
|
||||||
>
|
>
|
||||||
<Box
|
<Box
|
||||||
@ -177,13 +165,6 @@ export const EmojiVariant = ({
|
|||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{own ? (
|
|
||||||
<OwnEmojiPicker
|
|
||||||
emoji={customEmoji || variant.extendedText}
|
|
||||||
onEmojiSelect={handleEmojiSelect}
|
|
||||||
onEmojiRemove={customEmoji ? handleEmojiRemove : undefined}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
@ -193,7 +174,6 @@ export const EmojiVariant = ({
|
|||||||
>
|
>
|
||||||
{variant.extendedText && <Typography fontSize="100px">{variant.extendedText}</Typography>}
|
{variant.extendedText && <Typography fontSize="100px">{variant.extendedText}</Typography>}
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
|
||||||
</Box>
|
</Box>
|
||||||
{own && (
|
{own && (
|
||||||
<Typography
|
<Typography
|
||||||
@ -237,14 +217,13 @@ export const EmojiVariant = ({
|
|||||||
control={
|
control={
|
||||||
isMulti ? (
|
isMulti ? (
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checked={isSelected}
|
checked={!!answer?.includes(variant.id)}
|
||||||
checkedIcon={<RadioCheck color={theme.palette.primary.main} />}
|
checkedIcon={<RadioCheck color={theme.palette.primary.main} />}
|
||||||
icon={<RadioIcon />}
|
icon={<RadioIcon />}
|
||||||
sx={{ position: "absolute", top: "-162px", right: "12px" }}
|
sx={{ position: "absolute", top: "-162px", right: "12px" }}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Radio
|
<Radio
|
||||||
checked={isSelected}
|
|
||||||
checkedIcon={<RadioCheck color={theme.palette.primary.main} />}
|
checkedIcon={<RadioCheck color={theme.palette.primary.main} />}
|
||||||
icon={<RadioIcon />}
|
icon={<RadioIcon />}
|
||||||
sx={{ position: "absolute", top: "-162px", right: "12px" }}
|
sx={{ position: "absolute", top: "-162px", right: "12px" }}
|
||||||
|
@ -1,103 +0,0 @@
|
|||||||
import { Box, ButtonBase, Typography, useTheme, Modal, IconButton } from "@mui/material";
|
|
||||||
import { useState } from "react";
|
|
||||||
import { EmojiPicker } from "./EmojiPicker";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import CloseIcon from "@mui/icons-material/Close";
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
emoji: string;
|
|
||||||
onEmojiSelect?: (emoji: string) => void;
|
|
||||||
onEmojiRemove?: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const OwnEmojiPicker = ({ emoji = "", onEmojiSelect, onEmojiRemove }: Props) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const [isPickerOpen, setIsPickerOpen] = useState(false);
|
|
||||||
|
|
||||||
const handleEmojiSelect = (emojiData: any) => {
|
|
||||||
onEmojiSelect?.(emojiData.native);
|
|
||||||
setIsPickerOpen(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClick = (e: React.MouseEvent) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
setIsPickerOpen(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClose = (e: React.MouseEvent) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
setIsPickerOpen(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleRemoveEmoji = (e: React.MouseEvent) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
onEmojiRemove?.();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Box sx={{ width: "100%", height: "100%", position: "relative" }}>
|
|
||||||
<ButtonBase
|
|
||||||
onClick={handleClick}
|
|
||||||
sx={{
|
|
||||||
width: "100%",
|
|
||||||
height: "100%",
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
"&:hover": {
|
|
||||||
bgcolor: theme.palette.grey[100],
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography fontSize={emoji ? "100px" : "18px"}>{emoji || t("select emoji")}</Typography>
|
|
||||||
</ButtonBase>
|
|
||||||
|
|
||||||
{onEmojiRemove && (
|
|
||||||
<IconButton
|
|
||||||
onClick={handleRemoveEmoji}
|
|
||||||
sx={{
|
|
||||||
position: "absolute",
|
|
||||||
top: 8,
|
|
||||||
left: 8,
|
|
||||||
zIndex: 1,
|
|
||||||
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
|
||||||
color: "white",
|
|
||||||
height: "25px",
|
|
||||||
width: "25px",
|
|
||||||
"&:hover": {
|
|
||||||
backgroundColor: "rgba(0, 0, 0, 0.7)",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<CloseIcon />
|
|
||||||
</IconButton>
|
|
||||||
)}
|
|
||||||
</Box>
|
|
||||||
|
|
||||||
<Modal
|
|
||||||
open={isPickerOpen}
|
|
||||||
onClose={handleClose}
|
|
||||||
sx={{
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
}}
|
|
||||||
keepMounted
|
|
||||||
>
|
|
||||||
<Box
|
|
||||||
onClick={(e) => e.stopPropagation()}
|
|
||||||
sx={{
|
|
||||||
bgcolor: "background.paper",
|
|
||||||
borderRadius: 2,
|
|
||||||
p: 2,
|
|
||||||
boxShadow: 24,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<EmojiPicker onEmojiSelect={handleEmojiSelect} />
|
|
||||||
</Box>
|
|
||||||
</Modal>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
@ -13,11 +13,10 @@ type EmojiProps = {
|
|||||||
|
|
||||||
export const Emoji = ({ currentQuestion }: EmojiProps) => {
|
export const Emoji = ({ currentQuestion }: EmojiProps) => {
|
||||||
const answers = useQuizViewStore((state) => state.answers);
|
const answers = useQuizViewStore((state) => state.answers);
|
||||||
|
const { updateAnswer } = useQuizViewStore((state) => state);
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { answer } = answers.find(({ questionId }) => questionId === currentQuestion.id) ?? {};
|
const { answer } = answers.find(({ questionId }) => questionId === currentQuestion.id) ?? {};
|
||||||
|
|
||||||
const selectedVariantId = Array.isArray(answer) ? answer[0] : answer;
|
|
||||||
|
|
||||||
if (moment.isMoment(answer)) throw new Error("Answer is Moment in Variant question");
|
if (moment.isMoment(answer)) throw new Error("Answer is Moment in Variant question");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -31,7 +30,14 @@ export const Emoji = ({ currentQuestion }: EmojiProps) => {
|
|||||||
</Typography>
|
</Typography>
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
name={currentQuestion.id}
|
name={currentQuestion.id}
|
||||||
value={selectedVariantId}
|
value={currentQuestion.content.variants.findIndex(({ id }) => answer === id)}
|
||||||
|
onChange={({ target }) =>
|
||||||
|
updateAnswer(
|
||||||
|
currentQuestion.id,
|
||||||
|
currentQuestion.content.variants[Number(target.value)].answer,
|
||||||
|
currentQuestion.content.variants[Number(target.value)].points || 0
|
||||||
|
)
|
||||||
|
}
|
||||||
sx={{
|
sx={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexWrap: "wrap",
|
flexWrap: "wrap",
|
||||||
|
@ -0,0 +1,122 @@
|
|||||||
|
import { Box, ButtonBase, Typography, useTheme } from "@mui/material";
|
||||||
|
import { useMemo, useState } from "react";
|
||||||
|
import { useRootContainerSize } from "@contexts/RootContainerWidthContext";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { enqueueSnackbar } from "notistack";
|
||||||
|
import { ACCEPT_SEND_FILE_TYPES_MAP } from "@/components/ViewPublicationPage/tools/fileUpload";
|
||||||
|
import UploadIcon from "@icons/UploadIcon";
|
||||||
|
import { uploadFile } from "@/utils/fileUpload";
|
||||||
|
import { useQuizStore } from "@/stores/useQuizStore";
|
||||||
|
|
||||||
|
interface ImageCardProps {
|
||||||
|
questionId: string;
|
||||||
|
imageUrl: string;
|
||||||
|
isOwn?: boolean;
|
||||||
|
onImageUpload?: (fileUrl: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const useFileUpload = (questionId: string, onImageUpload?: (fileUrl: string) => void) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [isSending, setIsSending] = useState(false);
|
||||||
|
const [currentImageUrl, setCurrentImageUrl] = useState<string | null>(null);
|
||||||
|
const { quizId, preview } = useQuizStore();
|
||||||
|
|
||||||
|
const handleFileUpload = async (file: File | undefined) => {
|
||||||
|
if (isSending || !file) return;
|
||||||
|
|
||||||
|
const result = await uploadFile({
|
||||||
|
file,
|
||||||
|
questionId,
|
||||||
|
quizId,
|
||||||
|
fileType: "picture",
|
||||||
|
preview,
|
||||||
|
onSuccess: (fileUrl) => {
|
||||||
|
setCurrentImageUrl(URL.createObjectURL(file));
|
||||||
|
onImageUpload?.(fileUrl);
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.error(error);
|
||||||
|
enqueueSnackbar(t(error.message));
|
||||||
|
},
|
||||||
|
onProgress: () => {
|
||||||
|
setIsSending(true);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
setIsSending(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
isSending,
|
||||||
|
currentImageUrl,
|
||||||
|
handleFileUpload,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ImageCard = ({ questionId, imageUrl, isOwn, onImageUpload }: ImageCardProps) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const isMobile = useRootContainerSize() < 450;
|
||||||
|
const isTablet = useRootContainerSize() < 850;
|
||||||
|
const [isDropzoneHighlighted, setIsDropzoneHighlighted] = useState(false);
|
||||||
|
const { currentImageUrl, handleFileUpload } = useFileUpload(questionId, onImageUpload);
|
||||||
|
|
||||||
|
const onDrop = (event: React.DragEvent<HTMLLabelElement>) => {
|
||||||
|
event.preventDefault();
|
||||||
|
setIsDropzoneHighlighted(false);
|
||||||
|
|
||||||
|
const file = event.dataTransfer.files[0];
|
||||||
|
handleFileUpload(file);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box sx={{ width: "100%", height: "300px", position: "relative" }}>
|
||||||
|
<img
|
||||||
|
src={currentImageUrl || imageUrl}
|
||||||
|
style={{
|
||||||
|
display: "block",
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
objectFit: "cover",
|
||||||
|
borderRadius: "12px 12px 0 0",
|
||||||
|
}}
|
||||||
|
alt=""
|
||||||
|
/>
|
||||||
|
{isOwn && (
|
||||||
|
<Box
|
||||||
|
component="label"
|
||||||
|
sx={{
|
||||||
|
position: "absolute",
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
||||||
|
opacity: isDropzoneHighlighted ? 1 : 0,
|
||||||
|
transition: "opacity 0.2s",
|
||||||
|
"&:hover": {
|
||||||
|
opacity: 1,
|
||||||
|
},
|
||||||
|
borderRadius: "12px 12px 0 0",
|
||||||
|
cursor: "pointer",
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
}}
|
||||||
|
onDragEnter={() => setIsDropzoneHighlighted(true)}
|
||||||
|
onDragLeave={() => setIsDropzoneHighlighted(false)}
|
||||||
|
onDragOver={(event) => event.preventDefault()}
|
||||||
|
onDrop={onDrop}
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
onChange={({ target }) => handleFileUpload(target.files?.[0])}
|
||||||
|
hidden
|
||||||
|
accept={ACCEPT_SEND_FILE_TYPES_MAP.picture.join(",")}
|
||||||
|
type="file"
|
||||||
|
/>
|
||||||
|
<UploadIcon color="#FFFFFF" />
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
@ -1,15 +1,30 @@
|
|||||||
|
import { CheckboxIcon } from "@/assets/icons/Checkbox";
|
||||||
import type { QuestionVariant, QuestionVariantWithEditedImages } from "@/model/questionTypes/shared";
|
import type { QuestionVariant, QuestionVariantWithEditedImages } from "@/model/questionTypes/shared";
|
||||||
import { Box, Checkbox, FormControlLabel, Input, Radio, TextareaAutosize, Typography, useTheme } from "@mui/material";
|
import {
|
||||||
|
Box,
|
||||||
|
Checkbox,
|
||||||
|
FormControlLabel,
|
||||||
|
Input,
|
||||||
|
Radio,
|
||||||
|
TextareaAutosize,
|
||||||
|
Typography,
|
||||||
|
useTheme,
|
||||||
|
ButtonBase,
|
||||||
|
} from "@mui/material";
|
||||||
import { useQuizViewStore } from "@stores/quizView";
|
import { useQuizViewStore } from "@stores/quizView";
|
||||||
import RadioCheck from "@ui_kit/RadioCheck";
|
import RadioCheck from "@ui_kit/RadioCheck";
|
||||||
import RadioIcon from "@ui_kit/RadioIcon";
|
import RadioIcon from "@ui_kit/RadioIcon";
|
||||||
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
||||||
import { useMemo, type MouseEvent, useRef, useEffect } from "react";
|
import { useMemo, type MouseEvent, useRef, useEffect, useState } from "react";
|
||||||
import { useRootContainerSize } from "@contexts/RootContainerWidthContext";
|
import { useRootContainerSize } from "@contexts/RootContainerWidthContext";
|
||||||
import { useQuizStore } from "@/stores/useQuizStore";
|
import { useQuizStore } from "@/stores/useQuizStore";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { OwnImage } from "./OwnImage";
|
import { sendAnswer, sendFile } from "@api/quizRelase";
|
||||||
import { useSnackbar } from "notistack";
|
import { enqueueSnackbar } from "notistack";
|
||||||
|
import { ACCEPT_SEND_FILE_TYPES_MAP, MAX_FILE_SIZE } from "@/components/ViewPublicationPage/tools/fileUpload";
|
||||||
|
import UploadIcon from "@icons/UploadIcon";
|
||||||
|
import { uploadFile } from "@/utils/fileUpload";
|
||||||
|
import { ImageCard } from "./ImageCard";
|
||||||
|
|
||||||
type ImagesProps = {
|
type ImagesProps = {
|
||||||
questionId: string;
|
questionId: string;
|
||||||
@ -23,7 +38,6 @@ type ImagesProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
interface OwnInputProps {
|
interface OwnInputProps {
|
||||||
questionId: string;
|
|
||||||
variant: QuestionVariant;
|
variant: QuestionVariant;
|
||||||
largeCheck: boolean;
|
largeCheck: boolean;
|
||||||
ownPlaceholder: string;
|
ownPlaceholder: string;
|
||||||
@ -98,15 +112,20 @@ export const ImageVariant = ({
|
|||||||
const { deleteAnswer, updateAnswer } = useQuizViewStore((state) => state);
|
const { deleteAnswer, updateAnswer } = useQuizViewStore((state) => state);
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const answers = useQuizViewStore((state) => state.answers);
|
||||||
const isMobile = useRootContainerSize() < 450;
|
const isMobile = useRootContainerSize() < 450;
|
||||||
const isTablet = useRootContainerSize() < 850;
|
const isTablet = useRootContainerSize() < 850;
|
||||||
const { enqueueSnackbar } = useSnackbar();
|
const [isSending, setIsSending] = useState(false);
|
||||||
|
|
||||||
|
const { quizId, preview } = useQuizStore();
|
||||||
|
|
||||||
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
||||||
|
|
||||||
const onVariantClick = async (event: MouseEvent<HTMLDivElement>) => {
|
const onVariantClick = async (event: MouseEvent<HTMLDivElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
|
if (own) return;
|
||||||
|
|
||||||
const variantId = variant.id;
|
const variantId = variant.id;
|
||||||
if (isMulti) {
|
if (isMulti) {
|
||||||
const currentAnswer = typeof answer !== "string" ? answer || [] : [];
|
const currentAnswer = typeof answer !== "string" ? answer || [] : [];
|
||||||
@ -127,13 +146,37 @@ export const ImageVariant = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleFileUpload = async (file: File | undefined) => {
|
||||||
|
if (isSending || !file) return;
|
||||||
|
|
||||||
|
const result = await uploadFile({
|
||||||
|
file,
|
||||||
|
questionId,
|
||||||
|
quizId,
|
||||||
|
fileType: "picture",
|
||||||
|
preview,
|
||||||
|
onSuccess: (fileUrl) => {
|
||||||
|
setImageUrl(URL.createObjectURL(file));
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.error(error);
|
||||||
|
enqueueSnackbar(t(error.message));
|
||||||
|
},
|
||||||
|
onProgress: () => {
|
||||||
|
setIsSending(true);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
setIsSending(false);
|
||||||
|
};
|
||||||
|
|
||||||
const choiceImgUrl = useMemo(() => {
|
const choiceImgUrl = useMemo(() => {
|
||||||
if (variant.editedUrlImagesList !== undefined && variant.editedUrlImagesList !== null) {
|
if (variant.editedUrlImagesList !== undefined && variant.editedUrlImagesList !== null) {
|
||||||
return variant.editedUrlImagesList[isMobile ? "mobile" : isTablet ? "tablet" : "desktop"];
|
return variant.editedUrlImagesList[isMobile ? "mobile" : isTablet ? "tablet" : "desktop"];
|
||||||
} else {
|
} else {
|
||||||
return variant.extendedText;
|
return variant.extendedText;
|
||||||
}
|
}
|
||||||
}, []);
|
}, [variant.editedUrlImagesList, isMobile, isTablet, variant.extendedText]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (canvasRef.current !== null) {
|
if (canvasRef.current !== null) {
|
||||||
@ -156,11 +199,11 @@ export const ImageVariant = ({
|
|||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
position: "relative",
|
position: "relative",
|
||||||
cursor: "pointer",
|
cursor: own ? "default" : "pointer",
|
||||||
borderRadius: "12px",
|
borderRadius: "12px",
|
||||||
border: `1px solid`,
|
border: `1px solid`,
|
||||||
borderColor: !!answer?.includes(variant.id) ? theme.palette.primary.main : "#9A9AAF",
|
borderColor: !own && !!answer?.includes(variant.id) ? theme.palette.primary.main : "#9A9AAF",
|
||||||
"&:hover": { borderColor: theme.palette.primary.main },
|
"&:hover": { borderColor: !own ? theme.palette.primary.main : "#9A9AAF" },
|
||||||
background:
|
background:
|
||||||
settings.cfg.design && !quizThemes[settings.cfg.theme].isLight
|
settings.cfg.design && !quizThemes[settings.cfg.theme].isLight
|
||||||
? "rgba(255,255,255, 0.3)"
|
? "rgba(255,255,255, 0.3)"
|
||||||
@ -171,34 +214,14 @@ export const ImageVariant = ({
|
|||||||
onClick={onVariantClick}
|
onClick={onVariantClick}
|
||||||
>
|
>
|
||||||
<Box sx={{ display: "flex", alignItems: "center", gap: "10px" }}>
|
<Box sx={{ display: "flex", alignItems: "center", gap: "10px" }}>
|
||||||
<Box sx={{ width: "100%", height: "300px" }}>
|
{variant.extendedText && (
|
||||||
{own ? (
|
<ImageCard
|
||||||
<OwnImage
|
|
||||||
imageUrl={choiceImgUrl}
|
|
||||||
questionId={questionId}
|
questionId={questionId}
|
||||||
variantId={variant.id}
|
imageUrl={choiceImgUrl}
|
||||||
onValidationError={(errorType) => {
|
isOwn={own}
|
||||||
enqueueSnackbar(errorType === "size" ? t("file is too big") : t("file type is not supported"), {
|
|
||||||
variant: "warning",
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
) : (
|
|
||||||
variant.extendedText && (
|
|
||||||
<canvas
|
|
||||||
ref={canvasRef}
|
|
||||||
style={{
|
|
||||||
display: "block",
|
|
||||||
width: "100%",
|
|
||||||
height: "100%",
|
|
||||||
objectFit: "cover",
|
|
||||||
borderRadius: "12px 12px 0 0",
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
|
||||||
{own && (
|
{own && (
|
||||||
<Typography
|
<Typography
|
||||||
sx={{
|
sx={{
|
||||||
@ -267,7 +290,6 @@ export const ImageVariant = ({
|
|||||||
label={
|
label={
|
||||||
own ? (
|
own ? (
|
||||||
<OwnInput
|
<OwnInput
|
||||||
questionId={questionId}
|
|
||||||
variant={variant}
|
variant={variant}
|
||||||
largeCheck={questionLargeCheck}
|
largeCheck={questionLargeCheck}
|
||||||
ownPlaceholder={ownPlaceholder || "|"}
|
ownPlaceholder={ownPlaceholder || "|"}
|
||||||
|
@ -1,187 +0,0 @@
|
|||||||
import { Box, ButtonBase, IconButton, Typography, useTheme } from "@mui/material";
|
|
||||||
import { useState, useRef } from "react";
|
|
||||||
import CloseIcon from "@mui/icons-material/Close";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { useQuizStore } from "@/stores/useQuizStore";
|
|
||||||
import { useQuizViewStore } from "@/stores/quizView";
|
|
||||||
import { useSnackbar } from "notistack";
|
|
||||||
import { Skeleton } from "@mui/material";
|
|
||||||
import UploadIcon from "@/assets/icons/UploadIcon";
|
|
||||||
import { sendFile } from "@/api/quizRelase";
|
|
||||||
import { ACCEPT_SEND_FILE_TYPES_MAP, MAX_FILE_SIZE } from "../../tools/fileUpload";
|
|
||||||
|
|
||||||
// Пропсы компонента
|
|
||||||
export type OwnImageProps = {
|
|
||||||
imageUrl?: string;
|
|
||||||
questionId: string;
|
|
||||||
variantId: string;
|
|
||||||
onValidationError: (error: "size" | "type") => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const OwnImage = ({ imageUrl, questionId, variantId, onValidationError }: OwnImageProps) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const { quizId, preview } = useQuizStore();
|
|
||||||
const { ownVariants, updateOwnVariant } = useQuizViewStore((state) => state);
|
|
||||||
const { enqueueSnackbar } = useSnackbar();
|
|
||||||
|
|
||||||
const [isUploading, setIsUploading] = useState(false);
|
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
||||||
|
|
||||||
// Получаем ownVariant для этого варианта
|
|
||||||
const ownVariantData = ownVariants.find((v) => v.id === variantId);
|
|
||||||
|
|
||||||
// Загрузка файла
|
|
||||||
const uploadImage = async (file: File) => {
|
|
||||||
if (isUploading) return;
|
|
||||||
if (!file) return;
|
|
||||||
if (file.size > MAX_FILE_SIZE) {
|
|
||||||
onValidationError("size");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const isFileTypeAccepted = ACCEPT_SEND_FILE_TYPES_MAP.picture.some((fileType) =>
|
|
||||||
file.name.toLowerCase().endsWith(fileType)
|
|
||||||
);
|
|
||||||
if (!isFileTypeAccepted) {
|
|
||||||
onValidationError("type");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setIsUploading(true);
|
|
||||||
try {
|
|
||||||
const data = await sendFile({
|
|
||||||
questionId,
|
|
||||||
body: { file, name: file.name, preview },
|
|
||||||
qid: quizId,
|
|
||||||
});
|
|
||||||
const fileId = data?.data.fileIDMap[questionId];
|
|
||||||
const localImageUrl = URL.createObjectURL(file);
|
|
||||||
updateOwnVariant(variantId, null, "", fileId, localImageUrl);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error uploading image:", error);
|
|
||||||
enqueueSnackbar(t("The answer was not counted"));
|
|
||||||
} finally {
|
|
||||||
setIsUploading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Обработчик выбора файла
|
|
||||||
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
const file = event.target.files?.[0];
|
|
||||||
if (file) {
|
|
||||||
uploadImage(file);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Открытие диалога выбора файла
|
|
||||||
const handleClick = (e: React.MouseEvent) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
if (fileInputRef.current) fileInputRef.current.value = "";
|
|
||||||
fileInputRef.current?.click();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Удаление изображения
|
|
||||||
const handleRemoveImage = (e: React.MouseEvent) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
updateOwnVariant(variantId, ownVariantData?.variant.answer || "", "", "", "");
|
|
||||||
/*
|
|
||||||
1 - answer - письменный ответ
|
|
||||||
2 - extendedText - строка используется в эмодзи-вопросах для хранения выбранного эмодзи
|
|
||||||
3 - originalImageUrl - полный URL изображения, загруженного на сервер
|
|
||||||
4 - localImageUrl - временный URL для отображения изображения в браузере
|
|
||||||
*/
|
|
||||||
};
|
|
||||||
|
|
||||||
// Определяем, что показывать
|
|
||||||
let imageToDisplay: string | null = null;
|
|
||||||
if (ownVariantData?.variant.localImageUrl) {
|
|
||||||
imageToDisplay = ownVariantData.variant.localImageUrl;
|
|
||||||
} else if (imageUrl) {
|
|
||||||
imageToDisplay = imageUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isUploading) {
|
|
||||||
return (
|
|
||||||
<Skeleton
|
|
||||||
variant="rounded"
|
|
||||||
sx={{ width: "100%", height: "100%", borderRadius: "12px" }}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ButtonBase
|
|
||||||
component="div"
|
|
||||||
onClick={handleClick}
|
|
||||||
disabled={isUploading}
|
|
||||||
sx={{
|
|
||||||
width: "100%",
|
|
||||||
height: "100%",
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
borderRadius: "12px",
|
|
||||||
transition: "border-color 0.3s, background-color 0.3s",
|
|
||||||
overflow: "hidden",
|
|
||||||
position: "relative",
|
|
||||||
opacity: isUploading ? 0.7 : 1,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="file"
|
|
||||||
ref={fileInputRef}
|
|
||||||
onChange={handleFileChange}
|
|
||||||
accept={ACCEPT_SEND_FILE_TYPES_MAP.picture.join(",")}
|
|
||||||
hidden
|
|
||||||
/>
|
|
||||||
{imageToDisplay ? (
|
|
||||||
<>
|
|
||||||
<Box sx={{ width: "100%", height: "100%", position: "relative" }}>
|
|
||||||
<img
|
|
||||||
src={imageToDisplay}
|
|
||||||
alt="Preview"
|
|
||||||
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
<IconButton
|
|
||||||
onClick={handleRemoveImage}
|
|
||||||
sx={{
|
|
||||||
position: "absolute",
|
|
||||||
top: 8,
|
|
||||||
left: 8,
|
|
||||||
zIndex: 1,
|
|
||||||
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
|
||||||
color: "white",
|
|
||||||
height: "25px",
|
|
||||||
width: "25px",
|
|
||||||
display: ownVariantData?.variant.localImageUrl ? "inherit" : "none",
|
|
||||||
"&:hover": {
|
|
||||||
backgroundColor: "rgba(0, 0, 0, 0.7)",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<CloseIcon />
|
|
||||||
</IconButton>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<Box
|
|
||||||
sx={{
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "column",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
opacity: 0.5,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<UploadIcon />
|
|
||||||
<Typography
|
|
||||||
variant="body2"
|
|
||||||
color="text.secondary"
|
|
||||||
sx={{ p: 2, textAlign: "center" }}
|
|
||||||
>
|
|
||||||
{t("Add your image")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
</ButtonBase>
|
|
||||||
);
|
|
||||||
};
|
|
@ -36,6 +36,10 @@ export const Number = ({ currentQuestion }: NumberProps) => {
|
|||||||
answer ||
|
answer ||
|
||||||
(reversed ? max + min - currentQuestion.content.start + "—" + max : currentQuestion.content.start + "—" + max);
|
(reversed ? max + min - currentQuestion.content.start + "—" + max : currentQuestion.content.start + "—" + max);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log("reversed:", reversed);
|
||||||
|
}, [reversed]);
|
||||||
|
|
||||||
const sendAnswerToBackend = async (value: string, noUpdate = false) => {
|
const sendAnswerToBackend = async (value: string, noUpdate = false) => {
|
||||||
if (!noUpdate) {
|
if (!noUpdate) {
|
||||||
updateAnswer(currentQuestion.id, value, 0);
|
updateAnswer(currentQuestion.id, value, 0);
|
||||||
|
@ -0,0 +1,120 @@
|
|||||||
|
import { Box, TextField as MuiTextField, TextFieldProps, Typography, useTheme } from "@mui/material";
|
||||||
|
|
||||||
|
import { Answer, useQuizViewStore } from "@stores/quizView";
|
||||||
|
import { useRootContainerSize } from "@contexts/RootContainerWidthContext";
|
||||||
|
|
||||||
|
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
||||||
|
|
||||||
|
import type { ChangeEvent, FC } from "react";
|
||||||
|
import type { QuizQuestionText } from "@model/questionTypes/text";
|
||||||
|
import { useQuizStore } from "@/stores/useQuizStore";
|
||||||
|
|
||||||
|
const TextField = MuiTextField as unknown as FC<TextFieldProps>; // temporary fix ts(2590)
|
||||||
|
|
||||||
|
interface TextSpecialProps {
|
||||||
|
currentQuestion: QuizQuestionText;
|
||||||
|
answer?: Answer;
|
||||||
|
stepNumber?: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function highlightQuestions(text: string) {
|
||||||
|
// Регулярка с учётом возможной точки в конце
|
||||||
|
const regex = /(вопрос\s\d+[a-zA-Zа-яА-Я]\.?)/g;
|
||||||
|
|
||||||
|
// Замена на <span> с жирным текстом
|
||||||
|
return text.replace(regex, '<span style="font-weight: bold">$1</span>');
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TextNeftyanka = ({ currentQuestion, answer, stepNumber }: TextSpecialProps) => {
|
||||||
|
const { settings } = useQuizStore();
|
||||||
|
const { updateAnswer } = useQuizViewStore((state) => state);
|
||||||
|
const isHorizontal = true;
|
||||||
|
const theme = useTheme();
|
||||||
|
const isMobile = useRootContainerSize() < 650;
|
||||||
|
|
||||||
|
const onInputChange = async ({ target }: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
updateAnswer(currentQuestion.id, target.value, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: isMobile ? "column" : undefined,
|
||||||
|
alignItems: isMobile ? "center" : undefined,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "flex",
|
||||||
|
width: "100%",
|
||||||
|
marginTop: "20px",
|
||||||
|
flexDirection: "column",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: "20px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{isHorizontal && currentQuestion.content.back && currentQuestion.content.back !== " " && (
|
||||||
|
<Box
|
||||||
|
sx={{ margin: "30px", width: "50vw", maxHeight: "550px" }}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
key={currentQuestion.id}
|
||||||
|
src={currentQuestion.content.back}
|
||||||
|
style={{ width: "100%", height: "100%", objectFit: "contain" }}
|
||||||
|
alt=""
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
<Typography
|
||||||
|
variant="h5"
|
||||||
|
color={theme.palette.text.primary}
|
||||||
|
sx={{ wordBreak: "break-word" }}
|
||||||
|
>
|
||||||
|
{highlightQuestions(currentQuestion.title)}
|
||||||
|
</Typography>
|
||||||
|
{
|
||||||
|
<TextField
|
||||||
|
autoFocus={true}
|
||||||
|
multiline
|
||||||
|
maxRows={4}
|
||||||
|
placeholder={currentQuestion.content.placeholder}
|
||||||
|
value={answer || ""}
|
||||||
|
onChange={onInputChange}
|
||||||
|
inputProps={{
|
||||||
|
maxLength: 400,
|
||||||
|
background: settings.cfg.design
|
||||||
|
? quizThemes[settings.cfg.theme].isLight
|
||||||
|
? "#F2F3F7"
|
||||||
|
: "rgba(154,154,175, 0.2)"
|
||||||
|
: "transparent",
|
||||||
|
}}
|
||||||
|
sx={{
|
||||||
|
width: "100%",
|
||||||
|
"& .MuiOutlinedInput-root": {
|
||||||
|
backgroundColor: settings.cfg.design ? "rgba(154,154,175, 0.2)" : "#FFFFFF",
|
||||||
|
},
|
||||||
|
"&:focus-visible": {
|
||||||
|
borderColor: theme.palette.primary.main,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</Box>
|
||||||
|
{!isHorizontal && currentQuestion.content.back && currentQuestion.content.back !== " " && (
|
||||||
|
<Box
|
||||||
|
sx={{ margin: "15px", width: "40vw" }}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
key={currentQuestion.id}
|
||||||
|
src={currentQuestion.content.back}
|
||||||
|
style={{ width: "100%", height: "100%", objectFit: "contain" }}
|
||||||
|
alt=""
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
@ -5,6 +5,8 @@ import { TextSpecialHorisontal } from "./TextSpecialHorisontal";
|
|||||||
|
|
||||||
import type { QuizQuestionText } from "@model/questionTypes/text";
|
import type { QuizQuestionText } from "@model/questionTypes/text";
|
||||||
import { useQuizStore } from "@/stores/useQuizStore";
|
import { useQuizStore } from "@/stores/useQuizStore";
|
||||||
|
import { isNeftyanka } from "@/ui_kit/neftyankacrutch";
|
||||||
|
import { TextNeftyanka } from "./TextNeftyanka";
|
||||||
|
|
||||||
type TextProps = {
|
type TextProps = {
|
||||||
currentQuestion: QuizQuestionText;
|
currentQuestion: QuizQuestionText;
|
||||||
@ -18,7 +20,16 @@ export const Text = ({ currentQuestion, stepNumber }: TextProps) => {
|
|||||||
const answers = useQuizViewStore((state) => state.answers);
|
const answers = useQuizViewStore((state) => state.answers);
|
||||||
const { answer } = answers.find(({ questionId }) => questionId === currentQuestion.id) ?? {};
|
const { answer } = answers.find(({ questionId }) => questionId === currentQuestion.id) ?? {};
|
||||||
|
|
||||||
if (pathOnly === "/92ed5e3e-8e6a-491e-87d0-d3197682d0e3" || pathOnly === "/cc006b40-ccbd-4600-a1d3-f902f85aa0a0")
|
if (isNeftyanka)
|
||||||
|
return (
|
||||||
|
<TextNeftyanka
|
||||||
|
currentQuestion={currentQuestion}
|
||||||
|
answer={answer}
|
||||||
|
stepNumber={stepNumber}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (pathOnly === "/92ed5e3e-8e6a-491e-87d0-d3197682d0e3")
|
||||||
return (
|
return (
|
||||||
<TextSpecialHorisontal
|
<TextSpecialHorisontal
|
||||||
currentQuestion={currentQuestion}
|
currentQuestion={currentQuestion}
|
||||||
|
@ -28,18 +28,11 @@ interface OwnInputProps {
|
|||||||
}
|
}
|
||||||
const OwnInput = ({ questionId, variant, largeCheck, ownPlaceholder }: OwnInputProps) => {
|
const OwnInput = ({ questionId, variant, largeCheck, ownPlaceholder }: OwnInputProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
console.log("здравствуй, я овн вопрос. Вот инфо обо мне: ");
|
|
||||||
console.log("questionId ", questionId);
|
|
||||||
console.log("variant", variant);
|
|
||||||
console.log("largeCheck", largeCheck);
|
|
||||||
console.log("ownPlaceholder", ownPlaceholder);
|
|
||||||
console.log("--------------------------");
|
|
||||||
|
|
||||||
const ownVariants = useQuizViewStore((state) => state.ownVariants);
|
const ownVariants = useQuizViewStore((state) => state.ownVariants);
|
||||||
const { updateOwnVariant } = useQuizViewStore((state) => state);
|
const { updateOwnVariant } = useQuizViewStore((state) => state);
|
||||||
|
|
||||||
const ownAnswer = ownVariants[ownVariants.findIndex((v) => v.id === variant.id)]?.variant.answer || "";
|
const ownAnswer = ownVariants[ownVariants.findIndex((v) => v.id === variant.id)]?.variant.answer || "";
|
||||||
console.log("Вот каков стор в данный момент времени:", ownVariants);
|
|
||||||
|
|
||||||
return largeCheck ? (
|
return largeCheck ? (
|
||||||
<TextareaAutosize
|
<TextareaAutosize
|
||||||
@ -66,7 +59,6 @@ const OwnInput = ({ questionId, variant, largeCheck, ownPlaceholder }: OwnInputP
|
|||||||
value={ownAnswer}
|
value={ownAnswer}
|
||||||
onClick={(e: React.MouseEvent<HTMLTextAreaElement>) => e.stopPropagation()}
|
onClick={(e: React.MouseEvent<HTMLTextAreaElement>) => e.stopPropagation()}
|
||||||
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||||
console.log("клик", e.target.value);
|
|
||||||
updateOwnVariant(variant.id, e.target.value);
|
updateOwnVariant(variant.id, e.target.value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -1,83 +0,0 @@
|
|||||||
import React, { forwardRef, useState } from "react";
|
|
||||||
import { useQuizViewStore } from "@stores/quizView";
|
|
||||||
import { useQuizStore } from "@/stores/useQuizStore";
|
|
||||||
import { useSnackbar } from "notistack";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { sendFile } from "@/api/quizRelase";
|
|
||||||
import { ACCEPT_SEND_FILE_TYPES_MAP, MAX_FILE_SIZE } from "../../tools/fileUpload";
|
|
||||||
|
|
||||||
interface OwnVarimgImageProps {
|
|
||||||
questionId: string;
|
|
||||||
variantId: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const OwnVarimgImage = forwardRef<HTMLInputElement, OwnVarimgImageProps>(({ questionId, variantId }, ref) => {
|
|
||||||
const { updateAnswer, updateOwnVariant } = useQuizViewStore((state) => state);
|
|
||||||
const { quizId, preview } = useQuizStore();
|
|
||||||
const { enqueueSnackbar } = useSnackbar();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
const [isUploading, setIsUploading] = useState(false);
|
|
||||||
|
|
||||||
const uploadImage = async (file: File) => {
|
|
||||||
if (isUploading) return;
|
|
||||||
if (!file) return;
|
|
||||||
|
|
||||||
// Валидация размера файла
|
|
||||||
if (file.size > MAX_FILE_SIZE) {
|
|
||||||
enqueueSnackbar(t("file is too big"), { variant: "warning" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Валидация типа файла
|
|
||||||
const isFileTypeAccepted = ACCEPT_SEND_FILE_TYPES_MAP.picture.some((fileType) =>
|
|
||||||
file.name.toLowerCase().endsWith(fileType)
|
|
||||||
);
|
|
||||||
if (!isFileTypeAccepted) {
|
|
||||||
enqueueSnackbar(t("file type is not supported"), { variant: "warning" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsUploading(true);
|
|
||||||
try {
|
|
||||||
const data = await sendFile({
|
|
||||||
questionId,
|
|
||||||
body: { file, name: file.name, preview },
|
|
||||||
qid: quizId,
|
|
||||||
});
|
|
||||||
|
|
||||||
const fileId = data?.data.fileIDMap[questionId];
|
|
||||||
const localImageUrl = URL.createObjectURL(file);
|
|
||||||
|
|
||||||
updateOwnVariant(variantId, null, "", fileId, localImageUrl);
|
|
||||||
// Убираем автоматический выбор own варианта - загрузка возможна только при выбранном own варианте
|
|
||||||
// updateAnswer(questionId, variantId, 0);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error uploading image:", error);
|
|
||||||
enqueueSnackbar(t("The answer was not counted"));
|
|
||||||
} finally {
|
|
||||||
setIsUploading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
const file = event.target.files?.[0];
|
|
||||||
if (file) {
|
|
||||||
uploadImage(file);
|
|
||||||
event.target.value = "";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<input
|
|
||||||
type="file"
|
|
||||||
ref={ref}
|
|
||||||
style={{ display: "none" }}
|
|
||||||
accept={ACCEPT_SEND_FILE_TYPES_MAP.picture.join(",")}
|
|
||||||
onChange={handleFileChange}
|
|
||||||
disabled={isUploading}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
OwnVarimgImage.displayName = "OwnVarimgImage";
|
|
@ -1,12 +1,23 @@
|
|||||||
import type { QuestionVariant, QuestionVariantWithEditedImages } from "@/model/questionTypes/shared";
|
import type { QuestionVariant, QuestionVariantWithEditedImages } from "@/model/questionTypes/shared";
|
||||||
import { useQuizStore } from "@/stores/useQuizStore";
|
import { useQuizStore } from "@/stores/useQuizStore";
|
||||||
import { FormControlLabel, TextareaAutosize, Radio, useTheme, Box, Input, Typography } from "@mui/material";
|
import {
|
||||||
|
FormControlLabel,
|
||||||
|
TextareaAutosize,
|
||||||
|
Radio,
|
||||||
|
useTheme,
|
||||||
|
Box,
|
||||||
|
Input,
|
||||||
|
FormControl,
|
||||||
|
InputLabel,
|
||||||
|
Typography,
|
||||||
|
} from "@mui/material";
|
||||||
import { useQuizViewStore } from "@stores/quizView";
|
import { useQuizViewStore } from "@stores/quizView";
|
||||||
import RadioCheck from "@ui_kit/RadioCheck";
|
import RadioCheck from "@ui_kit/RadioCheck";
|
||||||
import RadioIcon from "@ui_kit/RadioIcon";
|
import RadioIcon from "@ui_kit/RadioIcon";
|
||||||
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
||||||
import { type MouseEvent } from "react";
|
import { type MouseEvent } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useDebouncedCallback } from "use-debounce";
|
||||||
|
|
||||||
type VarimgVariantProps = {
|
type VarimgVariantProps = {
|
||||||
questionId: string;
|
questionId: string;
|
||||||
@ -164,12 +175,16 @@ export const VarimgVariant = ({
|
|||||||
value={index}
|
value={index}
|
||||||
onClick={sendVariant}
|
onClick={sendVariant}
|
||||||
label={
|
label={
|
||||||
|
variant?.isOwn ? (
|
||||||
<OwnInput
|
<OwnInput
|
||||||
questionId={questionId}
|
questionId={questionId}
|
||||||
variant={variant}
|
variant={variant}
|
||||||
largeCheck={questionLargeCheck}
|
largeCheck={questionLargeCheck}
|
||||||
ownPlaceholder={ownPlaceholder || "|"}
|
ownPlaceholder={ownPlaceholder || "|"}
|
||||||
/>
|
/>
|
||||||
|
) : (
|
||||||
|
variant.answer
|
||||||
|
)
|
||||||
}
|
}
|
||||||
control={
|
control={
|
||||||
<Radio
|
<Radio
|
||||||
@ -224,7 +239,18 @@ export const VarimgVariant = ({
|
|||||||
labelPlacement="start"
|
labelPlacement="start"
|
||||||
value={index}
|
value={index}
|
||||||
onClick={sendVariant}
|
onClick={sendVariant}
|
||||||
label={variant.answer}
|
label={
|
||||||
|
variant?.isOwn ? (
|
||||||
|
<OwnInput
|
||||||
|
questionId={questionId}
|
||||||
|
variant={variant}
|
||||||
|
largeCheck={questionLargeCheck}
|
||||||
|
ownPlaceholder={ownPlaceholder || "|"}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
variant.answer
|
||||||
|
)
|
||||||
|
}
|
||||||
control={
|
control={
|
||||||
<Radio
|
<Radio
|
||||||
checkedIcon={<RadioCheck color={theme.palette.primary.main} />}
|
checkedIcon={<RadioCheck color={theme.palette.primary.main} />}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { Box, ButtonBase, RadioGroup, Typography, useTheme, IconButton } from "@mui/material";
|
import { Box, RadioGroup, Typography, useTheme } from "@mui/material";
|
||||||
import CloseIcon from "@mui/icons-material/Close";
|
|
||||||
|
|
||||||
import { VarimgVariant } from "./VarimgVariant";
|
import { VarimgVariant } from "./VarimgVariant";
|
||||||
import { OwnVarimgImage } from "./OwnVarimgImage";
|
|
||||||
|
|
||||||
import { useQuizViewStore } from "@stores/quizView";
|
import { useQuizViewStore } from "@stores/quizView";
|
||||||
import { useRootContainerSize } from "@contexts/RootContainerWidthContext";
|
import { useRootContainerSize } from "@contexts/RootContainerWidthContext";
|
||||||
@ -32,16 +30,6 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
|||||||
const { answer } = answers.find(({ questionId }) => questionId === currentQuestion.id) ?? {};
|
const { answer } = answers.find(({ questionId }) => questionId === currentQuestion.id) ?? {};
|
||||||
const ownVariant = ownVariants.find((variant) => variant.id === currentQuestion.id);
|
const ownVariant = ownVariants.find((variant) => variant.id === currentQuestion.id);
|
||||||
const variant = currentQuestion.content.variants.find(({ id }) => answer === id);
|
const variant = currentQuestion.content.variants.find(({ id }) => answer === id);
|
||||||
const ownVariantInQuestion = useMemo(
|
|
||||||
() => currentQuestion.content.variants.find((v) => v.isOwn),
|
|
||||||
[currentQuestion.content.variants]
|
|
||||||
);
|
|
||||||
const ownVariantData = ownVariants.find((v) => v.id === answer);
|
|
||||||
const ownImageUrl = useMemo(() => {
|
|
||||||
return ownVariantData?.variant.localImageUrl;
|
|
||||||
}, [ownVariantData]);
|
|
||||||
|
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ownVariant) {
|
if (!ownVariant) {
|
||||||
@ -70,23 +58,6 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
|||||||
return currentQuestion.content.back;
|
return currentQuestion.content.back;
|
||||||
}
|
}
|
||||||
}, [variant]);
|
}, [variant]);
|
||||||
|
|
||||||
const handlePreviewAreaClick = () => {
|
|
||||||
// Загрузка возможна только если own вариант выбран
|
|
||||||
if (ownVariantInQuestion && answer === ownVariantInQuestion.id) {
|
|
||||||
inputRef.current?.click();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleRemoveImage = (e: React.MouseEvent) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
if (ownVariantData) {
|
|
||||||
// Сохраняем текущий answer, очищаем только изображения
|
|
||||||
const currentAnswer = ownVariantData.variant.answer || "";
|
|
||||||
updateOwnVariant(ownVariantData.id, currentAnswer, "", "", "");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (moment.isMoment(answer)) throw new Error("Answer is Moment in Variant question");
|
if (moment.isMoment(answer)) throw new Error("Answer is Moment in Variant question");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -148,18 +119,9 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
|||||||
answer={answer}
|
answer={answer}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
{ownVariantInQuestion && (
|
|
||||||
<OwnVarimgImage
|
|
||||||
ref={inputRef}
|
|
||||||
questionId={currentQuestion.id}
|
|
||||||
variantId={ownVariantInQuestion.id}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Box>
|
</Box>
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
<ButtonBase
|
<Box
|
||||||
onClick={handlePreviewAreaClick}
|
|
||||||
disabled={!ownVariantInQuestion || answer !== ownVariantInQuestion.id}
|
|
||||||
sx={{
|
sx={{
|
||||||
maxWidth: "450px",
|
maxWidth: "450px",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
@ -173,94 +135,34 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
|||||||
backgroundColor: "#9A9AAF30",
|
backgroundColor: "#9A9AAF30",
|
||||||
color: theme.palette.text.primary,
|
color: theme.palette.text.primary,
|
||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
position: "relative",
|
|
||||||
"&:hover": {
|
|
||||||
backgroundColor:
|
|
||||||
ownVariantInQuestion && answer === ownVariantInQuestion.id ? "rgba(0,0,0,0.04)" : "transparent",
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
|
onClick={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
{(() => {
|
{answer ? (
|
||||||
if (answer) {
|
choiceImgUrlAnswer ? (
|
||||||
const imageUrl = variant?.isOwn && ownImageUrl ? ownImageUrl : choiceImgUrlAnswer;
|
|
||||||
if (imageUrl) {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<img
|
<img
|
||||||
key={imageUrl}
|
key={choiceImgUrlAnswer}
|
||||||
src={imageUrl}
|
src={choiceImgUrlAnswer}
|
||||||
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
||||||
alt=""
|
alt=""
|
||||||
/>
|
/>
|
||||||
{variant?.isOwn && ownImageUrl && (
|
) : (
|
||||||
<IconButton
|
|
||||||
onClick={handleRemoveImage}
|
|
||||||
sx={{
|
|
||||||
position: "absolute",
|
|
||||||
top: 8,
|
|
||||||
left: 8,
|
|
||||||
zIndex: 1,
|
|
||||||
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
|
||||||
color: "white",
|
|
||||||
height: "25px",
|
|
||||||
width: "25px",
|
|
||||||
"&:hover": {
|
|
||||||
backgroundColor: "rgba(0, 0, 0, 0.7)",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<CloseIcon />
|
|
||||||
</IconButton>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<Box
|
|
||||||
sx={{
|
|
||||||
position: "relative",
|
|
||||||
width: "100%",
|
|
||||||
height: "100%",
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<BlankImage />
|
<BlankImage />
|
||||||
{variant?.isOwn && (
|
)
|
||||||
<Box
|
) : choiceImgUrlQuestion !== " " && choiceImgUrlQuestion !== null && choiceImgUrlQuestion.length > 0 ? (
|
||||||
sx={{
|
|
||||||
position: "absolute",
|
|
||||||
top: "50%",
|
|
||||||
left: "50%",
|
|
||||||
transform: "translate(-50%, -50%)",
|
|
||||||
zIndex: 1,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("Add your image")}
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (choiceImgUrlQuestion && choiceImgUrlQuestion.trim().length > 0) {
|
|
||||||
return (
|
|
||||||
<img
|
<img
|
||||||
src={choiceImgUrlQuestion}
|
src={choiceImgUrlQuestion}
|
||||||
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
||||||
alt=""
|
alt=""
|
||||||
/>
|
/>
|
||||||
);
|
) : currentQuestion.content.replText !== " " && currentQuestion.content.replText.length > 0 ? (
|
||||||
}
|
currentQuestion.content.replText
|
||||||
|
) : variant?.extendedText || isMobile ? (
|
||||||
if (currentQuestion.content.replText && currentQuestion.content.replText.trim().length > 0) {
|
t("Select an answer option below")
|
||||||
return currentQuestion.content.replText;
|
) : (
|
||||||
}
|
t("Select an answer option on the left")
|
||||||
|
)}
|
||||||
return isMobile ? t("Select an answer option below") : t("Select an answer option on the left");
|
</Box>
|
||||||
})()}
|
|
||||||
</ButtonBase>
|
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useQuizStore } from "@/stores/useQuizStore";
|
import { useQuizStore } from "@/stores/useQuizStore";
|
||||||
import { Button, Skeleton } from "@mui/material";
|
import { Button } from "@mui/material";
|
||||||
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
@ -9,19 +9,10 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function NextButton({ isNextButtonEnabled, moveToNextQuestion }: Props) {
|
export default function NextButton({ isNextButtonEnabled, moveToNextQuestion }: Props) {
|
||||||
const { settings, nextLoading } = useQuizStore();
|
const { settings } = useQuizStore();
|
||||||
const { t, i18n } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
return nextLoading ? (
|
return (
|
||||||
<Skeleton
|
|
||||||
variant="rectangular"
|
|
||||||
sx={{
|
|
||||||
borderRadius: "8px",
|
|
||||||
width: "96px",
|
|
||||||
height: "44px",
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<Button
|
<Button
|
||||||
disabled={!isNextButtonEnabled}
|
disabled={!isNextButtonEnabled}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
@ -34,7 +25,7 @@ export default function NextButton({ isNextButtonEnabled, moveToNextQuestion }:
|
|||||||
}}
|
}}
|
||||||
onClick={moveToNextQuestion}
|
onClick={moveToNextQuestion}
|
||||||
>
|
>
|
||||||
{`${t("Next")} →`}
|
далее →{/* {t("Next")} → (*.*) */}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,7 @@ export default function PrevButton({ isPreviousButtonEnabled, moveToPrevQuestion
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { settings } = useQuizStore();
|
const { settings } = useQuizStore();
|
||||||
const isMobileMini = useRootContainerSize() < 382;
|
const isMobileMini = useRootContainerSize() < 382;
|
||||||
const { t, i18n } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
disabled={!isPreviousButtonEnabled}
|
disabled={!isPreviousButtonEnabled}
|
||||||
@ -38,7 +37,8 @@ export default function PrevButton({ isPreviousButtonEnabled, moveToPrevQuestion
|
|||||||
}}
|
}}
|
||||||
onClick={moveToPrevQuestion}
|
onClick={moveToPrevQuestion}
|
||||||
>
|
>
|
||||||
{isMobileMini ? "←" : `← ${t("Prev")}`}
|
{isMobileMini ? "←" : `← назад`}
|
||||||
|
{/* {isMobileMini ? "←" : `← ${t("Prev")}`} (*.*) */}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import { QuizSettings } from "@model/settingsData";
|
|||||||
|
|
||||||
export interface GetQuizDataResponse {
|
export interface GetQuizDataResponse {
|
||||||
cnt: number;
|
cnt: number;
|
||||||
settings?: {
|
settings: {
|
||||||
fp: boolean;
|
fp: boolean;
|
||||||
rep: boolean;
|
rep: boolean;
|
||||||
name: string;
|
name: string;
|
||||||
@ -27,31 +27,9 @@ export interface GetQuizDataResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function parseQuizData(quizDataResponse: GetQuizDataResponse): Omit<QuizSettings, "recentlyCompleted"> {
|
export function parseQuizData(quizDataResponse: GetQuizDataResponse): Omit<QuizSettings, "recentlyCompleted"> {
|
||||||
const readyData = {
|
|
||||||
cnt: quizDataResponse.cnt,
|
|
||||||
show_badge: quizDataResponse.show_badge,
|
|
||||||
settings: {} as QuizSettings["settings"],
|
|
||||||
questions: [] as QuizSettings["questions"],
|
|
||||||
} as QuizSettings;
|
|
||||||
|
|
||||||
const items: QuizSettings["questions"] = quizDataResponse.items.map((item) => {
|
const items: QuizSettings["questions"] = quizDataResponse.items.map((item) => {
|
||||||
const content = item.c
|
const content = JSON.parse(item.c);
|
||||||
? JSON.parse(item.c)
|
|
||||||
: {
|
|
||||||
hint: { text: "", video: "" },
|
|
||||||
rule: { children: [], main: [], parentId: "", default: "" },
|
|
||||||
back: "",
|
|
||||||
originalBack: "",
|
|
||||||
autofill: false,
|
|
||||||
placeholder: "",
|
|
||||||
innerNameCheck: false,
|
|
||||||
innerName: "",
|
|
||||||
required: false,
|
|
||||||
answerType: "single",
|
|
||||||
onlyNumbers: false,
|
|
||||||
};
|
|
||||||
// Убираю замену ID - оставляю оригинальный с бэкенда
|
|
||||||
// if (item.c) content.id = Math.floor(Math.random() * 9999999999) + 1;
|
|
||||||
return {
|
return {
|
||||||
description: item.desc,
|
description: item.desc,
|
||||||
id: item.id,
|
id: item.id,
|
||||||
@ -63,10 +41,7 @@ export function parseQuizData(quizDataResponse: GetQuizDataResponse): Omit<QuizS
|
|||||||
} as unknown as AnyTypedQuizQuestion;
|
} as unknown as AnyTypedQuizQuestion;
|
||||||
});
|
});
|
||||||
|
|
||||||
readyData.questions = items;
|
const settings: QuizSettings["settings"] = {
|
||||||
|
|
||||||
if (quizDataResponse?.settings !== undefined) {
|
|
||||||
readyData.settings = {
|
|
||||||
fp: quizDataResponse.settings.fp,
|
fp: quizDataResponse.settings.fp,
|
||||||
rep: quizDataResponse.settings.rep,
|
rep: quizDataResponse.settings.rep,
|
||||||
name: quizDataResponse.settings.name,
|
name: quizDataResponse.settings.name,
|
||||||
@ -77,7 +52,6 @@ export function parseQuizData(quizDataResponse: GetQuizDataResponse): Omit<QuizS
|
|||||||
pausable: quizDataResponse.settings.pausable,
|
pausable: quizDataResponse.settings.pausable,
|
||||||
status: quizDataResponse.settings.status,
|
status: quizDataResponse.settings.status,
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
return readyData;
|
return { cnt: quizDataResponse.cnt, settings, questions: items, show_badge: quizDataResponse.show_badge };
|
||||||
}
|
}
|
||||||
|
@ -51,10 +51,7 @@ export type QuestionVariant = {
|
|||||||
isMulti?: boolean;
|
isMulti?: boolean;
|
||||||
/** Оригинал изображения (до кропа) */
|
/** Оригинал изображения (до кропа) */
|
||||||
originalImageUrl: string;
|
originalImageUrl: string;
|
||||||
/** Локальный URL для предпросмотра */
|
|
||||||
localImageUrl?: string;
|
|
||||||
points?: number;
|
points?: number;
|
||||||
fileId?: string;
|
|
||||||
};
|
};
|
||||||
export interface QuestionVariantWithEditedImages extends QuestionVariant {
|
export interface QuestionVariantWithEditedImages extends QuestionVariant {
|
||||||
editedUrlImagesList?: EditedUrlImagesList | null;
|
editedUrlImagesList?: EditedUrlImagesList | null;
|
||||||
|
@ -42,8 +42,6 @@ export type FCField = {
|
|||||||
used: boolean;
|
used: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Status = "start" | "stop" | "ai";
|
|
||||||
|
|
||||||
export type QuizSettingsConfig = {
|
export type QuizSettingsConfig = {
|
||||||
fp: boolean;
|
fp: boolean;
|
||||||
rep: boolean;
|
rep: boolean;
|
||||||
@ -53,7 +51,7 @@ export type QuizSettingsConfig = {
|
|||||||
delay: number;
|
delay: number;
|
||||||
pausable: boolean;
|
pausable: boolean;
|
||||||
cfg: QuizConfig;
|
cfg: QuizConfig;
|
||||||
status: Status;
|
status: "start" | "stop" | "ai";
|
||||||
};
|
};
|
||||||
|
|
||||||
export type QuizSettings = {
|
export type QuizSettings = {
|
||||||
@ -119,7 +117,6 @@ export interface QuizConfig {
|
|||||||
showfc?: boolean;
|
showfc?: boolean;
|
||||||
yandexMetricsNumber?: number;
|
yandexMetricsNumber?: number;
|
||||||
vkMetricsNumber?: number;
|
vkMetricsNumber?: number;
|
||||||
backBlocked?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FormContactFieldName = "name" | "email" | "phone" | "text" | "address";
|
export type FormContactFieldName = "name" | "email" | "phone" | "text" | "address";
|
||||||
|
@ -30,13 +30,7 @@ interface QuizViewStore {
|
|||||||
interface QuizViewActions {
|
interface QuizViewActions {
|
||||||
updateAnswer: (questionId: string, answer: string | string[] | Moment, points: number) => void;
|
updateAnswer: (questionId: string, answer: string | string[] | Moment, points: number) => void;
|
||||||
deleteAnswer: (questionId: string) => void;
|
deleteAnswer: (questionId: string) => void;
|
||||||
updateOwnVariant: (
|
updateOwnVariant: (id: string, answer: string) => void;
|
||||||
id: string, //
|
|
||||||
answer: string | null, //
|
|
||||||
extendedText?: string, //
|
|
||||||
originalImageUrl?: string, //
|
|
||||||
localImageUrl?: string //
|
|
||||||
) => void;
|
|
||||||
deleteOwnVariant: (id: string) => void;
|
deleteOwnVariant: (id: string) => void;
|
||||||
setCurrentQuizStep: (step: QuizStep) => void;
|
setCurrentQuizStep: (step: QuizStep) => void;
|
||||||
}
|
}
|
||||||
@ -55,8 +49,8 @@ export const createQuizViewStore = () =>
|
|||||||
immer(
|
immer(
|
||||||
devtools(
|
devtools(
|
||||||
(set, get) => ({
|
(set, get) => ({
|
||||||
answers: [], //Массив вообще всех ответов. Объекты хранят инфо о id вопроса и списке выбранных ответов
|
answers: [],
|
||||||
ownVariants: [], //Подробное описание ответов для особенных. Здесь подробно расписана вся кастомизация ответов в own вариантах
|
ownVariants: [],
|
||||||
points: {},
|
points: {},
|
||||||
pointsSum: 0,
|
pointsSum: 0,
|
||||||
currentQuizStep: "startpage",
|
currentQuizStep: "startpage",
|
||||||
@ -96,11 +90,9 @@ export const createQuizViewStore = () =>
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
updateOwnVariant(id, answer, extendedText, originalImageUrl, localImageUrl) {
|
updateOwnVariant(id, answer) {
|
||||||
set(
|
set(
|
||||||
(state) => {
|
(state) => {
|
||||||
console.log("!!! STORE !!! ___ Случился вызов варианта свой ответ. Вот что я получил:");
|
|
||||||
console.log(id, answer, extendedText, originalImageUrl, localImageUrl);
|
|
||||||
const index = state.ownVariants.findIndex((variant) => variant.id === id);
|
const index = state.ownVariants.findIndex((variant) => variant.id === id);
|
||||||
|
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
@ -108,24 +100,14 @@ export const createQuizViewStore = () =>
|
|||||||
id,
|
id,
|
||||||
variant: {
|
variant: {
|
||||||
id: id,
|
id: id,
|
||||||
answer: answer === null ? state.ownVariants[index].variant.answer : answer,
|
answer,
|
||||||
extendedText: extendedText || "",
|
extendedText: "",
|
||||||
hints: "",
|
hints: "",
|
||||||
originalImageUrl: originalImageUrl || "",
|
originalImageUrl: "",
|
||||||
localImageUrl: localImageUrl || "",
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (answer !== null) state.ownVariants[index].variant.answer = answer;
|
state.ownVariants[index].variant.answer = answer;
|
||||||
if (extendedText !== undefined) {
|
|
||||||
state.ownVariants[index].variant.extendedText = extendedText;
|
|
||||||
}
|
|
||||||
if (originalImageUrl !== undefined) {
|
|
||||||
state.ownVariants[index].variant.originalImageUrl = originalImageUrl;
|
|
||||||
}
|
|
||||||
if (localImageUrl !== undefined) {
|
|
||||||
state.ownVariants[index].variant.localImageUrl = localImageUrl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
|
@ -7,8 +7,6 @@ export type QuizStore = QuizSettings & {
|
|||||||
quizId: string;
|
quizId: string;
|
||||||
preview: boolean;
|
preview: boolean;
|
||||||
changeFaviconAndTitle: boolean;
|
changeFaviconAndTitle: boolean;
|
||||||
quizStep: number;
|
|
||||||
nextLoading: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useQuizStore = create<QuizStore>(() => ({
|
export const useQuizStore = create<QuizStore>(() => ({
|
||||||
@ -20,25 +18,17 @@ export const useQuizStore = create<QuizStore>(() => ({
|
|||||||
cnt: 0,
|
cnt: 0,
|
||||||
recentlyCompleted: false,
|
recentlyCompleted: false,
|
||||||
show_badge: false,
|
show_badge: false,
|
||||||
quizStep: 0,
|
|
||||||
nextLoading: false,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const setQuizData = (data: QuizSettings) => {
|
export const setQuizData = (data: QuizSettings) => {
|
||||||
const currentState = useQuizStore.getState();
|
console.log("zusstand");
|
||||||
|
console.log(data);
|
||||||
useQuizStore.setState((state: QuizStore) => {
|
useQuizStore.setState((state: QuizStore) => ({ ...state, ...data }));
|
||||||
const newState = { ...state, ...data };
|
|
||||||
return newState;
|
|
||||||
});
|
|
||||||
|
|
||||||
const updatedState = useQuizStore.getState();
|
|
||||||
};
|
};
|
||||||
|
export const addQuestion = (newQuestion: AnyTypedQuizQuestion) =>
|
||||||
export const addQuestions = (newQuestions: AnyTypedQuizQuestion[]) =>
|
|
||||||
useQuizStore.setState(
|
useQuizStore.setState(
|
||||||
produce((state: QuizStore) => {
|
produce((state: QuizStore) => {
|
||||||
state.questions.push(...newQuestions);
|
state.questions.push(newQuestion);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
export const addquizid = (id: string) =>
|
export const addquizid = (id: string) =>
|
||||||
@ -47,29 +37,3 @@ export const addquizid = (id: string) =>
|
|||||||
state.quizId = id;
|
state.quizId = id;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
export const quizStepInc = () =>
|
|
||||||
useQuizStore.setState(
|
|
||||||
produce((state: QuizStore) => {
|
|
||||||
//Дополнительная проверка что мы не вышли за пределы массива вопросов
|
|
||||||
if (state.quizStep + 1 <= state.questions.length) {
|
|
||||||
state.quizStep += 1;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
export const quizStepDec = () =>
|
|
||||||
useQuizStore.setState(
|
|
||||||
produce((state: QuizStore) => {
|
|
||||||
//Дополнительная проверка что мы не вышли на менее чем 0 вопрос
|
|
||||||
if (state.quizStep > 0) {
|
|
||||||
state.quizStep--;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
export const changeNextLoading = (status: boolean) =>
|
|
||||||
useQuizStore.setState(
|
|
||||||
produce((state: QuizStore) => {
|
|
||||||
state.nextLoading = status;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
1
lib/ui_kit/neftyankacrutch.ts
Normal file
1
lib/ui_kit/neftyankacrutch.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export const isNeftyanka = window.location.pathname === "/cc006b40-ccbd-4600-a1d3-f902f85aa0a0";
|
@ -12,7 +12,6 @@ const isProduction = !(
|
|||||||
);
|
);
|
||||||
|
|
||||||
//туризм больше не в исключениях
|
//туризм больше не в исключениях
|
||||||
if (!isProduction) domain = "https://hbpn.link";
|
if (!isProduction) domain = "https://s.hbpn.link";
|
||||||
// domain = "https://hbpn.link";
|
|
||||||
|
|
||||||
export { domain, isProduction };
|
export { domain, isProduction };
|
||||||
|
80
lib/utils/fileUpload.ts
Normal file
80
lib/utils/fileUpload.ts
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
import { UploadFileType } from "@model/questionTypes/file";
|
||||||
|
import { sendAnswer, sendFile } from "@api/quizRelase";
|
||||||
|
import { ACCEPT_SEND_FILE_TYPES_MAP, MAX_FILE_SIZE } from "@/components/ViewPublicationPage/tools/fileUpload";
|
||||||
|
|
||||||
|
export interface UploadFileOptions {
|
||||||
|
file: File;
|
||||||
|
questionId: string;
|
||||||
|
quizId: string;
|
||||||
|
fileType: UploadFileType;
|
||||||
|
preview: boolean;
|
||||||
|
onSuccess?: (fileUrl: string) => void;
|
||||||
|
onError?: (error: Error) => void;
|
||||||
|
onProgress?: (progress: number) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UploadFileResult {
|
||||||
|
success: boolean;
|
||||||
|
fileUrl?: string;
|
||||||
|
error?: Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function uploadFile({
|
||||||
|
file,
|
||||||
|
questionId,
|
||||||
|
quizId,
|
||||||
|
fileType,
|
||||||
|
preview,
|
||||||
|
onSuccess,
|
||||||
|
onError,
|
||||||
|
onProgress,
|
||||||
|
}: UploadFileOptions): Promise<UploadFileResult> {
|
||||||
|
try {
|
||||||
|
// Проверка размера файла
|
||||||
|
if (file.size > MAX_FILE_SIZE) {
|
||||||
|
const error = new Error("File is too big. Maximum size is 50 MB");
|
||||||
|
onError?.(error);
|
||||||
|
return { success: false, error };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка типа файла
|
||||||
|
const isFileTypeAccepted = ACCEPT_SEND_FILE_TYPES_MAP[fileType].some((fileType) =>
|
||||||
|
file.name.toLowerCase().endsWith(fileType)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isFileTypeAccepted) {
|
||||||
|
const error = new Error("Incorrect file type selected");
|
||||||
|
onError?.(error);
|
||||||
|
return { success: false, error };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Загрузка файла
|
||||||
|
const data = await sendFile({
|
||||||
|
questionId,
|
||||||
|
body: {
|
||||||
|
file,
|
||||||
|
name: file.name,
|
||||||
|
preview,
|
||||||
|
},
|
||||||
|
qid: quizId,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Отправка ответа
|
||||||
|
await sendAnswer({
|
||||||
|
questionId,
|
||||||
|
body: `${data!.data.fileIDMap[questionId]}`,
|
||||||
|
qid: quizId,
|
||||||
|
preview,
|
||||||
|
});
|
||||||
|
|
||||||
|
const fileUrl = `${file.name}|${URL.createObjectURL(file)}`;
|
||||||
|
onSuccess?.(fileUrl);
|
||||||
|
onProgress?.(100);
|
||||||
|
|
||||||
|
return { success: true, fileUrl };
|
||||||
|
} catch (error) {
|
||||||
|
const err = error instanceof Error ? error : new Error("Unknown error occurred");
|
||||||
|
onError?.(err);
|
||||||
|
return { success: false, error: err };
|
||||||
|
}
|
||||||
|
}
|
@ -37,6 +37,6 @@ async function sendErrorsToServer() {
|
|||||||
// body: errorsQueue,
|
// body: errorsQueue,
|
||||||
// useToken: true,
|
// useToken: true,
|
||||||
// });
|
// });
|
||||||
console.info(`Fake-sending ${errorsQueue.length} errors to server`, errorsQueue);
|
console.log(`Fake-sending ${errorsQueue.length} errors to server`, errorsQueue);
|
||||||
errorsQueue = [];
|
errorsQueue = [];
|
||||||
}
|
}
|
||||||
|
@ -1,110 +0,0 @@
|
|||||||
import { useCallback, useDebugValue, useEffect, useMemo, useState } from "react";
|
|
||||||
import { enqueueSnackbar } from "notistack";
|
|
||||||
import moment from "moment";
|
|
||||||
|
|
||||||
import { isResultQuestionEmpty } from "@/components/ViewPublicationPage/tools/checkEmptyData";
|
|
||||||
import { changeNextLoading, quizStepDec, quizStepInc, useQuizStore } from "@/stores/useQuizStore";
|
|
||||||
|
|
||||||
import { useQuizViewStore } from "@stores/quizView";
|
|
||||||
|
|
||||||
import { useVkMetricsGoals } from "@/utils/hooks/metrics/useVkMetricsGoals";
|
|
||||||
import { useYandexMetricsGoals } from "@/utils/hooks/metrics/useYandexMetricsGoals";
|
|
||||||
|
|
||||||
export function useAIQuiz() {
|
|
||||||
//Получаем инфо о квизе и список вопросов.
|
|
||||||
const { settings, questions, quizId, cnt, quizStep } = useQuizStore();
|
|
||||||
|
|
||||||
//Список ответов на вопрос. Мы записываем ответы локально, параллельно отправляя на бек информацию о ответах
|
|
||||||
const answers = useQuizViewStore((state) => state.answers);
|
|
||||||
|
|
||||||
//Текущий шаг "startpage" | "question" | "contactform"
|
|
||||||
const setCurrentQuizStep = useQuizViewStore((state) => state.setCurrentQuizStep);
|
|
||||||
//Получение возможности управлять состоянием метрик
|
|
||||||
const vkMetrics = useVkMetricsGoals(settings.cfg.vkMetricsNumber);
|
|
||||||
const yandexMetrics = useYandexMetricsGoals(settings.cfg.yandexMetricsNumber);
|
|
||||||
|
|
||||||
const currentQuestion = useMemo(() => {
|
|
||||||
const calcQuestion = questions[quizStep];
|
|
||||||
if (calcQuestion) {
|
|
||||||
vkMetrics.questionPassed(calcQuestion.id);
|
|
||||||
yandexMetrics.questionPassed(calcQuestion.id);
|
|
||||||
|
|
||||||
return calcQuestion;
|
|
||||||
} else return questions[questions.length - 1];
|
|
||||||
}, [questions, quizStep]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (currentQuestion.type === "result") showResult();
|
|
||||||
if (currentQuestion) changeNextLoading(false);
|
|
||||||
}, [currentQuestion, questions]);
|
|
||||||
|
|
||||||
//Показать визуалом юзеру результат
|
|
||||||
const showResult = useCallback(() => {
|
|
||||||
if (currentQuestion?.type !== "result") throw new Error("Current question is not result");
|
|
||||||
|
|
||||||
//Смотрим по настройкам показывать ли вообще форму контактов. Показывать ли страницу результатов до или после формы контактов (ФК)
|
|
||||||
if (
|
|
||||||
settings.cfg.showfc !== false &&
|
|
||||||
(settings.cfg.resultInfo.showResultForm === "after" || isResultQuestionEmpty(currentQuestion))
|
|
||||||
)
|
|
||||||
setCurrentQuizStep("contactform");
|
|
||||||
}, [currentQuestion, setCurrentQuizStep, settings.cfg.resultInfo.showResultForm, settings.cfg.showfc]);
|
|
||||||
|
|
||||||
//рычаг управления из визуала в этот контроллер
|
|
||||||
|
|
||||||
const showResultAfterContactForm = useCallback(() => {
|
|
||||||
if (currentQuestion?.type !== "result") throw new Error("Current question is not result");
|
|
||||||
if (isResultQuestionEmpty(currentQuestion)) return;
|
|
||||||
|
|
||||||
setCurrentQuizStep("question");
|
|
||||||
}, [currentQuestion, setCurrentQuizStep]);
|
|
||||||
|
|
||||||
//рычаг управления из визуала в этот контроллер
|
|
||||||
const moveToPrevQuestion = useCallback(() => {
|
|
||||||
if (quizStep > 0 && !questions[quizStep - 1]) throw new Error("Previous question not found");
|
|
||||||
|
|
||||||
if (settings.status === "ai" && quizStep > 0) quizStepDec();
|
|
||||||
}, [quizStep]);
|
|
||||||
|
|
||||||
//рычаг управления из визуала в этот контроллер
|
|
||||||
const moveToNextQuestion = useCallback(async () => {
|
|
||||||
changeNextLoading(true);
|
|
||||||
quizStepInc();
|
|
||||||
}, [quizStep, changeNextLoading, quizStepInc]);
|
|
||||||
|
|
||||||
//рычаг управления из визуала в этот контроллер
|
|
||||||
const setQuestion = useCallback((_: string) => {}, []);
|
|
||||||
|
|
||||||
//Анализ дисаблить ли кнопки навигации
|
|
||||||
const isPreviousButtonEnabled = settings.cfg?.backBlocked ? false : quizStep > 0;
|
|
||||||
|
|
||||||
//Анализ дисаблить ли кнопки навигации
|
|
||||||
const isNextButtonEnabled = useMemo(() => {
|
|
||||||
const hasAnswer = answers.some(({ questionId }) => questionId === currentQuestion.id);
|
|
||||||
|
|
||||||
if ("required" in currentQuestion.content && currentQuestion.content.required) {
|
|
||||||
return hasAnswer;
|
|
||||||
}
|
|
||||||
|
|
||||||
return quizStep < cnt;
|
|
||||||
}, [answers, currentQuestion]);
|
|
||||||
|
|
||||||
useDebugValue({
|
|
||||||
CurrentQuestionIndex: quizStep,
|
|
||||||
currentQuestion: currentQuestion,
|
|
||||||
prevQuestion: questions[quizStep + 1],
|
|
||||||
nextQuestion: questions[quizStep - 1],
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
currentQuestion,
|
|
||||||
currentQuestionStepNumber: null,
|
|
||||||
nextQuestion: undefined,
|
|
||||||
isNextButtonEnabled,
|
|
||||||
isPreviousButtonEnabled,
|
|
||||||
moveToPrevQuestion,
|
|
||||||
moveToNextQuestion,
|
|
||||||
showResultAfterContactForm,
|
|
||||||
setQuestion,
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,257 +0,0 @@
|
|||||||
import { useCallback, useDebugValue, useEffect, useMemo, useState } from "react";
|
|
||||||
import { enqueueSnackbar } from "notistack";
|
|
||||||
import moment from "moment";
|
|
||||||
|
|
||||||
import { isResultQuestionEmpty } from "@/components/ViewPublicationPage/tools/checkEmptyData";
|
|
||||||
import { useQuizStore } from "@/stores/useQuizStore";
|
|
||||||
|
|
||||||
import { useQuizViewStore } from "@stores/quizView";
|
|
||||||
|
|
||||||
import { useVkMetricsGoals } from "@/utils/hooks/metrics/useVkMetricsGoals";
|
|
||||||
import { useYandexMetricsGoals } from "@/utils/hooks/metrics/useYandexMetricsGoals";
|
|
||||||
|
|
||||||
export function useBranchingQuiz() {
|
|
||||||
//Получаем инфо о квизе и список вопросов.
|
|
||||||
const { settings, questions, quizId, cnt } = useQuizStore();
|
|
||||||
|
|
||||||
//Когда квиз линейный, не ветвящийся, мы идём по вопросам по их порядковому номеру. Это их page.
|
|
||||||
//За корректность page отвечает конструктор квизов. Интересный факт, если в конструкторе удалить из середины вопрос, то случится куча запросов изменения вопросов с изменением этого page
|
|
||||||
const sortedQuestions = useMemo(() => {
|
|
||||||
return [...questions].sort((a, b) => a.page - b.page);
|
|
||||||
}, [questions]);
|
|
||||||
//React сам будет менять визуал - главное говорить из какого вопроса ему брать инфо. Изменение этой переменной меняет визуал.
|
|
||||||
const [currentQuestionId, setCurrentQuestionId] = useState<string | null>(getFirstQuestionId);
|
|
||||||
//Список ответов на вопрос. Мы записываем ответы локально, параллельно отправляя на бек информацию о ответах
|
|
||||||
const answers = useQuizViewStore((state) => state.answers);
|
|
||||||
//Список засчитанных баллов для балловых квизов
|
|
||||||
const pointsSum = useQuizViewStore((state) => state.pointsSum);
|
|
||||||
//Текущий шаг "startpage" | "question" | "contactform"
|
|
||||||
const setCurrentQuizStep = useQuizViewStore((state) => state.setCurrentQuizStep);
|
|
||||||
//Получение возможности управлять состоянием метрик
|
|
||||||
const vkMetrics = useVkMetricsGoals(settings.cfg.vkMetricsNumber);
|
|
||||||
const yandexMetrics = useYandexMetricsGoals(settings.cfg.yandexMetricsNumber);
|
|
||||||
|
|
||||||
//Изменение стейта (переменной currentQuestionId) ведёт к пересчёту что же за объект сейчас используется. Мы каждый раз просто ищем в списке
|
|
||||||
const currentQuestion = sortedQuestions.find((question) => question.id === currentQuestionId) ?? sortedQuestions[0];
|
|
||||||
|
|
||||||
//Индекс текущего вопроса только если квиз линейный
|
|
||||||
const linearQuestionIndex = //: number | null
|
|
||||||
currentQuestion && sortedQuestions.every(({ content }) => content.rule.parentId !== "root") // null when branching enabled
|
|
||||||
? sortedQuestions.indexOf(currentQuestion)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
//Индекс первого вопроса
|
|
||||||
function getFirstQuestionId() {
|
|
||||||
//: string | null
|
|
||||||
if (sortedQuestions.length === 0) return null; //Если нету сортированного списка, то и не рыпаемся
|
|
||||||
|
|
||||||
if (settings.cfg.haveRoot) {
|
|
||||||
// Если есть ветвление, то settings.cfg.haveRoot будет заполнен
|
|
||||||
//Если заполнен, то дерево растёт с root и это 1 вопрос :)
|
|
||||||
const nextQuestion = sortedQuestions.find(
|
|
||||||
//Функция ищет первое совпадение по массиву
|
|
||||||
(question) => question.id === settings.cfg.haveRoot || question.content.id === settings.cfg.haveRoot
|
|
||||||
);
|
|
||||||
if (!nextQuestion) return null;
|
|
||||||
|
|
||||||
return nextQuestion.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Если не возникло исключительных ситуаций - первый вопрос - нулевой элемент сортированного массива
|
|
||||||
return sortedQuestions[0].id;
|
|
||||||
}
|
|
||||||
|
|
||||||
const nextQuestionIdPointsLogic = useCallback(() => {
|
|
||||||
return sortedQuestions.find((question) => question.type === "result" && question.content.rule.parentId === "line");
|
|
||||||
}, [sortedQuestions]);
|
|
||||||
|
|
||||||
//Анализируем какой вопрос должен быть следующим. Это главная логика
|
|
||||||
const nextQuestionIdMainLogic = useCallback(() => {
|
|
||||||
//Список ответов данных этому вопросу. Вернёт QuestionAnswer | undefined
|
|
||||||
const questionAnswer = answers.find(({ questionId }) => questionId === currentQuestion.id);
|
|
||||||
|
|
||||||
//Если questionAnswer не undefined и ответ на вопрос не является временем:
|
|
||||||
if (questionAnswer && !moment.isMoment(questionAnswer.answer)) {
|
|
||||||
//Вопрос типизации. Получаем список строк ответов на этот вопрос
|
|
||||||
const userAnswers = Array.isArray(questionAnswer.answer) ? questionAnswer.answer : [questionAnswer.answer];
|
|
||||||
|
|
||||||
//цикл. Перебираем список условий .main и обзываем их переменной branchingRule
|
|
||||||
for (const branchingRule of currentQuestion.content.rule.main) {
|
|
||||||
// Перебираем список ответов. Если хоть один ответ из списка совпадает с прописанным правилом из условий - этот вопрос нужный нам. Его и дадимкак следующий
|
|
||||||
if (userAnswers.some((answer) => branchingRule.rules[0].answers.includes(answer))) {
|
|
||||||
return branchingRule.next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Не помню что это, но чёт при первом взгляде оно true только у результатов
|
|
||||||
if (!currentQuestion.required) {
|
|
||||||
//Готовим себе дефолтный путь
|
|
||||||
const defaultNextQuestionId = currentQuestion.content.rule.default;
|
|
||||||
|
|
||||||
//Если строка не пустая и не пробел. (Обычно при получении данных мы сразу чистим пустые строки только с пробелом на просто пустые строки. Это прост доп защита)
|
|
||||||
if (defaultNextQuestionId.length > 1 && defaultNextQuestionId !== " ") return defaultNextQuestionId;
|
|
||||||
//Вопросы типа страница, ползунок, своё поле для ввода и дата не могут иметь больше 1 ребёнка. Пользователь не может настроить там дефолт
|
|
||||||
//Кинуть на ребёнка надо даже если там нет дефолта
|
|
||||||
if (
|
|
||||||
["date", "page", "text", "number"].includes(currentQuestion.type) &&
|
|
||||||
currentQuestion.content.rule.children.length === 1
|
|
||||||
)
|
|
||||||
return currentQuestion.content.rule.children[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
//ничё не нашли, ищем резулт
|
|
||||||
return sortedQuestions.find((q) => {
|
|
||||||
return q.type === "result" && q.content.rule.parentId === currentQuestion.content.id;
|
|
||||||
})?.id;
|
|
||||||
}, [answers, currentQuestion, sortedQuestions]);
|
|
||||||
|
|
||||||
//Анализ следующего вопроса. Это логика для вопроса с баллами
|
|
||||||
const nextQuestionId = useMemo(() => {
|
|
||||||
if (settings.cfg.score) {
|
|
||||||
return nextQuestionIdPointsLogic();
|
|
||||||
}
|
|
||||||
return nextQuestionIdMainLogic();
|
|
||||||
}, [nextQuestionIdMainLogic, nextQuestionIdPointsLogic, settings.cfg.score, questions]);
|
|
||||||
|
|
||||||
//Поиск предыдущго вопроса либо по индексу либо по id родителя
|
|
||||||
const prevQuestion =
|
|
||||||
linearQuestionIndex !== null
|
|
||||||
? sortedQuestions[linearQuestionIndex - 1]
|
|
||||||
: sortedQuestions.find(
|
|
||||||
(q) =>
|
|
||||||
q.id === currentQuestion?.content.rule.parentId || q.content.id === currentQuestion?.content.rule.parentId
|
|
||||||
);
|
|
||||||
|
|
||||||
//Анализ результата по количеству баллов
|
|
||||||
const findResultPointsLogic = useCallback(() => {
|
|
||||||
//Отбираем из массива только тип резулт И результы с информацией о ожидаемых баллах И те результы, чьи суммы баллов меньше или равны насчитанным баллам юзера
|
|
||||||
|
|
||||||
const results = sortedQuestions.filter(
|
|
||||||
(e) => e.type === "result" && e.content.rule.minScore !== undefined && e.content.rule.minScore <= pointsSum
|
|
||||||
);
|
|
||||||
//Создаём массив строк из результатов. У кого есть инфо о баллах - дают свои, остальные 0
|
|
||||||
const numbers = results.map((e) =>
|
|
||||||
e.type === "result" && e.content.rule.minScore !== undefined ? e.content.rule.minScore : 0
|
|
||||||
);
|
|
||||||
//Извлекаем самое большое число
|
|
||||||
const indexOfNext = Math.max(...numbers);
|
|
||||||
//Отдаём индекс нужного нам результата
|
|
||||||
return results[numbers.indexOf(indexOfNext)];
|
|
||||||
}, [pointsSum, sortedQuestions]);
|
|
||||||
|
|
||||||
//Ищем следующий вопрос (не его индекс, или id). Сам вопрос
|
|
||||||
const nextQuestion = useMemo(() => {
|
|
||||||
let next;
|
|
||||||
|
|
||||||
if (settings.cfg.score) {
|
|
||||||
//Ессли квиз балловый
|
|
||||||
if (linearQuestionIndex !== null) {
|
|
||||||
next = sortedQuestions[linearQuestionIndex + 1]; //ищем по индексу
|
|
||||||
if (next?.type === "result" || next == undefined) next = findResultPointsLogic(); //если в поисках пришли к результату - считаем нужный
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//иначе
|
|
||||||
if (linearQuestionIndex !== null) {
|
|
||||||
//для линейных ищем по индексу
|
|
||||||
next =
|
|
||||||
sortedQuestions[linearQuestionIndex + 1] ??
|
|
||||||
sortedQuestions.find((question) => question.type === "result" && question.content.rule.parentId === "line");
|
|
||||||
} else {
|
|
||||||
// для нелинейных ищем по вычесленному id
|
|
||||||
next = sortedQuestions.find((q) => q.id === nextQuestionId || q.content.id === nextQuestionId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return next;
|
|
||||||
}, [nextQuestionId, findResultPointsLogic, linearQuestionIndex, sortedQuestions, settings.cfg.score]);
|
|
||||||
|
|
||||||
//Показать визуалом юзеру результат
|
|
||||||
const showResult = useCallback(() => {
|
|
||||||
if (nextQuestion?.type !== "result") throw new Error("Current question is not result");
|
|
||||||
|
|
||||||
//Записать в переменную ид текущего вопроса
|
|
||||||
setCurrentQuestionId(nextQuestion.id);
|
|
||||||
//Смотрим по настройкам показывать ли вообще форму контактов. Показывать ли страницу результатов до или после формы контактов (ФК)
|
|
||||||
if (
|
|
||||||
settings.cfg.showfc !== false &&
|
|
||||||
(settings.cfg.resultInfo.showResultForm === "after" || isResultQuestionEmpty(nextQuestion))
|
|
||||||
)
|
|
||||||
setCurrentQuizStep("contactform");
|
|
||||||
}, [nextQuestion, setCurrentQuizStep, settings.cfg.resultInfo.showResultForm, settings.cfg.showfc]);
|
|
||||||
|
|
||||||
//рычаг управления из визуала в этот контроллер
|
|
||||||
const showResultAfterContactForm = useCallback(() => {
|
|
||||||
if (currentQuestion?.type !== "result") throw new Error("Current question is not result");
|
|
||||||
if (isResultQuestionEmpty(currentQuestion)) return;
|
|
||||||
|
|
||||||
setCurrentQuizStep("question");
|
|
||||||
}, [currentQuestion, setCurrentQuizStep]);
|
|
||||||
|
|
||||||
//рычаг управления из визуала в этот контроллер
|
|
||||||
const moveToPrevQuestion = useCallback(() => {
|
|
||||||
if (!prevQuestion) throw new Error("Previous question not found");
|
|
||||||
|
|
||||||
setCurrentQuestionId(prevQuestion.id);
|
|
||||||
}, [prevQuestion]);
|
|
||||||
|
|
||||||
//рычаг управления из визуала в этот контроллер
|
|
||||||
const moveToNextQuestion = useCallback(async () => {
|
|
||||||
// Если есть следующий вопрос в уже загруженных - используем его
|
|
||||||
|
|
||||||
if (nextQuestion) {
|
|
||||||
vkMetrics.questionPassed(currentQuestion.id);
|
|
||||||
yandexMetrics.questionPassed(currentQuestion.id);
|
|
||||||
|
|
||||||
if (nextQuestion.type === "result") return showResult();
|
|
||||||
setCurrentQuestionId(nextQuestion.id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}, [currentQuestion.id, nextQuestion, showResult, vkMetrics, yandexMetrics, linearQuestionIndex, questions]);
|
|
||||||
|
|
||||||
//рычаг управления из визуала в этот контроллер
|
|
||||||
const setQuestion = useCallback(
|
|
||||||
(questionId: string) => {
|
|
||||||
const question = sortedQuestions.find((q) => q.id === questionId);
|
|
||||||
if (!question) return;
|
|
||||||
|
|
||||||
setCurrentQuestionId(question.id);
|
|
||||||
},
|
|
||||||
[sortedQuestions]
|
|
||||||
);
|
|
||||||
|
|
||||||
//Анализ дисаблить ли кнопки навигации
|
|
||||||
const isPreviousButtonEnabled = settings.cfg?.backBlocked ? false : Boolean(prevQuestion);
|
|
||||||
|
|
||||||
//Анализ дисаблить ли кнопки навигации
|
|
||||||
const isNextButtonEnabled = useMemo(() => {
|
|
||||||
const hasAnswer = answers.some(({ questionId }) => questionId === currentQuestion.id);
|
|
||||||
|
|
||||||
if ("required" in currentQuestion.content && currentQuestion.content.required) {
|
|
||||||
return hasAnswer;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (linearQuestionIndex !== null && questions.length < cnt) return true;
|
|
||||||
return Boolean(nextQuestion);
|
|
||||||
}, [answers, currentQuestion, nextQuestion]);
|
|
||||||
|
|
||||||
useDebugValue({
|
|
||||||
linearQuestionIndex,
|
|
||||||
currentQuestion: currentQuestion,
|
|
||||||
prevQuestion: prevQuestion,
|
|
||||||
nextQuestion: nextQuestion,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
currentQuestion,
|
|
||||||
currentQuestionStepNumber:
|
|
||||||
settings.status === "ai" ? null : linearQuestionIndex === null ? null : linearQuestionIndex + 1,
|
|
||||||
nextQuestion,
|
|
||||||
isNextButtonEnabled,
|
|
||||||
isPreviousButtonEnabled,
|
|
||||||
moveToPrevQuestion,
|
|
||||||
moveToNextQuestion,
|
|
||||||
showResultAfterContactForm,
|
|
||||||
setQuestion,
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,257 +0,0 @@
|
|||||||
import { useCallback, useDebugValue, useEffect, useMemo, useState } from "react";
|
|
||||||
import { enqueueSnackbar } from "notistack";
|
|
||||||
import moment from "moment";
|
|
||||||
|
|
||||||
import { isResultQuestionEmpty } from "@/components/ViewPublicationPage/tools/checkEmptyData";
|
|
||||||
import { useQuizStore } from "@/stores/useQuizStore";
|
|
||||||
|
|
||||||
import { useQuizViewStore } from "@stores/quizView";
|
|
||||||
|
|
||||||
import { useVkMetricsGoals } from "@/utils/hooks/metrics/useVkMetricsGoals";
|
|
||||||
import { useYandexMetricsGoals } from "@/utils/hooks/metrics/useYandexMetricsGoals";
|
|
||||||
|
|
||||||
export function useLinearQuiz() {
|
|
||||||
//Получаем инфо о квизе и список вопросов.
|
|
||||||
const { settings, questions, quizId, cnt } = useQuizStore();
|
|
||||||
|
|
||||||
//Когда квиз линейный, не ветвящийся, мы идём по вопросам по их порядковому номеру. Это их page.
|
|
||||||
//За корректность page отвечает конструктор квизов. Интересный факт, если в конструкторе удалить из середины вопрос, то случится куча запросов изменения вопросов с изменением этого page
|
|
||||||
const sortedQuestions = useMemo(() => {
|
|
||||||
return [...questions].sort((a, b) => a.page - b.page);
|
|
||||||
}, [questions]);
|
|
||||||
//React сам будет менять визуал - главное говорить из какого вопроса ему брать инфо. Изменение этой переменной меняет визуал.
|
|
||||||
const [currentQuestionId, setCurrentQuestionId] = useState<string | null>(getFirstQuestionId);
|
|
||||||
//Список ответов на вопрос. Мы записываем ответы локально, параллельно отправляя на бек информацию о ответах
|
|
||||||
const answers = useQuizViewStore((state) => state.answers);
|
|
||||||
//Список засчитанных баллов для балловых квизов
|
|
||||||
const pointsSum = useQuizViewStore((state) => state.pointsSum);
|
|
||||||
//Текущий шаг "startpage" | "question" | "contactform"
|
|
||||||
const setCurrentQuizStep = useQuizViewStore((state) => state.setCurrentQuizStep);
|
|
||||||
//Получение возможности управлять состоянием метрик
|
|
||||||
const vkMetrics = useVkMetricsGoals(settings.cfg.vkMetricsNumber);
|
|
||||||
const yandexMetrics = useYandexMetricsGoals(settings.cfg.yandexMetricsNumber);
|
|
||||||
|
|
||||||
//Изменение стейта (переменной currentQuestionId) ведёт к пересчёту что же за объект сейчас используется. Мы каждый раз просто ищем в списке
|
|
||||||
const currentQuestion = sortedQuestions.find((question) => question.id === currentQuestionId) ?? sortedQuestions[0];
|
|
||||||
|
|
||||||
//Индекс текущего вопроса только если квиз линейный
|
|
||||||
const linearQuestionIndex = //: number | null
|
|
||||||
currentQuestion && sortedQuestions.every(({ content }) => content.rule.parentId !== "root") // null when branching enabled
|
|
||||||
? sortedQuestions.indexOf(currentQuestion)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
//Индекс первого вопроса
|
|
||||||
function getFirstQuestionId() {
|
|
||||||
//: string | null
|
|
||||||
if (sortedQuestions.length === 0) return null; //Если нету сортированного списка, то и не рыпаемся
|
|
||||||
|
|
||||||
if (settings.cfg.haveRoot) {
|
|
||||||
// Если есть ветвление, то settings.cfg.haveRoot будет заполнен
|
|
||||||
//Если заполнен, то дерево растёт с root и это 1 вопрос :)
|
|
||||||
const nextQuestion = sortedQuestions.find(
|
|
||||||
//Функция ищет первое совпадение по массиву
|
|
||||||
(question) => question.id === settings.cfg.haveRoot || question.content.id === settings.cfg.haveRoot
|
|
||||||
);
|
|
||||||
if (!nextQuestion) return null;
|
|
||||||
|
|
||||||
return nextQuestion.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Если не возникло исключительных ситуаций - первый вопрос - нулевой элемент сортированного массива
|
|
||||||
return sortedQuestions[0].id;
|
|
||||||
}
|
|
||||||
|
|
||||||
const nextQuestionIdPointsLogic = useCallback(() => {
|
|
||||||
return sortedQuestions.find((question) => question.type === "result" && question.content.rule.parentId === "line");
|
|
||||||
}, [sortedQuestions]);
|
|
||||||
|
|
||||||
//Анализируем какой вопрос должен быть следующим. Это главная логика
|
|
||||||
const nextQuestionIdMainLogic = useCallback(() => {
|
|
||||||
//Список ответов данных этому вопросу. Вернёт QuestionAnswer | undefined
|
|
||||||
const questionAnswer = answers.find(({ questionId }) => questionId === currentQuestion.id);
|
|
||||||
|
|
||||||
//Если questionAnswer не undefined и ответ на вопрос не является временем:
|
|
||||||
if (questionAnswer && !moment.isMoment(questionAnswer.answer)) {
|
|
||||||
//Вопрос типизации. Получаем список строк ответов на этот вопрос
|
|
||||||
const userAnswers = Array.isArray(questionAnswer.answer) ? questionAnswer.answer : [questionAnswer.answer];
|
|
||||||
|
|
||||||
//цикл. Перебираем список условий .main и обзываем их переменной branchingRule
|
|
||||||
for (const branchingRule of currentQuestion.content.rule.main) {
|
|
||||||
// Перебираем список ответов. Если хоть один ответ из списка совпадает с прописанным правилом из условий - этот вопрос нужный нам. Его и дадимкак следующий
|
|
||||||
if (userAnswers.some((answer) => branchingRule.rules[0].answers.includes(answer))) {
|
|
||||||
return branchingRule.next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Не помню что это, но чёт при первом взгляде оно true только у результатов
|
|
||||||
if (!currentQuestion.required) {
|
|
||||||
//Готовим себе дефолтный путь
|
|
||||||
const defaultNextQuestionId = currentQuestion.content.rule.default;
|
|
||||||
|
|
||||||
//Если строка не пустая и не пробел. (Обычно при получении данных мы сразу чистим пустые строки только с пробелом на просто пустые строки. Это прост доп защита)
|
|
||||||
if (defaultNextQuestionId.length > 1 && defaultNextQuestionId !== " ") return defaultNextQuestionId;
|
|
||||||
//Вопросы типа страница, ползунок, своё поле для ввода и дата не могут иметь больше 1 ребёнка. Пользователь не может настроить там дефолт
|
|
||||||
//Кинуть на ребёнка надо даже если там нет дефолта
|
|
||||||
if (
|
|
||||||
["date", "page", "text", "number"].includes(currentQuestion.type) &&
|
|
||||||
currentQuestion.content.rule.children.length === 1
|
|
||||||
)
|
|
||||||
return currentQuestion.content.rule.children[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
//ничё не нашли, ищем резулт
|
|
||||||
return sortedQuestions.find((q) => {
|
|
||||||
return q.type === "result" && q.content.rule.parentId === currentQuestion.content.id;
|
|
||||||
})?.id;
|
|
||||||
}, [answers, currentQuestion, sortedQuestions]);
|
|
||||||
|
|
||||||
//Анализ следующего вопроса. Это логика для вопроса с баллами
|
|
||||||
const nextQuestionId = useMemo(() => {
|
|
||||||
if (settings.cfg.score) {
|
|
||||||
return nextQuestionIdPointsLogic();
|
|
||||||
}
|
|
||||||
return nextQuestionIdMainLogic();
|
|
||||||
}, [nextQuestionIdMainLogic, nextQuestionIdPointsLogic, settings.cfg.score, questions]);
|
|
||||||
|
|
||||||
//Поиск предыдущго вопроса либо по индексу либо по id родителя
|
|
||||||
const prevQuestion =
|
|
||||||
linearQuestionIndex !== null
|
|
||||||
? sortedQuestions[linearQuestionIndex - 1]
|
|
||||||
: sortedQuestions.find(
|
|
||||||
(q) =>
|
|
||||||
q.id === currentQuestion?.content.rule.parentId || q.content.id === currentQuestion?.content.rule.parentId
|
|
||||||
);
|
|
||||||
|
|
||||||
//Анализ результата по количеству баллов
|
|
||||||
const findResultPointsLogic = useCallback(() => {
|
|
||||||
//Отбираем из массива только тип резулт И результы с информацией о ожидаемых баллах И те результы, чьи суммы баллов меньше или равны насчитанным баллам юзера
|
|
||||||
|
|
||||||
const results = sortedQuestions.filter(
|
|
||||||
(e) => e.type === "result" && e.content.rule.minScore !== undefined && e.content.rule.minScore <= pointsSum
|
|
||||||
);
|
|
||||||
//Создаём массив строк из результатов. У кого есть инфо о баллах - дают свои, остальные 0
|
|
||||||
const numbers = results.map((e) =>
|
|
||||||
e.type === "result" && e.content.rule.minScore !== undefined ? e.content.rule.minScore : 0
|
|
||||||
);
|
|
||||||
//Извлекаем самое большое число
|
|
||||||
const indexOfNext = Math.max(...numbers);
|
|
||||||
//Отдаём индекс нужного нам результата
|
|
||||||
return results[numbers.indexOf(indexOfNext)];
|
|
||||||
}, [pointsSum, sortedQuestions]);
|
|
||||||
|
|
||||||
//Ищем следующий вопрос (не его индекс, или id). Сам вопрос
|
|
||||||
const nextQuestion = useMemo(() => {
|
|
||||||
let next;
|
|
||||||
|
|
||||||
if (settings.cfg.score) {
|
|
||||||
//Ессли квиз балловый
|
|
||||||
if (linearQuestionIndex !== null) {
|
|
||||||
next = sortedQuestions[linearQuestionIndex + 1]; //ищем по индексу
|
|
||||||
if (next?.type === "result" || next == undefined) next = findResultPointsLogic(); //если в поисках пришли к результату - считаем нужный
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//иначе
|
|
||||||
if (linearQuestionIndex !== null) {
|
|
||||||
//для линейных ищем по индексу
|
|
||||||
next =
|
|
||||||
sortedQuestions[linearQuestionIndex + 1] ??
|
|
||||||
sortedQuestions.find((question) => question.type === "result" && question.content.rule.parentId === "line");
|
|
||||||
} else {
|
|
||||||
// для нелинейных ищем по вычесленному id
|
|
||||||
next = sortedQuestions.find((q) => q.id === nextQuestionId || q.content.id === nextQuestionId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return next;
|
|
||||||
}, [nextQuestionId, findResultPointsLogic, linearQuestionIndex, sortedQuestions, settings.cfg.score]);
|
|
||||||
|
|
||||||
//Показать визуалом юзеру результат
|
|
||||||
const showResult = useCallback(() => {
|
|
||||||
if (nextQuestion?.type !== "result") throw new Error("Current question is not result");
|
|
||||||
|
|
||||||
//Записать в переменную ид текущего вопроса
|
|
||||||
setCurrentQuestionId(nextQuestion.id);
|
|
||||||
//Смотрим по настройкам показывать ли вообще форму контактов. Показывать ли страницу результатов до или после формы контактов (ФК)
|
|
||||||
if (
|
|
||||||
settings.cfg.showfc !== false &&
|
|
||||||
(settings.cfg.resultInfo.showResultForm === "after" || isResultQuestionEmpty(nextQuestion))
|
|
||||||
)
|
|
||||||
setCurrentQuizStep("contactform");
|
|
||||||
}, [nextQuestion, setCurrentQuizStep, settings.cfg.resultInfo.showResultForm, settings.cfg.showfc]);
|
|
||||||
|
|
||||||
//рычаг управления из визуала в этот контроллер
|
|
||||||
const showResultAfterContactForm = useCallback(() => {
|
|
||||||
if (currentQuestion?.type !== "result") throw new Error("Current question is not result");
|
|
||||||
if (isResultQuestionEmpty(currentQuestion)) return;
|
|
||||||
|
|
||||||
setCurrentQuizStep("question");
|
|
||||||
}, [currentQuestion, setCurrentQuizStep]);
|
|
||||||
|
|
||||||
//рычаг управления из визуала в этот контроллер
|
|
||||||
const moveToPrevQuestion = useCallback(() => {
|
|
||||||
if (!prevQuestion) throw new Error("Previous question not found");
|
|
||||||
|
|
||||||
setCurrentQuestionId(prevQuestion.id);
|
|
||||||
}, [prevQuestion]);
|
|
||||||
|
|
||||||
//рычаг управления из визуала в этот контроллер
|
|
||||||
const moveToNextQuestion = useCallback(async () => {
|
|
||||||
// Если есть следующий вопрос в уже загруженных - используем его
|
|
||||||
|
|
||||||
if (nextQuestion) {
|
|
||||||
vkMetrics.questionPassed(currentQuestion.id);
|
|
||||||
yandexMetrics.questionPassed(currentQuestion.id);
|
|
||||||
|
|
||||||
if (nextQuestion.type === "result") return showResult();
|
|
||||||
setCurrentQuestionId(nextQuestion.id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}, [currentQuestion.id, nextQuestion, showResult, vkMetrics, yandexMetrics, linearQuestionIndex, questions]);
|
|
||||||
|
|
||||||
//рычаг управления из визуала в этот контроллер
|
|
||||||
const setQuestion = useCallback(
|
|
||||||
(questionId: string) => {
|
|
||||||
const question = sortedQuestions.find((q) => q.id === questionId);
|
|
||||||
if (!question) return;
|
|
||||||
|
|
||||||
setCurrentQuestionId(question.id);
|
|
||||||
},
|
|
||||||
[sortedQuestions]
|
|
||||||
);
|
|
||||||
|
|
||||||
//Анализ дисаблить ли кнопки навигации
|
|
||||||
const isPreviousButtonEnabled = settings.cfg?.backBlocked ? false : Boolean(prevQuestion);
|
|
||||||
|
|
||||||
//Анализ дисаблить ли кнопки навигации
|
|
||||||
const isNextButtonEnabled = useMemo(() => {
|
|
||||||
const hasAnswer = answers.some(({ questionId }) => questionId === currentQuestion.id);
|
|
||||||
|
|
||||||
if ("required" in currentQuestion.content && currentQuestion.content.required) {
|
|
||||||
return hasAnswer;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (linearQuestionIndex !== null && questions.length < cnt) return true;
|
|
||||||
return Boolean(nextQuestion);
|
|
||||||
}, [answers, currentQuestion, nextQuestion]);
|
|
||||||
|
|
||||||
useDebugValue({
|
|
||||||
linearQuestionIndex,
|
|
||||||
currentQuestion: currentQuestion,
|
|
||||||
prevQuestion: prevQuestion,
|
|
||||||
nextQuestion: nextQuestion,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
currentQuestion,
|
|
||||||
currentQuestionStepNumber:
|
|
||||||
settings.status === "ai" ? null : linearQuestionIndex === null ? null : linearQuestionIndex + 1,
|
|
||||||
nextQuestion,
|
|
||||||
isNextButtonEnabled,
|
|
||||||
isPreviousButtonEnabled,
|
|
||||||
moveToPrevQuestion,
|
|
||||||
moveToNextQuestion,
|
|
||||||
showResultAfterContactForm,
|
|
||||||
setQuestion,
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,50 +1,310 @@
|
|||||||
import { useBranchingQuiz } from "./FlowControlLogic/useBranchingQuiz";
|
import { useCallback, useDebugValue, useEffect, useMemo, useState } from "react";
|
||||||
import { useLinearQuiz } from "./FlowControlLogic/useLinearQuiz";
|
import { enqueueSnackbar } from "notistack";
|
||||||
import { useAIQuiz } from "./FlowControlLogic/useAIQuiz";
|
import moment from "moment";
|
||||||
import { Status } from "@/model/settingsData";
|
|
||||||
|
|
||||||
interface StatusData {
|
import { isResultQuestionEmpty } from "@/components/ViewPublicationPage/tools/checkEmptyData";
|
||||||
status: Status;
|
import { useQuizStore } from "@/stores/useQuizStore";
|
||||||
haveRoot: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// выбор способа управления в зависимости от статуса
|
import { useQuizViewStore } from "@stores/quizView";
|
||||||
let cachedManager: () => ReturnType<typeof useLinearQuiz>;
|
|
||||||
export let statusOfQuiz: "line" | "branch" | "ai";
|
|
||||||
|
|
||||||
function analyicStatus({ status, haveRoot }: StatusData) {
|
import { useVkMetricsGoals } from "@/utils/hooks/metrics/useVkMetricsGoals";
|
||||||
if (status === "ai") {
|
import { useYandexMetricsGoals } from "@/utils/hooks/metrics/useYandexMetricsGoals";
|
||||||
statusOfQuiz = "ai";
|
import { AnyTypedQuizQuestion } from "@/index";
|
||||||
return;
|
import { getQuizData } from "@/api/quizRelase";
|
||||||
}
|
import { useQuizGetNext } from "@/api/useQuizGetNext";
|
||||||
if (status === "start") {
|
|
||||||
|
let isgetting = false;
|
||||||
|
|
||||||
|
export function useQuestionFlowControl() {
|
||||||
|
//Получаем инфо о квизе и список вопросов.
|
||||||
|
const { loadMoreQuestions } = useQuizGetNext();
|
||||||
|
const { settings, questions, quizId, cnt } = useQuizStore();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log("useQuestionFlowControl useEffect");
|
||||||
|
console.log(questions);
|
||||||
|
}, [questions]);
|
||||||
|
console.log(questions);
|
||||||
|
|
||||||
|
//Когда квиз линейный, не ветвящийся, мы идём по вопросам по их порядковому номеру. Это их page.
|
||||||
|
//За корректность page отвечает конструктор квизов. Интересный факт, если в конструкторе удалить из середины вопрос, то случится куча запросов изменения вопросов с изменением этого page
|
||||||
|
const sortedQuestions = useMemo(() => {
|
||||||
|
return [...questions].sort((a, b) => a.page - b.page);
|
||||||
|
}, [questions]);
|
||||||
|
//React сам будет менять визуал - главное говорить из какого вопроса ему брать инфо. Изменение этой переменной меняет визуал.
|
||||||
|
const [currentQuestionId, setCurrentQuestionId] = useState<string | null>(getFirstQuestionId);
|
||||||
|
const [headAI, setHeadAI] = useState(0);
|
||||||
|
//Список ответов на вопрос. Мы записываем ответы локально, параллельно отправляя на бек информацию о ответах
|
||||||
|
const answers = useQuizViewStore((state) => state.answers);
|
||||||
|
//Список засчитанных баллов для балловых квизов
|
||||||
|
const pointsSum = useQuizViewStore((state) => state.pointsSum);
|
||||||
|
//Текущий шаг "startpage" | "question" | "contactform"
|
||||||
|
const setCurrentQuizStep = useQuizViewStore((state) => state.setCurrentQuizStep);
|
||||||
|
//Получение возможности управлять состоянием метрик
|
||||||
|
const vkMetrics = useVkMetricsGoals(settings.cfg.vkMetricsNumber);
|
||||||
|
const yandexMetrics = useYandexMetricsGoals(settings.cfg.yandexMetricsNumber);
|
||||||
|
|
||||||
|
//Изменение стейта (переменной currentQuestionId) ведёт к пересчёту что же за объект сейчас используется. Мы каждый раз просто ищем в списке
|
||||||
|
const currentQuestion = sortedQuestions.find((question) => question.id === currentQuestionId) ?? sortedQuestions[0];
|
||||||
|
|
||||||
|
console.log("currentQuestion");
|
||||||
|
console.log(currentQuestion);
|
||||||
|
console.log("filted");
|
||||||
|
console.log(sortedQuestions.find((question) => question.id === currentQuestionId));
|
||||||
|
|
||||||
|
//Индекс текущего вопроса только если квиз линейный
|
||||||
|
const linearQuestionIndex = //: number | null
|
||||||
|
currentQuestion && sortedQuestions.every(({ content }) => content.rule.parentId !== "root") // null when branching enabled
|
||||||
|
? sortedQuestions.indexOf(currentQuestion)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
//Индекс первого вопроса
|
||||||
|
function getFirstQuestionId() {
|
||||||
|
//: string | null
|
||||||
|
if (sortedQuestions.length === 0) return null; //Если нету сортированного списка, то и не рыпаемся
|
||||||
|
|
||||||
|
if (settings.cfg.haveRoot) {
|
||||||
// Если есть ветвление, то settings.cfg.haveRoot будет заполнен
|
// Если есть ветвление, то settings.cfg.haveRoot будет заполнен
|
||||||
if (haveRoot) statusOfQuiz = "branch";
|
//Если заполнен, то дерево растёт с root и это 1 вопрос :)
|
||||||
else statusOfQuiz = "line";
|
const nextQuestion = sortedQuestions.find(
|
||||||
|
//Функция ищет первое совпадение по массиву
|
||||||
|
(question) => question.id === settings.cfg.haveRoot || question.content.id === settings.cfg.haveRoot
|
||||||
|
);
|
||||||
|
if (!nextQuestion) return null;
|
||||||
|
|
||||||
|
return nextQuestion.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Если не возникло исключительных ситуаций - первый вопрос - нулевой элемент сортированного массива
|
||||||
|
return sortedQuestions[0].id;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextQuestionIdPointsLogic = useCallback(() => {
|
||||||
|
return sortedQuestions.find((question) => question.type === "result" && question.content.rule.parentId === "line");
|
||||||
|
}, [sortedQuestions]);
|
||||||
|
|
||||||
|
//Анализируем какой вопрос должен быть следующим. Это главная логика
|
||||||
|
const nextQuestionIdMainLogic = useCallback(() => {
|
||||||
|
//Список ответов данных этому вопросу. Вернёт QuestionAnswer | undefined
|
||||||
|
const questionAnswer = answers.find(({ questionId }) => questionId === currentQuestion.id);
|
||||||
|
|
||||||
|
//Если questionAnswer не undefined и ответ на вопрос не является временем:
|
||||||
|
if (questionAnswer && !moment.isMoment(questionAnswer.answer)) {
|
||||||
|
//Вопрос типизации. Получаем список строк ответов на этот вопрос
|
||||||
|
const userAnswers = Array.isArray(questionAnswer.answer) ? questionAnswer.answer : [questionAnswer.answer];
|
||||||
|
|
||||||
|
//цикл. Перебираем список условий .main и обзываем их переменной branchingRule
|
||||||
|
for (const branchingRule of currentQuestion.content.rule.main) {
|
||||||
|
// Перебираем список ответов. Если хоть один ответ из списка совпадает с прописанным правилом из условий - этот вопрос нужный нам. Его и дадимкак следующий
|
||||||
|
if (userAnswers.some((answer) => branchingRule.rules[0].answers.includes(answer))) {
|
||||||
|
return branchingRule.next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Не помню что это, но чёт при первом взгляде оно true только у результатов
|
||||||
|
if (!currentQuestion.required) {
|
||||||
|
//Готовим себе дефолтный путь
|
||||||
|
const defaultNextQuestionId = currentQuestion.content.rule.default;
|
||||||
|
|
||||||
|
//Если строка не пустая и не пробел. (Обычно при получении данных мы сразу чистим пустые строки только с пробелом на просто пустые строки. Это прост доп защита)
|
||||||
|
if (defaultNextQuestionId.length > 1 && defaultNextQuestionId !== " ") return defaultNextQuestionId;
|
||||||
|
//Вопросы типа страница, ползунок, своё поле для ввода и дата не могут иметь больше 1 ребёнка. Пользователь не может настроить там дефолт
|
||||||
|
//Кинуть на ребёнка надо даже если там нет дефолта
|
||||||
|
if (
|
||||||
|
["date", "page", "text", "number"].includes(currentQuestion.type) &&
|
||||||
|
currentQuestion.content.rule.children.length === 1
|
||||||
|
)
|
||||||
|
return currentQuestion.content.rule.children[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
//ничё не нашли, ищем резулт
|
||||||
|
return sortedQuestions.find((q) => {
|
||||||
|
return q.type === "result" && q.content.rule.parentId === currentQuestion.content.id;
|
||||||
|
})?.id;
|
||||||
|
}, [answers, currentQuestion, sortedQuestions]);
|
||||||
|
|
||||||
|
//Анализ следующего вопроса. Это логика для вопроса с баллами
|
||||||
|
const nextQuestionId = useMemo(() => {
|
||||||
|
if (settings.cfg.score) {
|
||||||
|
return nextQuestionIdPointsLogic();
|
||||||
|
}
|
||||||
|
return nextQuestionIdMainLogic();
|
||||||
|
}, [nextQuestionIdMainLogic, nextQuestionIdPointsLogic, settings.cfg.score, questions]);
|
||||||
|
|
||||||
|
//Поиск предыдущго вопроса либо по индексу либо по id родителя
|
||||||
|
const prevQuestion =
|
||||||
|
linearQuestionIndex !== null
|
||||||
|
? sortedQuestions[linearQuestionIndex - 1]
|
||||||
|
: sortedQuestions.find(
|
||||||
|
(q) =>
|
||||||
|
q.id === currentQuestion?.content.rule.parentId || q.content.id === currentQuestion?.content.rule.parentId
|
||||||
|
);
|
||||||
|
|
||||||
|
//Анализ результата по количеству баллов
|
||||||
|
const findResultPointsLogic = useCallback(() => {
|
||||||
|
//Отбираем из массива только тип резулт И результы с информацией о ожидаемых баллах И те результы, чьи суммы баллов меньше или равны насчитанным баллам юзера
|
||||||
|
|
||||||
|
const results = sortedQuestions.filter(
|
||||||
|
(e) => e.type === "result" && e.content.rule.minScore !== undefined && e.content.rule.minScore <= pointsSum
|
||||||
|
);
|
||||||
|
//Создаём массив строк из результатов. У кого есть инфо о баллах - дают свои, остальные 0
|
||||||
|
const numbers = results.map((e) =>
|
||||||
|
e.type === "result" && e.content.rule.minScore !== undefined ? e.content.rule.minScore : 0
|
||||||
|
);
|
||||||
|
//Извлекаем самое большое число
|
||||||
|
const indexOfNext = Math.max(...numbers);
|
||||||
|
//Отдаём индекс нужного нам результата
|
||||||
|
return results[numbers.indexOf(indexOfNext)];
|
||||||
|
}, [pointsSum, sortedQuestions]);
|
||||||
|
|
||||||
|
//Ищем следующий вопрос (не его индекс, или id). Сам вопрос
|
||||||
|
const nextQuestion = useMemo(() => {
|
||||||
|
let next;
|
||||||
|
|
||||||
|
if (settings.cfg.score) {
|
||||||
|
//Ессли квиз балловый
|
||||||
|
if (linearQuestionIndex !== null) {
|
||||||
|
next = sortedQuestions[linearQuestionIndex + 1]; //ищем по индексу
|
||||||
|
if (next?.type === "result" || next == undefined) next = findResultPointsLogic(); //если в поисках пришли к результату - считаем нужный
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//иначе
|
||||||
|
if (linearQuestionIndex !== null) {
|
||||||
|
//для линейных ищем по индексу
|
||||||
|
next =
|
||||||
|
sortedQuestions[linearQuestionIndex + 1] ??
|
||||||
|
sortedQuestions.find((question) => question.type === "result" && question.content.rule.parentId === "line");
|
||||||
|
} else {
|
||||||
|
// для нелинейных ищем по вычесленному id
|
||||||
|
next = sortedQuestions.find((q) => q.id === nextQuestionId || q.content.id === nextQuestionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return next;
|
||||||
|
}, [nextQuestionId, findResultPointsLogic, linearQuestionIndex, sortedQuestions, settings.cfg.score]);
|
||||||
|
|
||||||
|
//Показать визуалом юзеру результат
|
||||||
|
const showResult = useCallback(() => {
|
||||||
|
if (nextQuestion?.type !== "result") throw new Error("Current question is not result");
|
||||||
|
|
||||||
|
//Записать в переменную ид текущего вопроса
|
||||||
|
setCurrentQuestionId(nextQuestion.id);
|
||||||
|
//Смотрим по настройкам показывать ли вообще форму контактов. Показывать ли страницу результатов до или после формы контактов (ФК)
|
||||||
|
if (
|
||||||
|
settings.cfg.showfc !== false &&
|
||||||
|
(settings.cfg.resultInfo.showResultForm === "after" || isResultQuestionEmpty(nextQuestion))
|
||||||
|
)
|
||||||
|
setCurrentQuizStep("contactform");
|
||||||
|
}, [nextQuestion, setCurrentQuizStep, settings.cfg.resultInfo.showResultForm, settings.cfg.showfc]);
|
||||||
|
|
||||||
|
//рычаг управления из визуала в эту функцию
|
||||||
|
const showResultAfterContactForm = useCallback(() => {
|
||||||
|
if (currentQuestion?.type !== "result") throw new Error("Current question is not result");
|
||||||
|
if (isResultQuestionEmpty(currentQuestion)) {
|
||||||
|
enqueueSnackbar("Данные отправлены");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new Error("quiz is inactive");
|
|
||||||
|
setCurrentQuizStep("question");
|
||||||
|
}, [currentQuestion, setCurrentQuizStep]);
|
||||||
|
|
||||||
|
//рычаг управления из визуала в эту функцию
|
||||||
|
const moveToPrevQuestion = useCallback(() => {
|
||||||
|
if (!prevQuestion) throw new Error("Previous question not found");
|
||||||
|
|
||||||
|
if (settings.status === "ai" && headAI > 0) setHeadAI((old) => old--);
|
||||||
|
setCurrentQuestionId(prevQuestion.id);
|
||||||
|
}, [prevQuestion]);
|
||||||
|
|
||||||
|
//рычаг управления из визуала в эту функцию
|
||||||
|
const moveToNextQuestion = useCallback(async () => {
|
||||||
|
// Если есть следующий вопрос в уже загруженных - используем его
|
||||||
|
|
||||||
|
if (nextQuestion) {
|
||||||
|
vkMetrics.questionPassed(currentQuestion.id);
|
||||||
|
yandexMetrics.questionPassed(currentQuestion.id);
|
||||||
|
|
||||||
|
if (nextQuestion.type === "result") return showResult();
|
||||||
|
setCurrentQuestionId(nextQuestion.id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Если следующего нет - загружаем новый
|
||||||
|
try {
|
||||||
|
const newQuestion = await loadMoreQuestions();
|
||||||
|
console.log("Ффункция некст вопрос получила его с бека: ");
|
||||||
|
console.log(newQuestion);
|
||||||
|
if (newQuestion) {
|
||||||
|
vkMetrics.questionPassed(currentQuestion.id);
|
||||||
|
yandexMetrics.questionPassed(currentQuestion.id);
|
||||||
|
console.log("МЫ ПАЛУЧИЛИ НОВЫЙ ВОПРОС");
|
||||||
|
console.log(newQuestion);
|
||||||
|
console.log("typeof newQuestion.id");
|
||||||
|
console.log(typeof newQuestion.id);
|
||||||
|
setCurrentQuestionId(newQuestion.id);
|
||||||
|
setHeadAI((old) => old++);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
enqueueSnackbar("Ошибка загрузки следующего вопроса");
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
currentQuestion.id,
|
||||||
|
nextQuestion,
|
||||||
|
showResult,
|
||||||
|
vkMetrics,
|
||||||
|
yandexMetrics,
|
||||||
|
linearQuestionIndex,
|
||||||
|
loadMoreQuestions,
|
||||||
|
questions,
|
||||||
|
]);
|
||||||
|
|
||||||
|
//рычаг управления из визуала в эту функцию
|
||||||
|
const setQuestion = useCallback(
|
||||||
|
(questionId: string) => {
|
||||||
|
const question = sortedQuestions.find((q) => q.id === questionId);
|
||||||
|
if (!question) return;
|
||||||
|
|
||||||
|
setCurrentQuestionId(question.id);
|
||||||
|
},
|
||||||
|
[sortedQuestions]
|
||||||
|
);
|
||||||
|
|
||||||
|
//Анализ дисаблить ли кнопки навигации
|
||||||
|
const isPreviousButtonEnabled = Boolean(prevQuestion);
|
||||||
|
|
||||||
|
//Анализ дисаблить ли кнопки навигации
|
||||||
|
const isNextButtonEnabled = useMemo(() => {
|
||||||
|
const hasAnswer = answers.some(({ questionId }) => questionId === currentQuestion.id);
|
||||||
|
|
||||||
|
if ("required" in currentQuestion.content && currentQuestion.content.required) {
|
||||||
|
return hasAnswer;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(linearQuestionIndex);
|
||||||
|
console.log(questions.length);
|
||||||
|
console.log(cnt);
|
||||||
|
if (linearQuestionIndex !== null && questions.length < cnt) return true;
|
||||||
|
return Boolean(nextQuestion);
|
||||||
|
}, [answers, currentQuestion, nextQuestion]);
|
||||||
|
|
||||||
|
useDebugValue({
|
||||||
|
linearQuestionIndex,
|
||||||
|
currentQuestion: currentQuestion,
|
||||||
|
prevQuestion: prevQuestion,
|
||||||
|
nextQuestion: nextQuestion,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
currentQuestion,
|
||||||
|
currentQuestionStepNumber:
|
||||||
|
settings.status === "ai" ? null : linearQuestionIndex === null ? null : linearQuestionIndex + 1,
|
||||||
|
nextQuestion,
|
||||||
|
isNextButtonEnabled,
|
||||||
|
isPreviousButtonEnabled,
|
||||||
|
moveToPrevQuestion,
|
||||||
|
moveToNextQuestion,
|
||||||
|
showResultAfterContactForm,
|
||||||
|
setQuestion,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const initDataManager = (data: StatusData) => {
|
|
||||||
analyicStatus(data);
|
|
||||||
switch (statusOfQuiz) {
|
|
||||||
case "line":
|
|
||||||
cachedManager = useLinearQuiz;
|
|
||||||
break;
|
|
||||||
case "branch":
|
|
||||||
cachedManager = useBranchingQuiz;
|
|
||||||
break;
|
|
||||||
case "ai":
|
|
||||||
cachedManager = useAIQuiz;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Главный хук (интерфейс для потребителей)
|
|
||||||
export const useQuestionFlowControl = () => {
|
|
||||||
if (!cachedManager) {
|
|
||||||
throw new Error("DataManager not initialized! Call initDataManager() first.");
|
|
||||||
}
|
|
||||||
return cachedManager();
|
|
||||||
};
|
|
||||||
|
@ -50,17 +50,25 @@ export async function sendQuestionAnswer(
|
|||||||
}
|
}
|
||||||
case "emoji": {
|
case "emoji": {
|
||||||
if (question.content.multi) {
|
if (question.content.multi) {
|
||||||
const answer = questionAnswer.answer as string[];
|
const answer = questionAnswer.answer;
|
||||||
let answerString = ``;
|
const ownVariant = Array.isArray(answer)
|
||||||
|
? ownVariants[ownVariants.findIndex((variant) => answer.some((a: string) => a === variant.id))]?.variant || ""
|
||||||
|
: ownVariants[ownVariants.findIndex((variant) => variant.id === questionAnswer.answer)]?.variant || "";
|
||||||
|
|
||||||
|
if (moment.isMoment(answer)) throw new Error("Answer is Moment in Variant question");
|
||||||
|
|
||||||
|
//Оставляем только выбранные варианты
|
||||||
const selectedVariants = question.content.variants.filter((v) => answer.includes(v.id));
|
const selectedVariants = question.content.variants.filter((v) => answer.includes(v.id));
|
||||||
|
|
||||||
selectedVariants.forEach((variant) => {
|
let answerString = ``;
|
||||||
const ownVariantData = ownVariants.find((v) => v.id === variant.id)?.variant;
|
selectedVariants.forEach((e) => {
|
||||||
const customEmoji = ownVariantData?.extendedText || "";
|
if (e.isOwn) {
|
||||||
const emojiToSend = customEmoji || variant.extendedText;
|
if (question.content.own && selectedVariants.some((v) => v.isOwn)) {
|
||||||
const textToSend = variant.isOwn ? ownVariantData?.answer || "" : variant.answer;
|
answerString += `\`${e.extendedText} ${ownVariant?.answer ?? ""}\`,`;
|
||||||
answerString += `\`${emojiToSend} ${textToSend}\`,`;
|
}
|
||||||
|
} else {
|
||||||
|
answerString += `\`${e.extendedText} ${e.answer ?? ""}\`,`;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
answerString = answerString.slice(0, -1);
|
answerString = answerString.slice(0, -1);
|
||||||
@ -72,27 +80,12 @@ export async function sendQuestionAnswer(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback for old string format for single choice
|
const variant = question.content.variants.find((v) => v.id === questionAnswer.answer);
|
||||||
const answer = questionAnswer.answer as string;
|
if (!variant) throw new Error(`Cannot find variant with id ${questionAnswer.answer} in question ${question.id}`);
|
||||||
const variant = question.content.variants.find((v) => v.id === answer);
|
|
||||||
if (!variant) {
|
|
||||||
// This can happen if the answer is not set, so we don't throw an error, just send empty
|
|
||||||
return sendAnswer({
|
|
||||||
questionId: question.id,
|
|
||||||
body: "",
|
|
||||||
qid: quizId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const ownVariantData = ownVariants.find((v) => v.id === variant.id)?.variant;
|
|
||||||
const customEmoji = ownVariantData?.extendedText || "";
|
|
||||||
const emojiToSend = customEmoji || variant.extendedText;
|
|
||||||
const textToSend = variant.isOwn ? ownVariantData?.answer || "" : variant.answer;
|
|
||||||
const body = `${emojiToSend} ${textToSend}`.trim();
|
|
||||||
|
|
||||||
return sendAnswer({
|
return sendAnswer({
|
||||||
questionId: question.id,
|
questionId: question.id,
|
||||||
body: body,
|
body: variant.extendedText + " " + variant.answer,
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -100,9 +93,7 @@ export async function sendQuestionAnswer(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case "images": {
|
case "images": {
|
||||||
console.log("Работает отправщик ответа для типа КАРТИНКИ");
|
|
||||||
if (question.content.multi) {
|
if (question.content.multi) {
|
||||||
console.log("Этот вопрос есть МУЛЬТИ");
|
|
||||||
const answer = questionAnswer.answer;
|
const answer = questionAnswer.answer;
|
||||||
const ownAnswer = Array.isArray(answer)
|
const ownAnswer = Array.isArray(answer)
|
||||||
? ownVariants[ownVariants.findIndex((variant) => answer.some((a: string) => a === variant.id))]?.variant
|
? ownVariants[ownVariants.findIndex((variant) => answer.some((a: string) => a === variant.id))]?.variant
|
||||||
@ -118,25 +109,8 @@ export async function sendQuestionAnswer(
|
|||||||
let answerString = ``;
|
let answerString = ``;
|
||||||
selectedVariants.forEach((e) => {
|
selectedVariants.forEach((e) => {
|
||||||
if (!e.isOwn || (e.isOwn && question.content.own)) {
|
if (!e.isOwn || (e.isOwn && question.content.own)) {
|
||||||
let imageValue = e.extendedText;
|
|
||||||
if (e.isOwn) {
|
|
||||||
// Берем fileId из ownVariants для own вариантов
|
|
||||||
const ownVariantData = ownVariants.find((v) => v.id === e.id)?.variant;
|
|
||||||
if (ownVariantData?.originalImageUrl) {
|
|
||||||
// Конструируем полный URL для own вариантов
|
|
||||||
const baseUrl =
|
|
||||||
"https://s3.timeweb.cloud/3c580be9-cf31f296-d055-49cf-b39e-30c7959dc17b/squizimages/55c25eb9-4533-4d51-9da5-54e63e8aeace/";
|
|
||||||
// Убираем расширение файла из fileId
|
|
||||||
const fileIdWithoutExtension = ownVariantData.originalImageUrl.replace(
|
|
||||||
/\.(jpg|jpeg|png|gif|webp)$/i,
|
|
||||||
""
|
|
||||||
);
|
|
||||||
imageValue = baseUrl + fileIdWithoutExtension;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
Image: imageValue,
|
Image: e.extendedText,
|
||||||
Description: e.isOwn ? ownAnswer : e.answer,
|
Description: e.isOwn ? ownAnswer : e.answer,
|
||||||
};
|
};
|
||||||
answerString += `\`${JSON.stringify(body)}\`,`;
|
answerString += `\`${JSON.stringify(body)}\`,`;
|
||||||
@ -150,38 +124,13 @@ export async function sendQuestionAnswer(
|
|||||||
qid: quizId,
|
qid: quizId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log("Этот вопрос НЕ есть МУЛЬТИ");
|
|
||||||
|
|
||||||
const variant = question.content.variants.find((v) => v.id === questionAnswer.answer);
|
const variant = question.content.variants.find((v) => v.id === questionAnswer.answer);
|
||||||
|
|
||||||
if (!variant) throw new Error(`Cannot find variant with id ${questionAnswer.answer} in question ${question.id}`);
|
if (!variant) throw new Error(`Cannot find variant with id ${questionAnswer.answer} in question ${question.id}`);
|
||||||
|
|
||||||
// Берем fileId из ownVariants для own вариантов
|
|
||||||
const ownVariantData = ownVariants.find((v) => v.id === variant.id)?.variant;
|
|
||||||
|
|
||||||
console.log("Был выбран вариант ", variant);
|
|
||||||
console.log("Был выбран ownVariant ", ownVariantData);
|
|
||||||
|
|
||||||
let imageValue = variant.extendedText;
|
|
||||||
if (variant.isOwn) {
|
|
||||||
if (ownVariantData?.originalImageUrl) {
|
|
||||||
// Конструируем полный URL для own вариантов
|
|
||||||
const baseUrl =
|
|
||||||
"https://s3.timeweb.cloud/3c580be9-cf31f296-d055-49cf-b39e-30c7959dc17b/squizimages/55c25eb9-4533-4d51-9da5-54e63e8aeace/";
|
|
||||||
// Убираем расширение файла из fileId
|
|
||||||
const fileIdWithoutExtension = ownVariantData.originalImageUrl.replace(/\.(jpg|jpeg|png|gif|webp)$/i, "");
|
|
||||||
imageValue = baseUrl + fileIdWithoutExtension;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("В конечном итоге я планирую отправить вот эти данные: ", {
|
|
||||||
Image: imageValue,
|
|
||||||
Description: ownVariantData ? ownVariantData.answer : variant.answer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
Image: imageValue,
|
Image: variant.extendedText,
|
||||||
Description: ownVariantData ? ownVariantData.answer : variant.answer,
|
Description: variant.answer,
|
||||||
};
|
};
|
||||||
if (!body) throw new Error(`Body of answer in question ${question.id} is undefined`);
|
if (!body) throw new Error(`Body of answer in question ${question.id} is undefined`);
|
||||||
|
|
||||||
@ -279,24 +228,9 @@ export async function sendQuestionAnswer(
|
|||||||
ownVariants[ownVariants.findIndex((variant) => variant.id === questionAnswer.answer)]?.variant?.answer || "";
|
ownVariants[ownVariants.findIndex((variant) => variant.id === questionAnswer.answer)]?.variant?.answer || "";
|
||||||
|
|
||||||
if (!variant) throw new Error(`Cannot find variant with id ${questionAnswer.answer} in question ${question.id}`);
|
if (!variant) throw new Error(`Cannot find variant with id ${questionAnswer.answer} in question ${question.id}`);
|
||||||
|
|
||||||
let imageValue = variant.extendedText;
|
|
||||||
if (variant.isOwn) {
|
|
||||||
// Берем fileId из ownVariants для own вариантов
|
|
||||||
const ownVariantData = ownVariants.find((v) => v.id === variant.id)?.variant;
|
|
||||||
if (ownVariantData?.originalImageUrl) {
|
|
||||||
// Конструируем полный URL для own вариантов
|
|
||||||
const baseUrl =
|
|
||||||
"https://s3.timeweb.cloud/3c580be9-cf31f296-d055-49cf-b39e-30c7959dc17b/squizimages/55c25eb9-4533-4d51-9da5-54e63e8aeace/";
|
|
||||||
// Убираем расширение файла из fileId
|
|
||||||
const fileIdWithoutExtension = ownVariantData.originalImageUrl.replace(/\.(jpg|jpeg|png|gif|webp)$/i, "");
|
|
||||||
imageValue = baseUrl + fileIdWithoutExtension;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
Image: imageValue,
|
Image: variant.extendedText,
|
||||||
Description: variant.isOwn ? ownAnswer : variant.answer,
|
Description: question.content.own ? ownAnswer : variant.answer,
|
||||||
};
|
};
|
||||||
if (!body) throw new Error(`Body of answer in question ${question.id} is undefined`);
|
if (!body) throw new Error(`Body of answer in question ${question.id} is undefined`);
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"cypress:open": "cypress open",
|
"cypress:open": "cypress open",
|
||||||
"prepublishOnly": "npm run build:package",
|
"prepublishOnly": "npm run build:package",
|
||||||
"deploy": "docker login gitea.pena && docker build -t gitea.pena/squiz/frontanswerer/$(git branch --show-current):latest . && docker push gitea.pena/squiz/frontanswerer/$(git branch --show-current):latest",
|
|
||||||
"prepare": "husky"
|
"prepare": "husky"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -53,8 +53,5 @@
|
|||||||
"and": "and",
|
"and": "and",
|
||||||
"Get results": "Get results",
|
"Get results": "Get results",
|
||||||
"Data sent successfully": "Data sent successfully",
|
"Data sent successfully": "Data sent successfully",
|
||||||
"Step": "Step",
|
"Step": "Step"
|
||||||
"questions are not ready yet": "There are no questions for the audience yet. Please wait",
|
|
||||||
"Add your image": "Add your image",
|
|
||||||
"select emoji": "select emoji"
|
|
||||||
}
|
}
|
||||||
|
@ -54,10 +54,6 @@
|
|||||||
"Get results": "Получить результаты",
|
"Get results": "Получить результаты",
|
||||||
"Data sent successfully": "Данные успешно отправлены",
|
"Data sent successfully": "Данные успешно отправлены",
|
||||||
"Step": "Шаг",
|
"Step": "Шаг",
|
||||||
"questions are not ready yet": "Вопросы для аудитории ещё не созданы. Пожалуйста, подождите",
|
"neftyanka FK": "Заполните форму, чтобы отправить ваши ответы на викторину",
|
||||||
"Add your image": "Добавьте своё изображение",
|
"neftyanka button": "Отправить"
|
||||||
"select emoji": "выберите смайлик",
|
|
||||||
"Please complete the phone number": "Пожалуйста, завершите номер телефона",
|
|
||||||
"Please enter a valid email": "Пожалуйста, введите корректную почту",
|
|
||||||
"Please enter a valid phone number": "Пожалуйста, введите корректный номер телефона"
|
|
||||||
}
|
}
|
||||||
|
@ -53,8 +53,5 @@
|
|||||||
"and": "va",
|
"and": "va",
|
||||||
"Get results": "Natijalarni olish",
|
"Get results": "Natijalarni olish",
|
||||||
"Data sent successfully": "Ma'lumotlar muvaffaqiyatli yuborildi",
|
"Data sent successfully": "Ma'lumotlar muvaffaqiyatli yuborildi",
|
||||||
"Step": "Qadam",
|
"Step": "Qadam"
|
||||||
"questions are not ready yet": "Tomoshabinlar uchun hozircha savollar yo'q. Iltimos kuting",
|
|
||||||
"Add your image": "Rasmingizni qo'shing",
|
|
||||||
"select emoji": "emoji tanlang"
|
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,11 @@ const getLanguageFromURL = (): string => {
|
|||||||
const langMatch = path.match(/^\/(en|ru|uz)(\/|$)/i);
|
const langMatch = path.match(/^\/(en|ru|uz)(\/|$)/i);
|
||||||
|
|
||||||
if (langMatch) {
|
if (langMatch) {
|
||||||
const detectedLang = langMatch[1].toLowerCase();
|
//console.log("Язык из URL:", langMatch[1]);
|
||||||
return detectedLang;
|
return langMatch[1].toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//console.log('Язык не указан в URL, используем "ru"');
|
||||||
return "ru"; // Жёсткий фолбэк
|
return "ru"; // Жёсткий фолбэк
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -32,9 +33,6 @@ i18n
|
|||||||
backend: {
|
backend: {
|
||||||
loadPath: "/locales/{{lng}}.json",
|
loadPath: "/locales/{{lng}}.json",
|
||||||
allowMultiLoading: false,
|
allowMultiLoading: false,
|
||||||
requestOptions: {
|
|
||||||
cache: "no-store",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
react: {
|
react: {
|
||||||
useSuspense: false, // Отключаем для совместимости с React 18
|
useSuspense: false, // Отключаем для совместимости с React 18
|
||||||
@ -45,11 +43,11 @@ i18n
|
|||||||
caches: [], // Не использовать localStorage
|
caches: [], // Не использовать localStorage
|
||||||
},
|
},
|
||||||
parseMissingKeyHandler: (key) => {
|
parseMissingKeyHandler: (key) => {
|
||||||
console.warn("⚠️ Main i18n: Missing translation:", key);
|
console.warn("Missing translation:", key);
|
||||||
return key; // Вернёт ключ вместо ошибки
|
return key; // Вернёт ключ вместо ошибки
|
||||||
},
|
},
|
||||||
missingKeyHandler: (lngs, ns, key) => {
|
missingKeyHandler: (lngs, ns, key) => {
|
||||||
console.error("🚨 Main i18n: Missing i18n key:", {
|
console.error("🚨 Missing i18n key:", {
|
||||||
key,
|
key,
|
||||||
languages: lngs,
|
languages: lngs,
|
||||||
namespace: ns,
|
namespace: ns,
|
||||||
@ -57,35 +55,21 @@ i18n
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
.then(() => {
|
||||||
|
//console.log("i18n инициализирован! Текущий язык:", i18n.language);
|
||||||
|
//console.log("Загруженные переводы:", i18n.store.data);
|
||||||
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error("❌ Main i18n: Initialization failed:", err);
|
console.error("Ошибка i18n:", err);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 3. Логирование всех событий
|
// 3. Логирование всех событий
|
||||||
i18n.on("languageChanged", (lng) => {
|
i18n.on("languageChanged", (lng) => {
|
||||||
console.log("🔄 Main i18n: Language changed to:", lng);
|
console.log("Язык изменён на:", lng);
|
||||||
});
|
|
||||||
|
|
||||||
i18n.on("initialized", (options) => {
|
|
||||||
console.log("🎯 Main i18n: Initialized event fired with options:", options);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
i18n.on("failedLoading", (lng, ns, msg) => {
|
i18n.on("failedLoading", (lng, ns, msg) => {
|
||||||
console.error(`💥 Main i18n: Failed loading ${lng}.json:`, msg);
|
console.error(`Ошибка загрузки ${lng}.json:`, msg);
|
||||||
|
|
||||||
// Если не удалось загрузить русский, пробуем английский
|
|
||||||
if (lng === "ru") {
|
|
||||||
console.log("🔄 Main i18n: Trying to load English as fallback");
|
|
||||||
i18n.changeLanguage("en");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
i18n.on("loaded", (loaded) => {
|
|
||||||
console.log("📦 Main i18n: Translations loaded:", loaded);
|
|
||||||
});
|
|
||||||
|
|
||||||
i18n.on("missingKey", (lngs, namespace, key, res) => {
|
|
||||||
console.warn("⚠️ Main i18n: Missing key event:", { lngs, namespace, key, res });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default i18n;
|
export default i18n;
|
||||||
|
@ -1,287 +0,0 @@
|
|||||||
import i18n from "i18next";
|
|
||||||
import { initReactI18next } from "react-i18next";
|
|
||||||
|
|
||||||
// 1. Функция для определения языка из URL
|
|
||||||
const getLanguageFromURL = (): string => {
|
|
||||||
const path = window.location.pathname;
|
|
||||||
const langMatch = path.match(/^\/(en|ru|uz)(\/|$)/i);
|
|
||||||
const detectedLang = langMatch ? langMatch[1].toLowerCase() : "ru"; // Фолбэк на 'ru'
|
|
||||||
return detectedLang;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 2. Локали, встроенные прямо в конфиг
|
|
||||||
|
|
||||||
const r = {
|
|
||||||
ru: {
|
|
||||||
translation: {
|
|
||||||
"quiz is inactive": "Квиз не активирован",
|
|
||||||
"no questions found": "Нет созданных вопросов",
|
|
||||||
"quiz is empty": "Квиз пуст",
|
|
||||||
"quiz already completed": "Вы уже прошли этот опрос",
|
|
||||||
"no quiz id": "Отсутствует id квиза",
|
|
||||||
"quiz data is null": "Не были переданы параметры квиза",
|
|
||||||
"invalid request data": "Такого квиза не существует",
|
|
||||||
"default message": "Что-то пошло не так",
|
|
||||||
"The request could not be sent": "Заявка не может быть отправлена",
|
|
||||||
"The number of points could not be sent": "Количество баллов не может быть отправлено",
|
|
||||||
"Your result": "Ваш результат",
|
|
||||||
"Your points": "Ваши баллы",
|
|
||||||
of: "из",
|
|
||||||
"View answers": "Посмотреть ответы",
|
|
||||||
"Find out more": "Узнать подробнее",
|
|
||||||
"Go to website": "Перейти на сайт",
|
|
||||||
"Question title": "Заголовок вопроса",
|
|
||||||
"Question without a title": "Вопрос без названия",
|
|
||||||
"Your answer": "Ваш ответ",
|
|
||||||
"Add image": "Добавить изображение",
|
|
||||||
"Accepts images": "Принимает изображения",
|
|
||||||
"Add video": "Добавить видео",
|
|
||||||
"Accepts .mp4 and .mov format - maximum 50mb": "Принимает .mp4 и .mov формат — максимум 50мб",
|
|
||||||
"Add audio file": "Добавить аудиофайл",
|
|
||||||
"Accepts audio files": "Принимает аудиофайлы",
|
|
||||||
"Add document": "Добавить документ",
|
|
||||||
"Accepts documents": "Принимает документы",
|
|
||||||
Next: "Далее",
|
|
||||||
Prev: "Назад",
|
|
||||||
From: "От",
|
|
||||||
До: "До",
|
|
||||||
"Enter your answer": "Введите свой ответ",
|
|
||||||
"Incorrect file type selected": "Выбран некорректный тип файла",
|
|
||||||
"File is too big. Maximum size is 50 MB": "Файл слишком большой. Максимальный размер 50 МБ",
|
|
||||||
"Acceptable file extensions": "Допустимые расширения файлов",
|
|
||||||
"You have uploaded": "Вы загрузили",
|
|
||||||
"The answer was not counted": "Ответ не был засчитан",
|
|
||||||
"Select an answer option below": "Выберите вариант ответа ниже",
|
|
||||||
"Select an answer option on the left": "Выберите вариант ответа слева",
|
|
||||||
"Fill out the form to receive your test results": "Заполните форму, чтобы получить результаты теста",
|
|
||||||
Enter: "Введите",
|
|
||||||
Name: "Имя",
|
|
||||||
"Phone number": "Номер телефона",
|
|
||||||
"Last name": "Фамилия",
|
|
||||||
Address: "Адрес",
|
|
||||||
"Incorrect email entered": "Введена некорректная почта",
|
|
||||||
"Please fill in the fields": "Пожалуйста, заполните поля",
|
|
||||||
"Please try again later": "повторите попытку позже",
|
|
||||||
"Regulation on the processing of personal data": "Положением об обработке персональных данных",
|
|
||||||
"Privacy Policy": "Политикой конфиденциальности",
|
|
||||||
familiarized: "ознакомлен",
|
|
||||||
and: "и",
|
|
||||||
"Get results": "Получить результаты",
|
|
||||||
"Data sent successfully": "Данные успешно отправлены",
|
|
||||||
Step: "Шаг",
|
|
||||||
"questions are not ready yet": "Вопросы для аудитории пока не готовы. Подождите",
|
|
||||||
"Add your image": "Добавьте своё изображение",
|
|
||||||
"select emoji": "выберите смайлик",
|
|
||||||
"Please complete the phone number": "Пожалуйста, заполните номер телефона до конца",
|
|
||||||
"": "", // Пустой ключ для fallback
|
|
||||||
},
|
|
||||||
},
|
|
||||||
en: {
|
|
||||||
translation: {
|
|
||||||
"quiz is inactive": "Quiz is inactive",
|
|
||||||
"no questions found": "No questions found",
|
|
||||||
"quiz is empty": "Quiz is empty",
|
|
||||||
"quiz already completed": "You've already completed this quiz",
|
|
||||||
"no quiz id": "Missing quiz ID",
|
|
||||||
"quiz data is null": "No quiz parameters were provided",
|
|
||||||
"invalid request data": "This quiz doesn't exist",
|
|
||||||
"default message": "Something went wrong",
|
|
||||||
"The request could not be sent": "Request could not be sent",
|
|
||||||
"The number of points could not be sent": "Points could not be submitted",
|
|
||||||
"Your result": "Your result",
|
|
||||||
"Your points": "Your points",
|
|
||||||
of: "of",
|
|
||||||
"View answers": "View answers",
|
|
||||||
"Find out more": "Learn more",
|
|
||||||
"Go to website": "Go to website",
|
|
||||||
"Question title": "Question title",
|
|
||||||
"Question without a title": "Untitled question",
|
|
||||||
"Your answer": "Your answer",
|
|
||||||
"Add image": "Add image",
|
|
||||||
"Accepts images": "Accepts images",
|
|
||||||
"Add video": "Add video",
|
|
||||||
"Accepts .mp4 and .mov format - maximum 50mb": "Accepts .mp4 and .mov format - maximum 50MB",
|
|
||||||
"Add audio file": "Add audio file",
|
|
||||||
"Accepts audio files": "Accepts audio files",
|
|
||||||
"Add document": "Add document",
|
|
||||||
"Accepts documents": "Accepts documents",
|
|
||||||
Next: "Next",
|
|
||||||
Prev: "Previous",
|
|
||||||
From: "From",
|
|
||||||
До: "To",
|
|
||||||
"Enter your answer": "Enter your answer",
|
|
||||||
"Incorrect file type selected": "Invalid file type selected",
|
|
||||||
"File is too big. Maximum size is 50 MB": "File is too large. Maximum size is 50 MB",
|
|
||||||
"Acceptable file extensions": "Allowed file extensions",
|
|
||||||
"You have uploaded": "You've uploaded",
|
|
||||||
"The answer was not counted": "Answer wasn't counted",
|
|
||||||
"Select an answer option below": "Select an answer option below",
|
|
||||||
"Select an answer option on the left": "Select an answer option on the left",
|
|
||||||
"Fill out the form to receive your test results": "Fill out the form to receive your test results",
|
|
||||||
Enter: "Enter",
|
|
||||||
Name: "Name",
|
|
||||||
"Phone number": "Phone number",
|
|
||||||
"Last name": "Last name",
|
|
||||||
Address: "Address",
|
|
||||||
"Incorrect email entered": "Invalid email entered",
|
|
||||||
"Please fill in the fields": "Please fill in the fields",
|
|
||||||
"Please try again later": "Please try again later",
|
|
||||||
"Regulation on the processing of personal data": "Personal Data Processing Regulation",
|
|
||||||
"Privacy Policy": "Privacy Policy",
|
|
||||||
familiarized: "acknowledged",
|
|
||||||
and: "and",
|
|
||||||
"Get results": "Get results",
|
|
||||||
"Data sent successfully": "Data sent successfully",
|
|
||||||
Step: "Step",
|
|
||||||
"questions are not ready yet": "There are no questions for the audience yet. Please wait",
|
|
||||||
"Add your image": "Add your image",
|
|
||||||
"select emoji": "select emoji",
|
|
||||||
"Please complete the phone number": "Please complete the phone number",
|
|
||||||
"": "", // Пустой ключ для fallback
|
|
||||||
},
|
|
||||||
},
|
|
||||||
uz: {
|
|
||||||
translation: {
|
|
||||||
"quiz is inactive": "Test faol emas",
|
|
||||||
"no questions found": "Savollar topilmadi",
|
|
||||||
"quiz is empty": "Test boʻsh",
|
|
||||||
"quiz already completed": "Siz bu testni allaqachon topshirgansiz",
|
|
||||||
"no quiz id": "Test IDsi yoʻq",
|
|
||||||
"quiz data is null": "Test parametrlari yuborilmagan",
|
|
||||||
"invalid request data": "Bunday test mavjud emas",
|
|
||||||
"default message": "Xatolik yuz berdi",
|
|
||||||
"The request could not be sent": "Soʻrov yuborib boʻlmadi",
|
|
||||||
"The number of points could not be sent": "Ballar yuborib boʻlmadi",
|
|
||||||
"Your result": "Sizning natijangiz",
|
|
||||||
"Your points": "Sizning ballaringiz",
|
|
||||||
of: "/",
|
|
||||||
"View answers": "Javoblarni koʻrish",
|
|
||||||
"Find out more": "Batafsil maʼlumot",
|
|
||||||
"Go to website": "Veb-saytga oʻtish",
|
|
||||||
"Question title": "Savol sarlavhasi",
|
|
||||||
"Question without a title": "Sarlavhasiz savol",
|
|
||||||
"Your answer": "Sizning javobingiz",
|
|
||||||
"Add image": "Rasm qoʻshish",
|
|
||||||
"Accepts images": "Rasmlarni qabul qiladi",
|
|
||||||
"Add video": "Video qoʻshish",
|
|
||||||
"Accepts .mp4 and .mov format - maximum 50mb": ".mp4 va .mov formatlarini qabul qiladi - maksimal 50MB",
|
|
||||||
"Add audio file": "Audio fayl qoʻshish",
|
|
||||||
"Accepts audio files": "Audio fayllarni qabul qiladi",
|
|
||||||
"Add document": "Hujjat qoʻshish",
|
|
||||||
"Accepts documents": "Hujjatlarni qabul qiladi",
|
|
||||||
Next: "Keyingi",
|
|
||||||
Prev: "Oldingi",
|
|
||||||
From: "Dan",
|
|
||||||
До: "Gacha",
|
|
||||||
"Enter your answer": "Javobingizni kiriting",
|
|
||||||
"Incorrect file type selected": "Notoʻgʻri fayl turi tanlandi",
|
|
||||||
"File is too big. Maximum size is 50 MB": "Fayl juda katta. Maksimal hajmi 50 MB",
|
|
||||||
"Acceptable file extensions": "Qabul qilinadigan fayl kengaytmalari",
|
|
||||||
"You have uploaded": "Siz yuklagansiz",
|
|
||||||
"The answer was not counted": "Javob hisobga olinmadi",
|
|
||||||
"Select an answer option below": "Quyidagi javob variantlaridan birini tanlang",
|
|
||||||
"Select an answer option on the left": "Chapdagi javob variantlaridan birini tanlang",
|
|
||||||
"Fill out the form to receive your test results": "Test natijalaringizni olish uchun shaklni toʻldiring",
|
|
||||||
Enter: "Kiriting",
|
|
||||||
Name: "Ism",
|
|
||||||
"Phone number": "Telefon raqami",
|
|
||||||
"Last name": "Familiya",
|
|
||||||
Address: "Manzil",
|
|
||||||
"Incorrect email entered": "Notoʻgʻri elektron pochta kiritildi",
|
|
||||||
"Please fill in the fields": "Iltimos, maydonlarni toʻldiring",
|
|
||||||
"Please try again later": "Iltimos, keyinroq urinib koʻring",
|
|
||||||
"Regulation on the processing of personal data": "Shaxsiy maʼlumotlarni qayta ishlash qoidalari",
|
|
||||||
"Privacy Policy": "Maxfiylik siyosati",
|
|
||||||
familiarized: "tanishdim",
|
|
||||||
and: "va",
|
|
||||||
"Get results": "Natijalarni olish",
|
|
||||||
"Data sent successfully": "Ma'lumotlar muvaffaqiyatli yuborildi",
|
|
||||||
Step: "Qadam",
|
|
||||||
"questions are not ready yet": "Tomoshabinlar uchun hozircha savollar yo'q. Iltimos kuting",
|
|
||||||
"Add your image": "Rasmingizni qo'shing",
|
|
||||||
"select emoji": "emoji tanlang",
|
|
||||||
"Please complete the phone number": "Iltimos, telefon raqamini to'liq kiriting",
|
|
||||||
"": "", // Пустой ключ для fallback
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Проверяем, не инициализирован ли уже i18n
|
|
||||||
if (i18n.isInitialized) {
|
|
||||||
// Добавляем ресурсы к существующему экземпляру
|
|
||||||
(Object.keys(r) as Array<"ru" | "en" | "uz">).forEach((lng) => {
|
|
||||||
if (i18n.store.data[lng] && i18n.store.data[lng].translation) {
|
|
||||||
// Объединяем с существующими переводами
|
|
||||||
i18n.store.data[lng].translation = {
|
|
||||||
...(i18n.store.data[lng].translation as Record<string, string>),
|
|
||||||
...r[lng].translation,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
// Добавляем новые переводы
|
|
||||||
i18n.store.data[lng] = {
|
|
||||||
...(i18n.store.data[lng] as Record<string, any>),
|
|
||||||
translation: r[lng].translation,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// 3. Конфигурация i18n без Backend
|
|
||||||
i18n
|
|
||||||
.use(initReactI18next)
|
|
||||||
.init({
|
|
||||||
resources: r, // Используем встроенные переводы
|
|
||||||
lng: getLanguageFromURL(),
|
|
||||||
fallbackLng: "ru",
|
|
||||||
supportedLngs: ["en", "ru", "uz"],
|
|
||||||
debug: true,
|
|
||||||
interpolation: {
|
|
||||||
escapeValue: false,
|
|
||||||
},
|
|
||||||
react: {
|
|
||||||
useSuspense: false,
|
|
||||||
},
|
|
||||||
detection: {
|
|
||||||
order: ["path"],
|
|
||||||
lookupFromPathIndex: 0,
|
|
||||||
caches: [],
|
|
||||||
},
|
|
||||||
parseMissingKeyHandler: (key) => {
|
|
||||||
console.warn("⚠️ Widget i18n: Missing translation key:", key);
|
|
||||||
return key;
|
|
||||||
},
|
|
||||||
missingKeyHandler: (lngs, ns, key) => {
|
|
||||||
console.error("🚨 Widget i18n: Missing i18n key:", {
|
|
||||||
key,
|
|
||||||
languages: lngs,
|
|
||||||
namespace: ns,
|
|
||||||
stack: new Error().stack,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("❌ Widget i18n: Initialization failed:", error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Логирование событий
|
|
||||||
i18n.on("languageChanged", (lng) => {
|
|
||||||
console.log("🔄 Widget i18n: Language changed to:", lng);
|
|
||||||
});
|
|
||||||
|
|
||||||
i18n.on("initialized", (options) => {
|
|
||||||
console.log("🎯 Widget i18n: Initialized event fired with options:", options);
|
|
||||||
});
|
|
||||||
|
|
||||||
i18n.on("loaded", (loaded) => {
|
|
||||||
console.log("📦 Widget i18n: Loaded event fired:", loaded);
|
|
||||||
});
|
|
||||||
|
|
||||||
i18n.on("failedLoading", (lng, ns, msg) => {
|
|
||||||
console.error("💥 Widget i18n: Failed loading:", { lng, ns, msg });
|
|
||||||
});
|
|
||||||
|
|
||||||
i18n.on("missingKey", (lngs, namespace, key, res) => {
|
|
||||||
console.warn("⚠️ Widget i18n: Missing key event:", { lngs, namespace, key, res });
|
|
||||||
});
|
|
||||||
|
|
||||||
export default i18n;
|
|
@ -2,7 +2,6 @@ import { createRoot } from "react-dom/client";
|
|||||||
import { RouteObject, RouterProvider, createBrowserRouter } from "react-router-dom";
|
import { RouteObject, RouterProvider, createBrowserRouter } from "react-router-dom";
|
||||||
import App from "./App";
|
import App from "./App";
|
||||||
import { StrictMode, lazy } from "react";
|
import { StrictMode, lazy } from "react";
|
||||||
|
|
||||||
import "./i18n/i18n";
|
import "./i18n/i18n";
|
||||||
|
|
||||||
const routes: RouteObject[] = [
|
const routes: RouteObject[] = [
|
||||||
|
@ -3,8 +3,6 @@ import { createRoot } from "react-dom/client";
|
|||||||
// eslint-disable-next-line react-refresh/only-export-components
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
export * from "./widgets";
|
export * from "./widgets";
|
||||||
|
|
||||||
import "./i18n/i18nWidget";
|
|
||||||
|
|
||||||
// old widget
|
// old widget
|
||||||
const widget = {
|
const widget = {
|
||||||
create({
|
create({
|
||||||
@ -17,20 +15,11 @@ const widget = {
|
|||||||
changeFaviconAndTitle: boolean;
|
changeFaviconAndTitle: boolean;
|
||||||
}) {
|
}) {
|
||||||
const element = document.getElementById(selector);
|
const element = document.getElementById(selector);
|
||||||
if (!element) {
|
if (!element) throw new Error("Element for widget doesn't exist");
|
||||||
console.error("❌ Widget: Element for widget doesn't exist:", selector);
|
|
||||||
throw new Error("Element for widget doesn't exist");
|
|
||||||
}
|
|
||||||
|
|
||||||
const root = createRoot(element);
|
const root = createRoot(element);
|
||||||
|
|
||||||
root.render(
|
root.render(<QuizAnswerer quizId={quizId} changeFaviconAndTitle={changeFaviconAndTitle} disableGlobalCss />);
|
||||||
<QuizAnswerer
|
|
||||||
quizId={quizId}
|
|
||||||
changeFaviconAndTitle={changeFaviconAndTitle}
|
|
||||||
disableGlobalCss
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ export default function QuizPopup({
|
|||||||
|
|
||||||
if (!quizData) return null;
|
if (!quizData) return null;
|
||||||
|
|
||||||
const isQuizCompleted = quizData.settings?.cfg?.antifraud ? quizData.recentlyCompleted : false;
|
const isQuizCompleted = quizData.settings.cfg.antifraud ? quizData.recentlyCompleted : false;
|
||||||
if (isQuizCompleted) return null;
|
if (isQuizCompleted) return null;
|
||||||
if (hideOnMobile && isMobile) return null;
|
if (hideOnMobile && isMobile) return null;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ export default function QuizSideButton({
|
|||||||
if (hideOnMobile && isMobile) return null;
|
if (hideOnMobile && isMobile) return null;
|
||||||
if (!quizData) return null;
|
if (!quizData) return null;
|
||||||
|
|
||||||
const isQuizCompleted = quizData.settings?.cfg?.antifraud ? quizData.recentlyCompleted : false;
|
const isQuizCompleted = quizData.settings.cfg.antifraud ? quizData.recentlyCompleted : false;
|
||||||
const showButtonFlash = !isQuizCompleted && isFlashEnabled;
|
const showButtonFlash = !isQuizCompleted && isFlashEnabled;
|
||||||
|
|
||||||
return createPortal(
|
return createPortal(
|
||||||
|
@ -9,8 +9,6 @@ export default defineConfig({
|
|||||||
alias,
|
alias,
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
minify: false, // Отключает минификацию
|
|
||||||
sourcemap: true, // Включает sourcemaps для отладки
|
|
||||||
copyPublicDir: false,
|
copyPublicDir: false,
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
input: "src/widget.tsx",
|
input: "src/widget.tsx",
|
||||||
|
@ -275,7 +275,7 @@
|
|||||||
|
|
||||||
"@emoji-mart/react@^1.1.1":
|
"@emoji-mart/react@^1.1.1":
|
||||||
version "1.1.1"
|
version "1.1.1"
|
||||||
resolved "https://registry.npmjs.org/@emoji-mart/react/-/react-1.1.1.tgz#ddad52f93a25baf31c5383c3e7e4c6e05554312a"
|
resolved "https://registry.npmjs.org/@emoji-mart/react/-/react-1.1.1.tgz"
|
||||||
integrity sha512-NMlFNeWgv1//uPsvLxvGQoIerPuVdXwK/EUek8OOkJ6wVOWPUizRBJU0hDqWZCOROVpfBgCemaC3m6jDOXi03g==
|
integrity sha512-NMlFNeWgv1//uPsvLxvGQoIerPuVdXwK/EUek8OOkJ6wVOWPUizRBJU0hDqWZCOROVpfBgCemaC3m6jDOXi03g==
|
||||||
|
|
||||||
"@emotion/babel-plugin@^11.11.0":
|
"@emotion/babel-plugin@^11.11.0":
|
||||||
|
Loading…
Reference in New Issue
Block a user