генерация ссылки на тест в зависимости от домена
This commit is contained in:
parent
29b5779b8e
commit
737cc61cf7
@ -22,6 +22,7 @@ import { questionApi } from "@api/question";
|
|||||||
import { createResult, setQuestions } from "@root/questions/actions";
|
import { createResult, setQuestions } from "@root/questions/actions";
|
||||||
import { toggleQuizPreview } from "@root/quizPreview";
|
import { toggleQuizPreview } from "@root/quizPreview";
|
||||||
import VisibilityIcon from "@mui/icons-material/Visibility";
|
import VisibilityIcon from "@mui/icons-material/Visibility";
|
||||||
|
import { useDomainDefine } from "@utils/hooks/useDomainDefine";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
sidebar: boolean;
|
sidebar: boolean;
|
||||||
@ -37,6 +38,7 @@ export default function Main({ sidebar, header, footer, Page }: Props) {
|
|||||||
const { questions } = useQuestionsStore();
|
const { questions } = useQuestionsStore();
|
||||||
const { editQuizId } = useQuizStore();
|
const { editQuizId } = useQuizStore();
|
||||||
const currentStep = useQuizStore((state) => state.currentStep);
|
const currentStep = useQuizStore((state) => state.currentStep);
|
||||||
|
const { isTestServer } = useDomainDefine();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const getData = async () => {
|
const getData = async () => {
|
||||||
@ -205,9 +207,15 @@ export default function Main({ sidebar, header, footer, Page }: Props) {
|
|||||||
fontSize: "14px",
|
fontSize: "14px",
|
||||||
}}
|
}}
|
||||||
target="_blank"
|
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>
|
||||||
) : (
|
) : (
|
||||||
<Box
|
<Box
|
||||||
@ -226,7 +234,11 @@ export default function Main({ sidebar, header, footer, Page }: Props) {
|
|||||||
borderRadius: "8px",
|
borderRadius: "8px",
|
||||||
}}
|
}}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
to={"https://s.hbpn.link/" + quiz.qid}
|
to={
|
||||||
|
isTestServer
|
||||||
|
? "https://s.hbpn.link/" + quiz.qid
|
||||||
|
: "https://hbpn.link/" + quiz.qid
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<LinkSimple />
|
<LinkSimple />
|
||||||
</Box>
|
</Box>
|
||||||
@ -249,7 +261,11 @@ export default function Main({ sidebar, header, footer, Page }: Props) {
|
|||||||
borderRadius: "8px",
|
borderRadius: "8px",
|
||||||
}}
|
}}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
to={"https://s.hbpn.link/" + quiz.qid}
|
to={
|
||||||
|
isTestServer
|
||||||
|
? "https://s.hbpn.link/" + quiz.qid
|
||||||
|
: "https://hbpn.link/" + quiz.qid
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<LinkSimple />
|
<LinkSimple />
|
||||||
</Box>
|
</Box>
|
||||||
|
14
src/utils/hooks/useDomainDefine.ts
Normal file
14
src/utils/hooks/useDomainDefine.ts
Normal file
@ -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 };
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user