Build and type fixes

This commit is contained in:
Darren Clarke 2023-05-24 20:27:57 +00:00
parent d5bd58ac3e
commit 656f3fbe71
64 changed files with 1878 additions and 1501 deletions

View file

@ -0,0 +1,76 @@
import { FC, useState } from "react";
import { useRouter } from "next/router";
import Iframe from "react-iframe";
type InternalZammadWrapperProps = {
path: string;
hideSidebar?: boolean;
};
export const InternalZammadWrapper: FC<InternalZammadWrapperProps> = ({
path,
hideSidebar = true,
}) => {
const router = useRouter();
const [display, setDisplay] = useState("none");
const url = `${origin}/zammad${path}`;
console.log({ origin, path, url });
return (
// @ts-ignore
<Iframe
id="link"
url={url}
width="100%"
height="100%"
frameBorder={0}
styles={{ display }}
onLoad={() => {
const linkElement = document.querySelector("iframe");
if (
linkElement.contentDocument &&
linkElement.contentDocument?.querySelector &&
linkElement.contentDocument.querySelector("#navigation") &&
linkElement.contentDocument.querySelector("body") &&
linkElement.contentDocument.querySelector(".sidebar")
) {
// @ts-ignore
linkElement.contentDocument.querySelector("#navigation").style =
"display: none";
// @ts-ignore
linkElement.contentDocument.querySelector("body").style =
"font-family: Arial";
if (hideSidebar) {
// @ts-ignore
linkElement.contentDocument.querySelector(".sidebar").style =
"display: none";
}
// @ts-ignore
if (linkElement.contentDocument.querySelector(".overview-header")) {
// @ts-ignore
linkElement.contentDocument.querySelector(".overview-header").style =
"display: none";
}
setDisplay("inherit");
if (linkElement.contentWindow) {
linkElement.contentWindow.addEventListener('hashchange', () => {
const hash = linkElement.contentWindow?.location?.hash ?? ""
if (hash.startsWith("#ticket/zoom/")) {
setDisplay("none");
const ticketID = hash.split("/").pop();
router.push(`/tickets/${ticketID}`);
setTimeout(() => {
setDisplay("inherit");
}, 1000);
}
});
}
}
}}
/>
);
};

View file

@ -1,6 +1,12 @@
import { FC, useState } from "react";
import { useRouter } from "next/router";
import Iframe from "react-iframe";
import { FC } from "react";
import dynamic from "next/dynamic";
const InternalZammadWrapper = dynamic(
import("./InternalZammadWrapper").then((mod) => mod.InternalZammadWrapper),
{
ssr: false,
}
);
type ZammadWrapperProps = {
path: string;
@ -9,72 +15,5 @@ type ZammadWrapperProps = {
export const ZammadWrapper: FC<ZammadWrapperProps> = ({
path,
hideSidebar = true,
}) => {
const router = useRouter();
const origin =
typeof window !== "undefined" && window.location.origin
? window.location.origin
: "";
const [display, setDisplay] = useState("none");
const url = `${origin}/zammad${path}`;
console.log({ origin, path, url });
return (
// @ts-ignore
<Iframe
id="link"
url={url}
width="100%"
height="100%"
frameBorder={0}
styles={{ display }}
onLoad={() => {
const linkElement = document.querySelector("iframe");
if (
linkElement.contentDocument &&
linkElement.contentDocument?.querySelector &&
linkElement.contentDocument.querySelector("#navigation") &&
linkElement.contentDocument.querySelector("body") &&
linkElement.contentDocument.querySelector(".sidebar")
) {
// @ts-ignore
linkElement.contentDocument.querySelector("#navigation").style =
"display: none";
// @ts-ignore
linkElement.contentDocument.querySelector("body").style =
"font-family: Arial";
if (hideSidebar) {
// @ts-ignore
linkElement.contentDocument.querySelector(".sidebar").style =
"display: none";
}
// @ts-ignore
if (linkElement.contentDocument.querySelector(".overview-header")) {
// @ts-ignore
linkElement.contentDocument.querySelector(".overview-header").style =
"display: none";
}
setDisplay("inherit");
if (linkElement.contentWindow) {
linkElement.contentWindow.addEventListener('hashchange', () => {
const hash = linkElement.contentWindow?.location?.hash ?? ""
if (hash.startsWith("#ticket/zoom/")) {
setDisplay("none");
const ticketID = hash.split("/").pop();
router.push(`/tickets/${ticketID}`);
setTimeout(() => {
setDisplay("inherit");
}, 1000);
}
});
}
}
}}
/>
);
};
hideSidebar,
}) => <InternalZammadWrapper path={path} hideSidebar={hideSidebar} />;

30
apps/link/middleware.ts Normal file
View file

@ -0,0 +1,30 @@
import { withAuth } from "next-auth/middleware";
export default withAuth(
() => { },
{
pages: {
signIn: `/login`,
},
callbacks: {
authorized: ({ token, req }) => {
const {
url,
headers,
} = req;
// check login page
const parsedURL = new URL(url);
if (parsedURL.pathname.startsWith('/login')) {
return true;
}
// check session auth
const authorizedDomains = ["redaranj.com", "digiresilience.org"];
const userDomain = token?.email?.toLowerCase().split("@").pop() ?? "unauthorized.net";
return false;
},
}
}
);

View file

@ -1,4 +1,5 @@
module.exports = {
reactStrictMode: true,
rewrites: async () => ({
fallback: [
{

View file

@ -11,45 +11,45 @@
"dependencies": {
"@chatscope/chat-ui-kit-react": "^1.10.1",
"@chatscope/chat-ui-kit-styles": "^1.4.0",
"@emotion/cache": "^11.10.5",
"@emotion/react": "^11.10.5",
"@emotion/server": "^11.10.0",
"@emotion/styled": "^11.10.5",
"@fontsource/playfair-display": "^4.5.13",
"@fontsource/poppins": "^4.5.10",
"@fontsource/roboto": "^4.5.8",
"@emotion/cache": "^11.11.0",
"@emotion/react": "^11.11.0",
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.11.0",
"@fontsource/playfair-display": "^5.0.1",
"@fontsource/poppins": "^5.0.1",
"@fontsource/roboto": "^5.0.1",
"@mui/icons-material": "^5",
"@mui/lab": "^5.0.0-alpha.118",
"@mui/lab": "^5.0.0-alpha.131",
"@mui/material": "^5",
"@mui/x-data-grid-pro": "^5.17.22",
"@mui/x-date-pickers-pro": "^5.0.17",
"date-fns": "^2.29.3",
"graphql-request": "^5.2.0",
"@mui/x-data-grid-pro": "^6.5.0",
"@mui/x-date-pickers-pro": "^6.5.0",
"date-fns": "^2.30.0",
"graphql-request": "^6.1.0",
"http-proxy-middleware": "^2.0.6",
"material-ui-popup-state": "^5.0.4",
"next": "^12",
"next-auth": "^4.19.2",
"material-ui-popup-state": "^5.0.8",
"next": "^13",
"next-auth": "^4.22.1",
"next-http-proxy-middleware": "^1.2.5",
"react": "^17",
"react-dom": "^17",
"react": "^18",
"react-dom": "^18",
"react-iframe": "^1.8.5",
"react-polyglot": "^0.7.2",
"sharp": "^0.30.7",
"swr": "^2.0.3"
"sharp": "^0.32.1",
"swr": "^2.1.5"
},
"devDependencies": {
"@babel/core": "^7.20.12",
"@babel/core": "^7.21.8",
"@types/react": "^18",
"@types/uuid": "^9.0.0",
"@types/uuid": "^9.0.1",
"babel-loader": "^9.1.2",
"eslint": "^8.33.0",
"eslint": "^8.41.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-next": "^13.1.6",
"eslint-config-prettier": "^8.6.0",
"eslint-config-next": "^13.4.3",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.32.2",
"typescript": "^4.9.5"
"typescript": "^5.0.4"
}
}

13
apps/link/pages/404.tsx Normal file
View file

@ -0,0 +1,13 @@
import { FC } from "react";
import Head from "next/head";
import { Layout } from "components/Layout";
const FourOhFour: FC = () => (
<Layout>
<Head>
<title>Link Shell</title>
</Head>
</Layout>
);
export default FourOhFour;

13
apps/link/pages/500.tsx Normal file
View file

@ -0,0 +1,13 @@
import { FC } from "react";
import Head from "next/head";
import { Layout } from "components/Layout";
const FiveHundred: FC = () => (
<Layout>
<Head>
<title>Link Shell</title>
</Head>
</Layout>
);
export default FiveHundred;

View file

@ -17,9 +17,7 @@ import { LicenseInfo } from "@mui/x-data-grid-pro";
import { SWRConfig } from "swr";
import { GraphQLClient } from "graphql-request";
LicenseInfo.setLicenseKey(
"fd009c623acc055adb16370731be92e4T1JERVI6NDA3NTQsRVhQSVJZPTE2ODAyNTAwMTUwMDAsS0VZVkVSU0lPTj0x"
);
LicenseInfo.setLicenseKey(process.env.MUI_LICENSE_KEY);
const clientSideEmotionCache: any = createEmotionCache();
@ -28,15 +26,18 @@ interface LinkWebProps extends AppProps {
emotionCache?: EmotionCache;
}
const LinkWeb = (props: LinkWebProps) => {
export default function LinkWeb(props: LinkWebProps) {
const { Component, emotionCache = clientSideEmotionCache, pageProps } = props;
const [csrfToken, setCsrfToken] = useState("");
const origin = typeof window !== 'undefined' && window.location.origin
? window.location.origin : null;
const origin =
typeof window !== "undefined" && window.location.origin
? window.location.origin
: null;
const client = new GraphQLClient(`${origin}/graphql`, {
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
Accept: "application/json",
},
});
const graphQLFetcher = async ({ document, variables }: any) => {
@ -49,7 +50,7 @@ const LinkWeb = (props: LinkWebProps) => {
requestHeaders
);
const token = headers.get('CSRF-Token');
const token = headers.get("CSRF-Token");
setCsrfToken(token);
return data;
@ -67,6 +68,4 @@ const LinkWeb = (props: LinkWebProps) => {
</CacheProvider>
</SessionProvider>
);
};
export default LinkWeb;
}

View file

@ -1,4 +1,3 @@
// @ts-nocheck
import { FC } from "react";
import Head from "next/head";
import { Grid } from "@mui/material";
@ -30,3 +29,5 @@ const LabelStudio: FC = () => (
);
export default LabelStudio;
export const getServerSideProps = async (context: any) => {};

View file

@ -1,4 +1,3 @@
// @ts-nocheck
import { FC } from "react";
import Head from "next/head";
import { Grid } from "@mui/material";
@ -30,3 +29,5 @@ const Metamigo: FC = () => (
);
export default Metamigo;
export const getServerSideProps = async (context: any) => {};

View file

@ -29,3 +29,5 @@ const Zammad: FC = () => (
);
export default Zammad;
export const getServerSideProps = async (context: any) => {};

View file

@ -28,3 +28,5 @@ const Home = () => (
);
export default Home;
export const getServerSideProps = async (context: any) => {};

View file

@ -1,7 +1,6 @@
// @ts-nocheck
import { FC, useState } from "react";
import Head from "next/head";
import { Grid, Button } from "@mui/material";
import { Grid } from "@mui/material";
import { Layout } from "components/Layout";
import Iframe from "react-iframe";
@ -35,3 +34,5 @@ const About: FC = () => {
};
export default About;
export const getServerSideProps = async (context: any) => {};

View file

@ -35,3 +35,5 @@ const Create: FC = () => {
};
export default Create;
export const getServerSideProps = async (context: any) => {};

View file

@ -35,3 +35,5 @@ const FAQ: FC = () => {
};
export default FAQ;
export const getServerSideProps = async (context: any) => {};

View file

@ -1,4 +1,3 @@
// @ts-nocheck
import { FC, useState } from "react";
import Head from "next/head";
import { Grid, Button } from "@mui/material";
@ -35,3 +34,5 @@ const Leafcutter: FC = () => {
};
export default Leafcutter;
export const getServerSideProps = async (context: any) => {};

View file

@ -35,3 +35,5 @@ const Trends: FC = () => {
};
export default Trends;
export const getServerSideProps = async (context: any) => {};

View file

@ -1,30 +0,0 @@
import Head from "next/head";
import { Grid } from "@mui/material";
import { Layout } from "components/Layout";
import { ZammadWrapper } from "components/ZammadWrapper";
const Link = () => (
<Layout>
<Head>
<title>Link Shell</title>
</Head>
<Grid
container
spacing={0}
sx={{ height: "100%", width: "100%" }}
direction="column"
>
<Grid
item
sx={{
height: "100%",
width: "100%",
}}
>
<ZammadWrapper path="/zammad/#ticket/zoom/518/1490" />
</Grid>
</Grid>
</Layout>
);
export default Link;

View file

@ -1,12 +1,18 @@
import Head from "next/head";
import { FC } from "react";
import { Box, Grid, Container, IconButton } from "@mui/material";
import { Apple as AppleIcon, Google as GoogleIcon } from "@mui/icons-material";
import { signIn, getSession } from "next-auth/react";
const Login = ({ session }) => {
const origin = typeof window !== 'undefined' && window.location.origin
type LoginProps = {
session: any;
};
const Login: FC<LoginProps> = ({ session }) => {
const origin =
typeof window !== "undefined" && window.location.origin
? window.location.origin
: '';
: "";
const buttonStyles = {
borderRadius: 500,
width: "100%",

View file

@ -29,3 +29,5 @@ const Profile: NextPage = () => (
);
export default Profile;
export const getServerSideProps = async (context: any) => {};

View file

@ -29,3 +29,5 @@ const Assigned: FC = () => (
);
export default Assigned;
export const getServerSideProps = async (context: any) => {};

View file

@ -29,3 +29,5 @@ const Pending: FC = () => (
);
export default Pending;
export const getServerSideProps = async (context: any) => {};

View file

@ -29,3 +29,5 @@ const Unassigned: FC = () => (
);
export default Unassigned;
export const getServerSideProps = async (context: any) => {};

View file

@ -29,3 +29,5 @@ const Urgent: FC = () => (
);
export default Urgent;
export const getServerSideProps = async (context: any) => {};