From 737cc61cf7d5f46adfd770b2bfc31064bae28a41 Mon Sep 17 00:00:00 2001 From: Tamara Date: Thu, 1 Feb 2024 01:31:51 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=82=D0=B5=D1=81=D1=82=20=D0=B2=20=D0=B7=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D0=B8=20=D0=BE=D1=82?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=BC=D0=B5=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/main.tsx | 24 ++++++++++++++++++++---- src/utils/hooks/useDomainDefine.ts | 14 ++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 src/utils/hooks/useDomainDefine.ts diff --git a/src/pages/main.tsx b/src/pages/main.tsx index 14cb34a1..f27494a5 100755 --- a/src/pages/main.tsx +++ b/src/pages/main.tsx @@ -22,6 +22,7 @@ import { questionApi } from "@api/question"; import { createResult, setQuestions } from "@root/questions/actions"; import { toggleQuizPreview } from "@root/quizPreview"; import VisibilityIcon from "@mui/icons-material/Visibility"; +import { useDomainDefine } from "@utils/hooks/useDomainDefine"; interface Props { sidebar: boolean; @@ -37,6 +38,7 @@ export default function Main({ sidebar, header, footer, Page }: Props) { const { questions } = useQuestionsStore(); const { editQuizId } = useQuizStore(); const currentStep = useQuizStore((state) => state.currentStep); + const { isTestServer } = useDomainDefine(); useEffect(() => { const getData = async () => { @@ -205,9 +207,15 @@ export default function Main({ sidebar, header, footer, Page }: Props) { fontSize: "14px", }} target="_blank" - to={"https://s.hbpn.link/" + quiz.qid} + to={ + isTestServer + ? "https://s.hbpn.link/" + quiz.qid + : "https://hbpn.link/" + quiz.qid + } > - https://s.hbpn.link/{quiz.qid} + {isTestServer + ? `https://s.hbpn.link/${quiz.qid}` + : `https://hbpn.link/${quiz.qid}`} ) : ( @@ -249,7 +261,11 @@ export default function Main({ sidebar, header, footer, Page }: Props) { borderRadius: "8px", }} target="_blank" - to={"https://s.hbpn.link/" + quiz.qid} + to={ + isTestServer + ? "https://s.hbpn.link/" + quiz.qid + : "https://hbpn.link/" + quiz.qid + } > diff --git a/src/utils/hooks/useDomainDefine.ts b/src/utils/hooks/useDomainDefine.ts new file mode 100644 index 00000000..5ef43c69 --- /dev/null +++ b/src/utils/hooks/useDomainDefine.ts @@ -0,0 +1,14 @@ +import { useEffect, useState } from "react"; + +export function useDomainDefine(): { isTestServer: boolean } { + const [isTestServer, setIsTestServer] = useState(null); + + useEffect(() => { + const host = window.location.hostname; + let isTest = host.includes("s"); + console.log("эта консольложь в хуке", isTest); + setIsTestServer(isTest); + }, []); + + return { isTestServer }; +}