diff --git a/package.json b/package.json index e3b42b47..8cd4aeec 100755 --- a/package.json +++ b/package.json @@ -108,6 +108,7 @@ "endOfLine": "auto", "bracketSpacing": true, "arrowParens": "always", - "jsxSingleQuote": false + "jsxSingleQuote": false, + "singleAttributePerLine": false } } diff --git a/src/pages/InstallQuiz/QuizInstallationCard/WidgetSetupByType/BannerWidgetSetup/BannerWidgetSetup.tsx b/src/pages/InstallQuiz/QuizInstallationCard/WidgetSetupByType/BannerWidgetSetup/BannerWidgetSetup.tsx index 6e790cf1..ca5dcad7 100644 --- a/src/pages/InstallQuiz/QuizInstallationCard/WidgetSetupByType/BannerWidgetSetup/BannerWidgetSetup.tsx +++ b/src/pages/InstallQuiz/QuizInstallationCard/WidgetSetupByType/BannerWidgetSetup/BannerWidgetSetup.tsx @@ -24,6 +24,7 @@ import { ReactNode, useState } from "react"; import fixedButtonWidgetPreview from "../../../../../assets/banner-widget-preview.png"; import WidgetScript from "../../WidgetScript"; import { createBannerWidgetScriptText } from "../../createWidgetScriptText"; +import { useWidgetUrl } from "../../useWidgetUrl"; import BannerWidgetPreviewIcon from "./BannerWidgetPreviewIcon"; interface Props { @@ -35,6 +36,7 @@ export default function BannerWidgetSetup({ step, nextButton }: Props) { const theme = useTheme(); const isSmallMonitor = useMediaQuery(theme.breakpoints.down(1065)); const quiz = useCurrentQuiz(); + const widgetUrl = useWidgetUrl(); const [widgetWidth, setWidgetWidth] = useState(""); const [widgetHeight, setWidgetHeight] = useState(""); const [isAutoopenQuizSettingsOpen, setIsAutoopenQuizSettingsOpen] = useState(false); @@ -58,31 +60,34 @@ export default function BannerWidgetSetup({ step, nextButton }: Props) { if (!quiz) return null; if (step === 3) { - const scriptText = createBannerWidgetScriptText({ - quizId: quiz.qid, - position, - hideOnMobile: hideOnMobile || undefined, - rounded: bannerFullWidth ? undefined : rounded || undefined, - withShadow: withShadow || undefined, - buttonFlash: buttonFlash || undefined, - buttonBackgroundColor, - buttonTextColor, - autoShowQuizTime: autoShowQuiz ? autoShowQuizTime : undefined, - openOnLeaveAttempt: openOnLeaveAttempt || undefined, - bannerFullWidth: bannerFullWidth || undefined, - autoShowWidgetTime, - appealText: appealText || undefined, - quizHeaderText: quizHeaderText || undefined, - pulsation: pulsation || undefined, - fullScreen: fullScreen || undefined, - dialogDimensions: - !fullScreen && (widgetWidth || widgetHeight) - ? { - width: widgetWidth ? `${widgetWidth}px` : "100%", - height: widgetHeight ? `${widgetHeight}px` : "100%", - } - : undefined, - }); + const scriptText = createBannerWidgetScriptText( + { + quizId: quiz.qid, + position, + hideOnMobile: hideOnMobile || undefined, + rounded: bannerFullWidth ? undefined : rounded || undefined, + withShadow: withShadow || undefined, + buttonFlash: buttonFlash || undefined, + buttonBackgroundColor, + buttonTextColor, + autoShowQuizTime: autoShowQuiz ? autoShowQuizTime : undefined, + openOnLeaveAttempt: openOnLeaveAttempt || undefined, + bannerFullWidth: bannerFullWidth || undefined, + autoShowWidgetTime, + appealText: appealText || undefined, + quizHeaderText: quizHeaderText || undefined, + pulsation: pulsation || undefined, + fullScreen: fullScreen || undefined, + dialogDimensions: + !fullScreen && (widgetWidth || widgetHeight) + ? { + width: widgetWidth ? `${widgetWidth}px` : "100%", + height: widgetHeight ? `${widgetHeight}px` : "100%", + } + : undefined, + }, + widgetUrl + ); return ; } diff --git a/src/pages/InstallQuiz/QuizInstallationCard/WidgetSetupByType/ButtonWidgetSetup.tsx b/src/pages/InstallQuiz/QuizInstallationCard/WidgetSetupByType/ButtonWidgetSetup.tsx index 30c80bab..dbf76127 100644 --- a/src/pages/InstallQuiz/QuizInstallationCard/WidgetSetupByType/ButtonWidgetSetup.tsx +++ b/src/pages/InstallQuiz/QuizInstallationCard/WidgetSetupByType/ButtonWidgetSetup.tsx @@ -1,7 +1,4 @@ -import { - ButtonWidgetFixedParams, - ButtonWidgetParams, -} from "@frontend/squzanswerer"; +import { ButtonWidgetFixedParams, ButtonWidgetParams } from "@frontend/squzanswerer"; import { Box, Button, @@ -28,6 +25,7 @@ import Dots from "../../../../assets/dots.png"; import fixedButtonWidgetPreview from "../../../../assets/fixed-button-widget-preview.png"; import WidgetScript from "../WidgetScript"; import { createButtonWidgetScriptText } from "../createWidgetScriptText"; +import { useWidgetUrl } from "../useWidgetUrl"; interface Props { step: 2 | 3; @@ -38,25 +36,21 @@ export default function ButtonWidgetSetup({ step, nextButton }: Props) { const theme = useTheme(); const isSmallMonitor = useMediaQuery(theme.breakpoints.down(1065)); const quiz = useCurrentQuiz(); + const widgetUrl = useWidgetUrl(); const [widgetWidth, setWidgetWidth] = useState(""); const [widgetHeight, setWidgetHeight] = useState(""); - const [isAutoopenQuizSettingsOpen, setIsAutoopenQuizSettingsOpen] = - useState(false); + const [isAutoopenQuizSettingsOpen, setIsAutoopenQuizSettingsOpen] = useState(false); const [hideOnMobile, setHideOnMobile] = useState(false); const [rounded, setRounded] = useState(false); const [withShadow, setWithShadow] = useState(false); const [buttonFlash, setButtonFlash] = useState(false); const [buttonText, setButtonText] = useState(""); - const [buttonBackgroundColor, setButtonBackgroundColor] = useState( - theme.palette.brightPurple.main, - ); + const [buttonBackgroundColor, setButtonBackgroundColor] = useState(theme.palette.brightPurple.main); const [buttonTextColor, setButtonTextColor] = useState("#FFFFFF"); const [autoShowQuiz, setAutoShowQuiz] = useState(false); const [autoShowQuizTime, setAutoShowQuizTime] = useState(10); const [openOnLeaveAttempt, setOpenOnLeaveAttempt] = useState(false); - const [fixedSide, setFixedSide] = useState< - null | ButtonWidgetFixedParams["fixedSide"] - >(null); + const [fixedSide, setFixedSide] = useState(null); const [fullScreen, setFullScreen] = useState(false); if (!quiz) return null; @@ -96,7 +90,7 @@ export default function ButtonWidgetSetup({ step, nextButton }: Props) { }; } - const scriptText = createButtonWidgetScriptText(params); + const scriptText = createButtonWidgetScriptText(params, widgetUrl); return ( - - Ширина (px) - + Ширина (px) - - Высота (px) - + Высота (px) - - Цвет кнопки - - setButtonBackgroundColor(color)} - /> - - Цвет текста кнопки - - setButtonTextColor(color)} - /> + Цвет кнопки + setButtonBackgroundColor(color)} /> + Цвет текста кнопки + setButtonTextColor(color)} /> setHideOnMobile(e.target.checked)} /> - setRounded(e.target.checked)} - /> - setWithShadow(e.target.checked)} - /> + setRounded(e.target.checked)} /> + setWithShadow(e.target.checked)} /> { - setFixedSide( - e.target.value as ButtonWidgetFixedParams["fixedSide"], - ); + setFixedSide(e.target.value as ButtonWidgetFixedParams["fixedSide"]); }} > } icon={} /> - } + control={} icon={} />} label="Слева" sx={{ color: theme.palette.grey2.main, @@ -326,9 +294,7 @@ export default function ButtonWidgetSetup({ step, nextButton }: Props) { /> } icon={} /> - } + control={} icon={} />} label="Справа" sx={{ color: theme.palette.grey2.main, @@ -337,9 +303,7 @@ export default function ButtonWidgetSetup({ step, nextButton }: Props) { )} - - Текст кнопки - + Текст кнопки setButtonText(e.target.value)} @@ -399,22 +363,16 @@ export default function ButtonWidgetSetup({ step, nextButton }: Props) { alignItems: "center", }} > - - Показывать через - + Показывать через - setAutoShowQuizTime(parseInt(e.target.value)) - } + onChange={(e) => setAutoShowQuizTime(parseInt(e.target.value))} FormControlSx={{ width: "90px", }} /> - - секунд - + секунд diff --git a/src/pages/InstallQuiz/QuizInstallationCard/WidgetSetupByType/ContainerWidgetSetup.tsx b/src/pages/InstallQuiz/QuizInstallationCard/WidgetSetupByType/ContainerWidgetSetup.tsx index 7ef31b4b..a9553668 100644 --- a/src/pages/InstallQuiz/QuizInstallationCard/WidgetSetupByType/ContainerWidgetSetup.tsx +++ b/src/pages/InstallQuiz/QuizInstallationCard/WidgetSetupByType/ContainerWidgetSetup.tsx @@ -1,12 +1,4 @@ -import { - Box, - Button, - Collapse, - Divider, - Typography, - useMediaQuery, - useTheme, -} from "@mui/material"; +import { Box, Button, Collapse, Divider, Typography, useMediaQuery, useTheme } from "@mui/material"; import { useCurrentQuiz } from "@root/quizes/hooks"; import CircleColorPicker from "@ui_kit/CircleColorPicker"; import CustomCheckbox from "@ui_kit/CustomCheckbox"; @@ -16,6 +8,7 @@ import { ReactNode, useState } from "react"; import Dots from "../../../../assets/dots.png"; import WidgetScript from "../WidgetScript"; import { createContainerWidgetScriptText } from "../createWidgetScriptText"; +import { useWidgetUrl } from "../useWidgetUrl"; interface Props { step: 2 | 3; @@ -26,8 +19,8 @@ export default function ContainerWidgetSetup({ step, nextButton }: Props) { const theme = useTheme(); const isSmallMonitor = useMediaQuery(theme.breakpoints.down(1065)); const quiz = useCurrentQuiz(); - const [isAutoopenQuizSettingsOpen, setIsAutoopenQuizSettingsOpen] = - useState(false); + const widgetUrl = useWidgetUrl(); + const [isAutoopenQuizSettingsOpen, setIsAutoopenQuizSettingsOpen] = useState(false); const [widgetWidth, setWidgetWidth] = useState(""); const [widgetHeight, setWidgetHeight] = useState(""); const [hideOnMobile, setHideOnMobile] = useState(false); @@ -36,9 +29,7 @@ export default function ContainerWidgetSetup({ step, nextButton }: Props) { const [withShadow, setWithShadow] = useState(false); const [buttonFlash, setButtonFlash] = useState(false); const [buttonText, setButtonText] = useState(""); - const [buttonBackgroundColor, setButtonBackgroundColor] = useState( - theme.palette.brightPurple.main, - ); + const [buttonBackgroundColor, setButtonBackgroundColor] = useState(theme.palette.brightPurple.main); const [buttonTextColor, setButtonTextColor] = useState("#FFFFFF"); const [autoShowQuiz, setAutoShowQuiz] = useState(false); const [autoShowQuizTime, setAutoShowQuizTime] = useState(10); @@ -47,34 +38,32 @@ export default function ContainerWidgetSetup({ step, nextButton }: Props) { if (!quiz) return null; if (step === 3) { - const scriptText = createContainerWidgetScriptText({ - quizId: quiz.qid, - selector: `#pena-quiz-container-${nanoid(6)}`, - dimensions: - widgetWidth || widgetHeight - ? { - width: widgetWidth ? `${widgetWidth}px` : "100%", - height: widgetHeight ? `${widgetHeight}px` : "100%", - } - : undefined, - hideOnMobile: hideOnMobile || undefined, - showButtonOnMobile: showButtonOnMobile || undefined, - rounded: rounded || undefined, - withShadow: withShadow || undefined, - buttonFlash: buttonFlash || undefined, - buttonText: buttonText || undefined, - buttonBackgroundColor, - buttonTextColor, - autoShowQuizTime: autoShowQuiz ? autoShowQuizTime : undefined, - openOnLeaveAttempt: openOnLeaveAttempt || undefined, - }); - - return ( - + const scriptText = createContainerWidgetScriptText( + { + quizId: quiz.qid, + selector: `#pena-quiz-container-${nanoid(6)}`, + dimensions: + widgetWidth || widgetHeight + ? { + width: widgetWidth ? `${widgetWidth}px` : "100%", + height: widgetHeight ? `${widgetHeight}px` : "100%", + } + : undefined, + hideOnMobile: hideOnMobile || undefined, + showButtonOnMobile: showButtonOnMobile || undefined, + rounded: rounded || undefined, + withShadow: withShadow || undefined, + buttonFlash: buttonFlash || undefined, + buttonText: buttonText || undefined, + buttonBackgroundColor, + buttonTextColor, + autoShowQuizTime: autoShowQuiz ? autoShowQuizTime : undefined, + openOnLeaveAttempt: openOnLeaveAttempt || undefined, + }, + widgetUrl ); + + return ; } return ( @@ -139,15 +128,11 @@ export default function ContainerWidgetSetup({ step, nextButton }: Props) { maxWidth: "365px", }} > - Quiz будет открыть прямо в том месте, где вы установите код на - сайте + Quiz будет открыть прямо в том месте, где вы установите код на сайте - - В мобильной версии будет показана кнопка, открывающая quiz в - модальном окне + + В мобильной версии будет показана кнопка, открывающая quiz в модальном окне @@ -164,9 +149,7 @@ export default function ContainerWidgetSetup({ step, nextButton }: Props) { - - Ширина (px) - + Ширина (px) - - Высота (px) - + Высота (px) - - Цвет кнопки - - setButtonBackgroundColor(color)} - /> - - Цвет текста кнопки - - setButtonTextColor(color)} - /> + Цвет кнопки + setButtonBackgroundColor(color)} /> + Цвет текста кнопки + setButtonTextColor(color)} /> setHideOnMobile(e.target.checked)} /> - setRounded(e.target.checked)} - /> - setWithShadow(e.target.checked)} - /> + setRounded(e.target.checked)} /> + setWithShadow(e.target.checked)} /> setShowButtonOnMobile(e.target.checked)} /> - - Текст кнопки - + Текст кнопки setButtonText(e.target.value)} @@ -307,22 +268,16 @@ export default function ContainerWidgetSetup({ step, nextButton }: Props) { alignItems: "center", }} > - - Показывать через - + Показывать через - setAutoShowQuizTime(parseInt(e.target.value)) - } + onChange={(e) => setAutoShowQuizTime(parseInt(e.target.value))} FormControlSx={{ width: "90px", }} /> - - секунд - + секунд diff --git a/src/pages/InstallQuiz/QuizInstallationCard/WidgetSetupByType/PopupWidgetSetup.tsx b/src/pages/InstallQuiz/QuizInstallationCard/WidgetSetupByType/PopupWidgetSetup.tsx index dac7a5cc..6a4f3009 100644 --- a/src/pages/InstallQuiz/QuizInstallationCard/WidgetSetupByType/PopupWidgetSetup.tsx +++ b/src/pages/InstallQuiz/QuizInstallationCard/WidgetSetupByType/PopupWidgetSetup.tsx @@ -1,10 +1,4 @@ -import { - Box, - Collapse, - Typography, - useMediaQuery, - useTheme, -} from "@mui/material"; +import { Box, Collapse, Typography, useMediaQuery, useTheme } from "@mui/material"; import { useCurrentQuiz } from "@root/quizes/hooks"; import CustomCheckbox from "@ui_kit/CustomCheckbox"; import PenaTextField from "@ui_kit/PenaTextField"; @@ -12,6 +6,7 @@ import { ReactNode, useState } from "react"; import Dots from "../../../../assets/dots.png"; import WidgetScript from "../WidgetScript"; import { createPopupWidgetScriptText } from "../createWidgetScriptText"; +import { useWidgetUrl } from "../useWidgetUrl"; interface Props { step: 2 | 3; @@ -22,6 +17,7 @@ export default function PopupWidgetSetup({ step, nextButton }: Props) { const theme = useTheme(); const isSmallMonitor = useMediaQuery(theme.breakpoints.down(1065)); const quiz = useCurrentQuiz(); + const widgetUrl = useWidgetUrl(); const [widgetWidth, setWidgetWidth] = useState(""); const [widgetHeight, setWidgetHeight] = useState(""); const [hideOnMobile, setHideOnMobile] = useState(false); @@ -32,27 +28,25 @@ export default function PopupWidgetSetup({ step, nextButton }: Props) { if (!quiz) return null; if (step === 3) { - const scriptText = createPopupWidgetScriptText({ - quizId: quiz.qid, - hideOnMobile: hideOnMobile || undefined, - autoShowQuizTime: autoShowQuizTime, - openOnLeaveAttempt: openOnLeaveAttempt || undefined, - fullScreen: fullScreen || undefined, - dialogDimensions: - !fullScreen && (widgetWidth || widgetHeight) - ? { - width: widgetWidth ? `${widgetWidth}px` : "100%", - height: widgetHeight ? `${widgetHeight}px` : "100%", - } - : undefined, - }); - - return ( - + const scriptText = createPopupWidgetScriptText( + { + quizId: quiz.qid, + hideOnMobile: hideOnMobile || undefined, + autoShowQuizTime: autoShowQuizTime, + openOnLeaveAttempt: openOnLeaveAttempt || undefined, + fullScreen: fullScreen || undefined, + dialogDimensions: + !fullScreen && (widgetWidth || widgetHeight) + ? { + width: widgetWidth ? `${widgetWidth}px` : "100%", + height: widgetHeight ? `${widgetHeight}px` : "100%", + } + : undefined, + }, + widgetUrl ); + + return ; } return ( @@ -147,9 +141,7 @@ export default function PopupWidgetSetup({ step, nextButton }: Props) { gap: "20px", }} > - - Ширина окна (px) - + Ширина окна (px) - - Высота окна (px) - + Высота окна (px) - - Показывать через - + Показывать через - - секунд - + секунд (""); const [widgetHeight, setWidgetHeight] = useState(""); const [hideOnMobile, setHideOnMobile] = useState(false); const [autoShowQuiz, setAutoShowQuiz] = useState(false); const [autoShowQuizTime, setAutoShowQuizTime] = useState(10); const [autoShowWidgetTime, setAutoShowWidgetTime] = useState(10); - const [position, setPosition] = - useState("left"); + const [position, setPosition] = useState("left"); const [fullScreen, setFullScreen] = useState(false); const [buttonFlash, setButtonFlash] = useState(false); - const [buttonBackgroundColor, setButtonBackgroundColor] = useState( - theme.palette.brightPurple.main, - ); + const [buttonBackgroundColor, setButtonBackgroundColor] = useState(theme.palette.brightPurple.main); const [buttonTextColor, setButtonTextColor] = useState("#FFFFFF"); if (!quiz) return null; if (step === 3) { - const scriptText = createSideWidgetScriptText({ - quizId: quiz.qid, - position: position, - hideOnMobile: hideOnMobile || undefined, - autoShowQuizTime: autoShowQuiz ? autoShowQuizTime : undefined, - autoShowWidgetTime: autoShowWidgetTime || undefined, - fullScreen: fullScreen || undefined, - buttonFlash: buttonFlash || undefined, - buttonTextColor, - buttonBackgroundColor, - dialogDimensions: - !fullScreen && (widgetWidth || widgetHeight) - ? { - width: widgetWidth ? `${widgetWidth}px` : "100%", - height: widgetHeight ? `${widgetHeight}px` : "100%", - } - : undefined, - }); - - return ( - + const scriptText = createSideWidgetScriptText( + { + quizId: quiz.qid, + position: position, + hideOnMobile: hideOnMobile || undefined, + autoShowQuizTime: autoShowQuiz ? autoShowQuizTime : undefined, + autoShowWidgetTime: autoShowWidgetTime || undefined, + fullScreen: fullScreen || undefined, + buttonFlash: buttonFlash || undefined, + buttonTextColor, + buttonBackgroundColor, + dialogDimensions: + !fullScreen && (widgetWidth || widgetHeight) + ? { + width: widgetWidth ? `${widgetWidth}px` : "100%", + height: widgetHeight ? `${widgetHeight}px` : "100%", + } + : undefined, + }, + widgetUrl ); + + return ; } return ( @@ -92,11 +83,7 @@ export default function SideWidgetSetup({ step, nextButton }: Props) { }} > setPosition("left")} /> - - Слева снизу - + Слева снизу setPosition("right")} /> - - Справа снизу - + Справа снизу - - Ширина окна (px) - + Ширина окна (px) - - Высота окна (px) - + Высота окна (px) - - Цвет кнопки - - setButtonBackgroundColor(color)} - /> - - Цвет текста кнопки - - setButtonTextColor(color)} - /> + Цвет кнопки + setButtonBackgroundColor(color)} /> + Цвет текста кнопки + setButtonTextColor(color)} /> - - Показывать кнопку через - + Показывать кнопку через - - секунд - + секунд - setButtonFlash(e.target.checked)} - /> + setButtonFlash(e.target.checked)} /> - - Показывать через - + Показывать через - - секунд - + секунд `; } -export function createButtonWidgetScriptText( - params: ButtonWidgetParams | ButtonWidgetFixedParams, -) { - const widgetClassName = - "fixedSide" in params ? "ButtonWidgetFixed" : "ButtonWidget"; +export function createButtonWidgetScriptText(params: ButtonWidgetParams | ButtonWidgetFixedParams, widgetUrl: string) { + const widgetClassName = "fixedSide" in params ? "ButtonWidgetFixed" : "ButtonWidget"; return `${"selector" in params ? `
\n` : ""}`; } -export function createPopupWidgetScriptText(params: PopupWidgetParams) { +export function createPopupWidgetScriptText(params: PopupWidgetParams, widgetUrl: string) { return ``; } -export function createSideWidgetScriptText(params: SideWidgetParams) { +export function createSideWidgetScriptText(params: SideWidgetParams, widgetUrl: string) { return ``; } -export function createBannerWidgetScriptText(params: BannerWidgetParams) { +export function createBannerWidgetScriptText(params: BannerWidgetParams, widgetUrl: string) { return ``; diff --git a/src/pages/InstallQuiz/QuizInstallationCard/useWidgetUrl.ts b/src/pages/InstallQuiz/QuizInstallationCard/useWidgetUrl.ts new file mode 100644 index 00000000..b1a6027f --- /dev/null +++ b/src/pages/InstallQuiz/QuizInstallationCard/useWidgetUrl.ts @@ -0,0 +1,7 @@ +import { useDomainDefine } from "@/utils/hooks/useDomainDefine"; + +export function useWidgetUrl() { + const { isTestServer } = useDomainDefine(); + + return `https://${isTestServer ? "s." : ""}hbpn.link/export/pub.js`; +}