import type { GetServerSideProps } from "next"; import Link from "next/link"; import { AllegatoIframe } from "~/components/allegato-iframe"; import { AreaRiservataLayout } from "~/components/Layout"; import { LoadingPage } from "~/components/loading"; import { getStorageUrl } from "~/lib/storage_utils"; import { redirectTo500 } from "~/lib/utils"; import type { NextPageWithLayout } from "~/pages/_app"; import { useTranslation } from "~/providers/I18nProvider"; import { TrpcAuthedFetchingIstance } from "~/server/utils/ssgHelper"; import { zAnnuncioId, zServizioId } from "~/server/utils/zod_types"; import { api } from "~/utils/api"; type ContrattoViewerProps = { storageId: string; }; /** * Pagina di visualizzazione del contratto di registrazione: /servizio/contratto-registrazione/[servizioId]/[annuncioId] */ const ContrattoViewer: NextPageWithLayout = ({ storageId, }: ContrattoViewerProps) => { const { data: fileInfos, isLoading } = api.storage.getFileInfos.useQuery({ storageId, }); const { t } = useTranslation(); if (isLoading) return ; if (!fileInfos) return

{t.file_section.error}

; return (

{t.servizio.contratto_view.ricevuta}

{t.servizio.contratto_view.ricevuta_cta}

{t.file_section.download}
); }; ContrattoViewer.getLayout = function getLayout(page) { return {page}; }; export default ContrattoViewer; export const getServerSideProps = (async (context) => { const slug = context.params?.slug; if (!slug || slug.length !== 2) { return { notFound: true, }; } const [servizioId, annuncioId] = slug; if (!servizioId || !annuncioId) { return { notFound: true, }; } const parsedServizioId = zServizioId.safeParse(servizioId); const parsedAnnuncioId = zAnnuncioId.safeParse(parseInt(annuncioId)); if (!parsedServizioId.success || !parsedAnnuncioId.success) { return { notFound: true, }; } const access_token = context.req.cookies.access_token; const helper = await TrpcAuthedFetchingIstance({ access_token }); if (helper) { const storageId = await helper.trpc.servizio.getServizioRegistrazione.fetch( { annuncioId: parsedAnnuncioId.data, servizioId: parsedServizioId.data, }, ); if (!storageId) { return redirectTo500; } await helper.trpc.storage.getFileInfos.prefetch({ storageId, }); return { props: { storageId, trpcState: helper.trpc.dehydrate(), }, }; } return redirectTo500; }) satisfies GetServerSideProps;