import type { GetServerSideProps } from "next"; import Head from "next/head"; import { AreaRiservataLayout } from "~/components/Layout"; import { LoadingPage } from "~/components/loading"; import { SchedaAnnuncioStampabile } from "~/components/schedaAnnuncioStampabile"; import { Status500 } from "~/components/status-page"; import type { NextPageWithLayout } from "~/pages/_app"; import type { AnnunciId } from "~/schemas/public/Annunci"; import { TrpcAuthedFetchingIstance } from "~/server/utils/ssgHelper"; import { zAnnuncioId } from "~/server/utils/zod_types"; import { api } from "~/utils/api"; type PageProps = { id: AnnunciId; }; const SchedaAnnuncioPage: NextPageWithLayout = ({ id, }: PageProps) => { const { data, isLoading } = api.annunci.getAnnuncioById_rawImgUrls.useQuery({ id, }); if (isLoading) { return ; } if (!data) { return ; } return ( <> Scheda Annuncio {data.codice}
); }; SchedaAnnuncioPage.getLayout = function getLayout(page) { return ( {page} ); }; export default SchedaAnnuncioPage; export const getServerSideProps = (async (context) => { const id = context.params?.id; if (typeof id !== "string") { console.error("Error: id is not a string"); return { redirect: { destination: "/500", permanent: false, }, }; } const parsed = zAnnuncioId.safeParse(parseInt(id)); if (!parsed.success) { console.error("Error parsing ordineId", parsed.error); return { redirect: { destination: "/500", permanent: false, }, }; } const access_token = context.req.cookies.access_token; const helper = await TrpcAuthedFetchingIstance({ access_token }); if (helper) { await helper.trpc.annunci.getAnnuncioById_rawImgUrls.prefetch({ id: parsed.data, }); return { props: { id: parsed.data, trpcState: helper.trpc.dehydrate(), }, }; } return { redirect: { destination: "/500", permanent: false, }, }; }) satisfies GetServerSideProps;