link-stack/apps/link/components/ZammadWrapper.tsx

52 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-12-02 17:45:14 +01:00
import { FC, useState } from "react";
import Iframe from "react-iframe";
type ZammadWrapperProps = {
2023-02-22 13:05:52 +00:00
path: string;
2022-12-02 17:45:14 +01:00
hideSidebar?: boolean;
};
export const ZammadWrapper: FC<ZammadWrapperProps> = ({
2023-02-22 13:05:52 +00:00
path,
2022-12-02 17:45:14 +01:00
hideSidebar = true,
}) => {
2023-02-22 13:05:52 +00:00
const [display, setDisplay] = useState("hidden");
const url = `https://redaranj-bookish-tribble-56jwjx5wh4j4w-8003.preview.app.github.dev/zammad${path}`;
console.log({ base: process.env.LINK_URL, path, url })
2022-12-02 17:45:14 +01:00
return (
2023-02-22 13:05:52 +00:00
< Iframe
2022-12-02 17:45:14 +01:00
id="link"
url={url}
width="100%"
height="100%"
frameBorder={0}
2023-02-22 13:05:52 +00:00
styles={{ display }
}
2022-12-02 17:45:14 +01:00
onLoad={() => {
const linkElement = document.querySelector("iframe");
if (
linkElement.contentDocument &&
2023-01-11 16:18:56 +01:00
linkElement.contentDocument?.querySelector &&
linkElement.contentDocument.querySelector("#navigation") &&
linkElement.contentDocument.querySelector("body") &&
linkElement.contentDocument.querySelector(".sidebar")
2022-12-02 17:45:14 +01:00
) {
// @ts-ignore
linkElement.contentDocument.querySelector("#navigation").style =
"display: none";
2022-12-14 13:24:50 +01:00
// @ts-ignore
linkElement.contentDocument.querySelector("body").style =
"font-family: Arial";
2022-12-02 17:45:14 +01:00
if (hideSidebar) {
// @ts-ignore
linkElement.contentDocument.querySelector(".sidebar").style =
"display: none";
}
}
2023-01-11 16:18:56 +01:00
setDisplay("inherit");
2022-12-02 17:45:14 +01:00
}}
/>
);
};