crutch neftyanka
This commit is contained in:
parent
fba39bec1d
commit
e654e1e90d
@ -75,8 +75,52 @@ 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<{
|
||||||
|
data: GetQuizDataResponse | null;
|
||||||
|
isRecentlyCompleted: boolean;
|
||||||
|
error?: AxiosError;
|
||||||
|
}> {
|
||||||
|
try {
|
||||||
|
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: 100,
|
||||||
|
page: 0,
|
||||||
|
need_config: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
|
||||||
|
|
||||||
export async function getData({ quizId, page }: { quizId: string; page?: number }): Promise<{
|
//Тут ещё проверка на антифрод без парса конфига. Нам не интересно время если не нужно запрещать проходить чаще чем в сутки
|
||||||
|
if (typeof sessions[quizId] === "number" && data.settings.cfg.includes('antifraud":true')) {
|
||||||
|
// unix время. Если меньше суток прошло - выводить ошибку, иначе пустить дальше
|
||||||
|
if (Date.now() - sessions[quizId] < 86400000) {
|
||||||
|
return { data, isRecentlyCompleted: true };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SESSIONS = headers["x-sessionkey"] ? headers["x-sessionkey"] : SESSIONS;
|
||||||
|
|
||||||
|
return { data, isRecentlyCompleted: false };
|
||||||
|
} catch (nativeError) {
|
||||||
|
const error = nativeError as AxiosError;
|
||||||
|
|
||||||
|
return { data: null, isRecentlyCompleted: false, error: error };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export async function getDataSingle({ quizId, page }: { quizId: string; page?: number }): Promise<{
|
||||||
data: GetQuizDataResponse | null;
|
data: GetQuizDataResponse | null;
|
||||||
isRecentlyCompleted: boolean;
|
isRecentlyCompleted: boolean;
|
||||||
error?: AxiosError;
|
error?: AxiosError;
|
||||||
@ -231,7 +275,7 @@ export async function getQuizDataAI(quizId: string) {
|
|||||||
while (resultRetryCount < maxRetries) {
|
while (resultRetryCount < maxRetries) {
|
||||||
try {
|
try {
|
||||||
console.log(`[getQuizDataAI] Attempt ${resultRetryCount + 1} for result questions, page: ${page}`);
|
console.log(`[getQuizDataAI] Attempt ${resultRetryCount + 1} for result questions, page: ${page}`);
|
||||||
const response = await getData({ quizId, page });
|
const response = await getData({ quizId });
|
||||||
console.log("[getQuizDataAI] Response from getData:", response);
|
console.log("[getQuizDataAI] Response from getData:", response);
|
||||||
|
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
@ -286,7 +330,7 @@ export async function getQuizDataAI(quizId: string) {
|
|||||||
try {
|
try {
|
||||||
console.log(`[getQuizDataAI] Empty items retry ${emptyRetryCount + 1}`);
|
console.log(`[getQuizDataAI] Empty items retry ${emptyRetryCount + 1}`);
|
||||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
const response = await getData({ quizId, page });
|
const response = await getData({ quizId });
|
||||||
|
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("[getQuizDataAI] Error in empty items check:", response.error);
|
console.error("[getQuizDataAI] Error in empty items check:", response.error);
|
||||||
|
@ -26,6 +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 { isNeftyanka } from "@/ui_kit/neftyankacrutch";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
currentQuestion: AnyTypedQuizQuestion;
|
currentQuestion: AnyTypedQuizQuestion;
|
||||||
@ -317,7 +318,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 && (
|
||||||
|
@ -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
|
||||||
|
@ -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>
|
||||||
|
);
|
||||||
|
};
|
@ -60,6 +60,7 @@ export const TextNormal = ({ currentQuestion, answer }: TextNormalProps) => {
|
|||||||
placeholder={currentQuestion.content.placeholder}
|
placeholder={currentQuestion.content.placeholder}
|
||||||
value={answer || ""}
|
value={answer || ""}
|
||||||
onChange={onInputChange}
|
onChange={onInputChange}
|
||||||
|
multiline={Boolean(currentQuestion.content?.multi)}
|
||||||
sx={{
|
sx={{
|
||||||
"& .MuiOutlinedInput-root": {
|
"& .MuiOutlinedInput-root": {
|
||||||
background: settings.cfg.design
|
background: settings.cfg.design
|
||||||
|
@ -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}
|
||||||
|
@ -20,5 +20,7 @@ export interface QuizQuestionText extends QuizQuestionBase {
|
|||||||
back: string | null;
|
back: string | null;
|
||||||
originalBack: string | null;
|
originalBack: string | null;
|
||||||
onlyNumbers: boolean;
|
onlyNumbers: boolean;
|
||||||
|
multi?: boolean;
|
||||||
|
detailedAnswer?: boolean;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ interface CustomTextFieldProps {
|
|||||||
text?: string;
|
text?: string;
|
||||||
sx?: SxProps<Theme>;
|
sx?: SxProps<Theme>;
|
||||||
InputProps?: Partial<InputProps>;
|
InputProps?: Partial<InputProps>;
|
||||||
|
multiline?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function CustomTextField({
|
export default function CustomTextField({
|
||||||
@ -28,11 +29,16 @@ export default function CustomTextField({
|
|||||||
onKeyDown,
|
onKeyDown,
|
||||||
onBlur,
|
onBlur,
|
||||||
InputProps,
|
InputProps,
|
||||||
|
multiline = false,
|
||||||
}: CustomTextFieldProps) {
|
}: CustomTextFieldProps) {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormControl fullWidth variant="standard" sx={{ p: 0 }}>
|
<FormControl
|
||||||
|
fullWidth
|
||||||
|
variant="standard"
|
||||||
|
sx={{ p: 0 }}
|
||||||
|
>
|
||||||
<TextField
|
<TextField
|
||||||
defaultValue={text}
|
defaultValue={text}
|
||||||
fullWidth
|
fullWidth
|
||||||
@ -43,10 +49,11 @@ export default function CustomTextField({
|
|||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
|
multiline={multiline}
|
||||||
sx={{
|
sx={{
|
||||||
"& .MuiInputBase-root": {
|
"& .MuiInputBase-root": {
|
||||||
backgroundColor: theme.palette.background.default,
|
backgroundColor: theme.palette.background.default,
|
||||||
height: "48px",
|
minHeight: "48px",
|
||||||
borderRadius: "10px",
|
borderRadius: "10px",
|
||||||
},
|
},
|
||||||
"& .MuiInputLabel-root": {
|
"& .MuiInputLabel-root": {
|
||||||
|
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";
|
@ -52,7 +52,8 @@
|
|||||||
"familiarized": "ознакомлен",
|
"familiarized": "ознакомлен",
|
||||||
"and": "и",
|
"and": "и",
|
||||||
"Get results": "Получить результаты",
|
"Get results": "Получить результаты",
|
||||||
|
"Data sent successfully": "Данные успешно отправлены",
|
||||||
"Step": "Шаг",
|
"Step": "Шаг",
|
||||||
"D": "-_-",
|
"neftyanka FK": "Заполните форму, чтобы отправить ваши ответы на викторину",
|
||||||
"d": "-_-"
|
"neftyanka button": "Отправить"
|
||||||
}
|
}
|
||||||
|
@ -3,23 +3,36 @@ 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";
|
||||||
|
|
||||||
|
/*
|
||||||
|
Две точки использования:
|
||||||
|
Или из конструктора квизов на сайте
|
||||||
|
Или запрос вместе с уже записанными в файлик данными
|
||||||
|
*/
|
||||||
// old widget
|
// old widget
|
||||||
const widget = {
|
const widget = {
|
||||||
create({
|
create({
|
||||||
selector,
|
selector,
|
||||||
quizId,
|
quizId,
|
||||||
changeFaviconAndTitle = true,
|
changeFaviconAndTitle = true,
|
||||||
|
preview = false, //Слать ли ответы на сервер
|
||||||
}: {
|
}: {
|
||||||
selector: string;
|
selector: string;
|
||||||
quizId: string;
|
quizId: string;
|
||||||
changeFaviconAndTitle: boolean;
|
changeFaviconAndTitle: boolean;
|
||||||
|
preview: boolean;
|
||||||
}) {
|
}) {
|
||||||
const element = document.getElementById(selector);
|
const element = document.getElementById(selector);
|
||||||
if (!element) throw new Error("Element for widget doesn't exist");
|
if (!element) throw new Error("Element for widget doesn't exist");
|
||||||
|
|
||||||
const root = createRoot(element);
|
const root = createRoot(element);
|
||||||
|
|
||||||
root.render(<QuizAnswerer quizId={quizId} changeFaviconAndTitle={changeFaviconAndTitle} disableGlobalCss />);
|
root.render(
|
||||||
|
<QuizAnswerer
|
||||||
|
quizId={quizId}
|
||||||
|
changeFaviconAndTitle={changeFaviconAndTitle}
|
||||||
|
disableGlobalCss
|
||||||
|
/>
|
||||||
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user