import type { GetServerSideProps } from "next"; import { AreaRiservataLayout } from "~/components/Layout"; import { LoadingPage } from "~/components/loading"; import { Status500 } from "~/components/status-page"; import type { NextPageWithLayout } from "~/pages/_app"; import type { TestiEStringheStingaId } from "~/schemas/public/TestiEStringhe"; import { TrpcAuthedFetchingIstance } from "~/server/utils/ssgHelper"; import { zTestiEStringheStingaId } from "~/server/utils/zod_types"; import { api } from "~/utils/api"; type CondizioniProps = { stringaId: TestiEStringheStingaId; }; const CondizioniPage: NextPageWithLayout = ({ stringaId, }: CondizioniProps) => { const { data, isLoading } = api.settings.getStringa.useQuery({ stringaId, }); if (isLoading) { return ; } if (!data) { return ; } return (
{data && (
)}
); }; CondizioniPage.getLayout = function getLayout(page) { return ( {page} ); }; export default CondizioniPage; export const getServerSideProps = (async (context) => { const id = context.params?.stringaId; if (typeof id !== "string") { console.error("Error: stringaId is not a string"); return { redirect: { destination: "/500", permanent: false, }, }; } const parsed = zTestiEStringheStingaId.safeParse(id); if (!parsed.success) { console.error("Error parsing paymentId", 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.settings.getStringa.prefetch({ stringaId: parsed.data, }); return { props: { stringaId: parsed.data, trpcState: helper.trpc.dehydrate(), }, }; } return { redirect: { destination: "/500", permanent: false, }, }; }) satisfies GetServerSideProps;