From 479532f6bec978497928fcb5b64fbdb14d9ab22a Mon Sep 17 00:00:00 2001 From: Nastya Date: Tue, 1 Jul 2025 11:23:40 +0300 Subject: [PATCH] -- --- lib/components/QuizAnswerer.tsx | 11 ++++ .../ViewPublicationPage/ApologyPage.tsx | 3 +- src/i18n/i18n.ts | 66 +++++++++++++++++++ src/widget.tsx | 14 +++- vite.config.widget.ts | 6 +- 5 files changed, 96 insertions(+), 4 deletions(-) diff --git a/lib/components/QuizAnswerer.tsx b/lib/components/QuizAnswerer.tsx index da5d58f..0a4bf83 100644 --- a/lib/components/QuizAnswerer.tsx +++ b/lib/components/QuizAnswerer.tsx @@ -99,9 +99,20 @@ function QuizAnswererInner({ console.log("settings"); console.log(settings); + console.log("questions"); + console.log(questions); + console.log("error"); + console.log(error); + console.log("isLoading"); + console.log(isLoading); + console.log("quizId"); + console.log(quizId); + if (isLoading && !questions.length) return ; if (error) return ; + if (isLoading) return ; + if (Object.keys(settings).length == 0) return ; if (questions.length === 0) return ; diff --git a/lib/components/ViewPublicationPage/ApologyPage.tsx b/lib/components/ViewPublicationPage/ApologyPage.tsx index a6afa60..71dcf4c 100644 --- a/lib/components/ViewPublicationPage/ApologyPage.tsx +++ b/lib/components/ViewPublicationPage/ApologyPage.tsx @@ -5,8 +5,9 @@ import { useTranslation } from "react-i18next"; type Props = Partial; export const ApologyPage = ({ error }: Props) => { - let message = error.message || error.response?.data; + let message = error?.message || error?.response?.data || "default message"; console.log("message"); + console.log(message); console.log(message.toLowerCase()); const { t } = useTranslation(); console.log("t"); diff --git a/src/i18n/i18n.ts b/src/i18n/i18n.ts index e4f8067..6c89d64 100644 --- a/src/i18n/i18n.ts +++ b/src/i18n/i18n.ts @@ -18,11 +18,77 @@ const getLanguageFromURL = (): string => { return "ru"; // Жёсткий фолбэк }; +const r = { + ru: { + "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": "выберите смайлик", + "file is too big": "Файл слишком большой", + "file type is not supported": "Тип файла не поддерживается", + }, +}; + // 2. Конфиг с полной отладкой i18n .use(Backend) .use(initReactI18next) .init({ + resources: r, lng: getLanguageFromURL(), // Принудительно из URL fallbackLng: "ru", supportedLngs: ["en", "ru", "uz"], diff --git a/src/widget.tsx b/src/widget.tsx index 653e35b..6ec8cc4 100644 --- a/src/widget.tsx +++ b/src/widget.tsx @@ -2,6 +2,7 @@ import QuizAnswerer from "@/components/QuizAnswerer"; import { createRoot } from "react-dom/client"; // eslint-disable-next-line react-refresh/only-export-components export * from "./widgets"; +import "./i18n/i18n"; // old widget const widget = { @@ -14,12 +15,23 @@ const widget = { quizId: string; changeFaviconAndTitle: boolean; }) { + console.log("Widget create called with:"); + console.log("selector:", selector); + console.log("quizId:", quizId); + console.log("changeFaviconAndTitle:", changeFaviconAndTitle); + const element = document.getElementById(selector); if (!element) throw new Error("Element for widget doesn't exist"); const root = createRoot(element); - root.render(); + root.render( + + ); }, }; diff --git a/vite.config.widget.ts b/vite.config.widget.ts index a5dddc6..bb14229 100644 --- a/vite.config.widget.ts +++ b/vite.config.widget.ts @@ -9,16 +9,18 @@ export default defineConfig({ alias, }, build: { + minify: true, // Включаем минификацию как в обычной сборке + sourcemap: false, // Отключаем sourcemaps как в обычной сборке copyPublicDir: false, rollupOptions: { input: "src/widget.tsx", - preserveEntrySignatures: "allow-extension", output: { - manualChunks: undefined, entryFileNames: "[name].js", chunkFileNames: "[name].js", assetFileNames: "[name].[ext]", + exports: "named", // Принудительно экспортируем все именованные экспорты }, + treeshake: false, // Отключаем tree-shaking для экспортов }, outDir: "widget", },