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 = ({ id }) => { const origin = typeof window !== 'undefined' && window.location.origin ? window.location.origin : ''; const fetcher = async (url: string) => { const res = await fetch(url); return res.json(); } const { data: ticketData, error: ticketError } = useSWR( `${origin}/api/v1/tickets/${id}`, fetcher ); const { data: articlesData, error: articlesError } = useSWR( `${origin}/api/v1/ticket_articles/by_ticket/${id}`, fetcher ); const shouldRender = !ticketError && !articlesError && ticketData && articlesData && !ticketData.error && !articlesData.error; return ( Link Shell {shouldRender && ( )} {ticketError &&
{ticketError.toString()}
}
); } export const getServerSideProps: GetServerSideProps = async ( context: GetServerSidePropsContext) => { const { id } = context.query; return { props: { id } }; } export default Ticket;