2023-02-22 13:05:52 +00:00
|
|
|
import { GetServerSideProps, GetServerSidePropsContext } from "next";
|
|
|
|
|
import Head from "next/head";
|
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
import { NextPage } from "next";
|
2023-03-15 12:17:43 +00:00
|
|
|
import { Grid } from "@mui/material";
|
2023-02-22 13:05:52 +00:00
|
|
|
import { Layout } from "components/Layout";
|
|
|
|
|
import { TicketDetail } from "components/TicketDetail";
|
2023-03-22 11:55:14 +00:00
|
|
|
import { TicketEdit } from "components/TicketEdit";
|
2023-03-29 14:43:27 +02:00
|
|
|
import { getTicketQuery } from "graphql/getTicketQuery";
|
2023-02-22 13:05:52 +00:00
|
|
|
|
|
|
|
|
type TicketProps = {
|
|
|
|
|
id: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Ticket: NextPage<TicketProps> = ({ id }) => {
|
2023-03-07 14:09:49 +00:00
|
|
|
const { data: ticketData, error: ticketError }: any = useSWR(
|
|
|
|
|
{
|
2023-03-29 14:43:27 +02:00
|
|
|
document: getTicketQuery,
|
|
|
|
|
variables: { ticketId: `gid://zammad/Ticket/${id}` },
|
2023-03-07 14:09:49 +00:00
|
|
|
},
|
2023-03-29 14:43:27 +02:00
|
|
|
{ refreshInterval: 100000 }
|
2023-02-22 13:05:52 +00:00
|
|
|
);
|
|
|
|
|
|
2023-03-07 14:09:49 +00:00
|
|
|
const shouldRender = !ticketError && ticketData;
|
2023-02-22 13:05:52 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Layout>
|
|
|
|
|
<Head>
|
|
|
|
|
<title>Link Shell</title>
|
|
|
|
|
</Head>
|
|
|
|
|
{shouldRender && (
|
|
|
|
|
<Grid container spacing={0} sx={{ height: "100vh" }} direction="row">
|
2023-03-22 11:55:14 +00:00
|
|
|
<Grid item sx={{ height: "100vh" }} xs={9}>
|
2023-03-07 14:09:49 +00:00
|
|
|
<TicketDetail ticket={ticketData.ticket} />
|
2023-02-22 13:05:52 +00:00
|
|
|
</Grid>
|
2023-03-22 11:55:14 +00:00
|
|
|
<Grid item xs={3} sx={{ height: "100vh" }}>
|
2023-03-07 14:09:49 +00:00
|
|
|
<TicketEdit ticket={ticketData.ticket} />
|
2023-03-22 11:55:14 +00:00
|
|
|
</Grid>
|
2023-03-15 12:17:43 +00:00
|
|
|
</Grid>
|
|
|
|
|
)}
|
2023-02-22 13:05:52 +00:00
|
|
|
{ticketError && <div>{ticketError.toString()}</div>}
|
|
|
|
|
</Layout>
|
|
|
|
|
);
|
2023-03-15 12:17:43 +00:00
|
|
|
};
|
2023-02-22 13:05:52 +00:00
|
|
|
|
|
|
|
|
export const getServerSideProps: GetServerSideProps = async (
|
2023-03-15 12:17:43 +00:00
|
|
|
context: GetServerSidePropsContext
|
|
|
|
|
) => {
|
2023-02-22 13:05:52 +00:00
|
|
|
const { id } = context.query;
|
|
|
|
|
return { props: { id } };
|
2023-03-15 12:17:43 +00:00
|
|
|
};
|
2023-02-22 13:05:52 +00:00
|
|
|
|
|
|
|
|
export default Ticket;
|