Middleware and login updates
This commit is contained in:
parent
484e8689a4
commit
4517241ead
23 changed files with 144 additions and 112 deletions
|
|
@ -1,54 +0,0 @@
|
|||
import Head from "next/head";
|
||||
import { NextPage, GetServerSideProps, GetServerSidePropsContext } from "next";
|
||||
import { Grid, Box } from "@mui/material";
|
||||
import { Layout } from "components/Layout";
|
||||
import { TicketDetail } from "components/TicketDetail";
|
||||
import { TicketEdit } from "components/TicketEdit";
|
||||
|
||||
const Link: NextPage = ({ ticket, articles }: any) => (
|
||||
<Layout>
|
||||
<Head>
|
||||
<title>Link Shell</title>
|
||||
</Head>
|
||||
<Grid container spacing={0} sx={{ height: "100vh" }} direction="row">
|
||||
<Grid item sx={{ height: "100vh" }} xs={10}>
|
||||
<TicketDetail ticket={ticket} articles={articles} />
|
||||
</Grid>
|
||||
<Grid item xs={2} sx={{ height: "100vh" }}>
|
||||
<TicketEdit ticket={ticket} />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Layout>
|
||||
);
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (
|
||||
context: GetServerSidePropsContext
|
||||
) => {
|
||||
const {
|
||||
params: { id },
|
||||
} = context;
|
||||
const baseURL = `${process.env.ZAMMAD_URL}/api/v1`;
|
||||
const token = process.env.ZAMMAD_API_TOKEN;
|
||||
const headers = { Authorization: `Token ${token}` };
|
||||
const rawTicket = await fetch(`${baseURL}/tickets/${id}`, {
|
||||
headers,
|
||||
});
|
||||
const ticket = await rawTicket.json();
|
||||
const rawArticles = await fetch(
|
||||
`${baseURL}/ticket_articles/by_ticket/${id}`,
|
||||
{
|
||||
headers,
|
||||
}
|
||||
);
|
||||
const articles = await rawArticles.json();
|
||||
|
||||
console.log({ ticket, articles });
|
||||
|
||||
return {
|
||||
props: {
|
||||
ticket,
|
||||
articles,
|
||||
},
|
||||
};
|
||||
};
|
||||
export default Link;
|
||||
58
apps/link/pages/tickets/[id].tsx
Normal file
58
apps/link/pages/tickets/[id].tsx
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import { GetServerSideProps, GetServerSidePropsContext } from "next";
|
||||
import Head from "next/head";
|
||||
import useSWR from "swr";
|
||||
import { NextPage } from "next";
|
||||
import { Grid, } from "@mui/material";
|
||||
import { Layout } from "components/Layout";
|
||||
import { TicketDetail } from "components/TicketDetail";
|
||||
import { TicketEdit } from "components/TicketEdit";
|
||||
|
||||
type TicketProps = {
|
||||
id: string;
|
||||
};
|
||||
|
||||
const Ticket: NextPage<TicketProps> = ({ id }) => {
|
||||
const fetcher = async (url: string) => {
|
||||
const res = await fetch(url);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
const { data: ticketData, error: ticketError } = useSWR(
|
||||
`https://redaranj-bookish-tribble-56jwjx5wh4j4w-8003.preview.app.github.dev/api/v1/tickets/${id}`,
|
||||
fetcher
|
||||
);
|
||||
|
||||
const { data: articlesData, error: articlesError } = useSWR(
|
||||
`https://redaranj-bookish-tribble-56jwjx5wh4j4w-8003.preview.app.github.dev/api/v1/ticket_articles/by_ticket/${id}`,
|
||||
fetcher
|
||||
);
|
||||
|
||||
const shouldRender = !ticketError && !articlesError && ticketData && articlesData && !ticketData.error && !articlesData.error;
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<Head>
|
||||
<title>Link Shell</title>
|
||||
</Head>
|
||||
{shouldRender && (
|
||||
<Grid container spacing={0} sx={{ height: "100vh" }} direction="row">
|
||||
<Grid item sx={{ height: "100vh" }} xs={10}>
|
||||
|
||||
<TicketDetail ticket={ticketData} articles={articlesData} />
|
||||
</Grid>
|
||||
<Grid item xs={2} sx={{ height: "100vh" }}>
|
||||
<TicketEdit ticket={ticketData} />
|
||||
</Grid>
|
||||
</Grid>)}
|
||||
{ticketError && <div>{ticketError.toString()}</div>}
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (
|
||||
context: GetServerSidePropsContext) => {
|
||||
const { id } = context.query;
|
||||
return { props: { id } };
|
||||
}
|
||||
|
||||
export default Ticket;
|
||||
|
|
@ -21,7 +21,7 @@ const Link = () => (
|
|||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<ZammadWrapper url="http://localhost:8003/zammad/#ticket/view/my_tickets" />
|
||||
<ZammadWrapper path="/#ticket/view/my_tickets" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Layout>
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ const Link = () => (
|
|||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<ZammadWrapper url="http://localhost:3000/zammad/#ticket/view/my_pending_reached" />
|
||||
<ZammadWrapper path="/#ticket/view/my_pending_reached" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Layout>
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ const Link = () => (
|
|||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<ZammadWrapper url="http://localhost:3000/zammad/#ticket/view/all_unassigned" />
|
||||
<ZammadWrapper path="/#ticket/view/all_unassigned" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Layout>
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ const Link = () => (
|
|||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<ZammadWrapper url="http://localhost:3000/zammad/#ticket/view/all_escalated" />
|
||||
<ZammadWrapper path="/#ticket/view/all_escalated" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Layout>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue