генерация ссылки на тест в зависимости от домена

This commit is contained in:
Tamara 2024-02-01 01:31:51 +03:00
parent 29b5779b8e
commit 737cc61cf7
2 changed files with 34 additions and 4 deletions

@ -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}`}
</Box>
) : (
<Box
@ -226,7 +234,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
}
>
<LinkSimple />
</Box>
@ -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
}
>
<LinkSimple />
</Box>

@ -0,0 +1,14 @@
import { useEffect, useState } from "react";
export function useDomainDefine(): { isTestServer: boolean } {
const [isTestServer, setIsTestServer] = useState<boolean>(null);
useEffect(() => {
const host = window.location.hostname;
let isTest = host.includes("s");
console.log("эта консольложь в хуке", isTest);
setIsTestServer(isTest);
}, []);
return { isTestServer };
}