import type { GetServerSideProps } from "next"; import { AreaRiservataLayout } from "~/components/Layout"; import { LoadingPage } from "~/components/loading"; import { OnboardTutorial } from "~/components/onboard_tutorial"; import { Status500 } from "~/components/status-page"; import { FormNewServizioAcquisto } from "~/forms/FormNewServizioAcquisto"; import type { NextPageWithLayout } from "~/pages/_app"; import { CatastoProvider } from "~/providers/CatastoProvider"; import { useTranslation } from "~/providers/I18nProvider"; import type { ServizioServizioId } from "~/schemas/public/Servizio"; import { TrpcAuthedFetchingIstance } from "~/server/utils/ssgHelper"; import { zServizioId } from "~/server/utils/zod_types"; import { api } from "~/utils/api"; type OnboardServizioProps = { servizioId: ServizioServizioId; }; const OnboardServizio: NextPageWithLayout = ({ servizioId, }: OnboardServizioProps) => { const { data, isLoading } = api.servizio.getAcquistoData.useQuery({ servizioId: servizioId, }); const { locale } = useTranslation(); if (isLoading) { return ; } if (!data) { return ; } return (

{locale === "it" ? "Dettagli del servizio" : "Service Details"}

); }; OnboardServizio.getLayout = function getLayout(page) { return ( {page} ); }; export default OnboardServizio; export const getServerSideProps = (async (context) => { const id = context.params?.servizioId; if (typeof id !== "string") { console.error("Error: servizioId is not a string"); return { redirect: { destination: "/500", permanent: false, }, }; } const parsed = zServizioId.safeParse(id); if (!parsed.success) { console.error("Error parsing servizioId", 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.servizio.getAcquistoData.prefetch({ servizioId: parsed.data, }); const servizio = await helper.trpc.servizio.getServizio.fetch({ servizioId: parsed.data, }); if ( !servizio || servizio.isOkAcconto || servizio.isInterrotto || servizio.decorrenza !== null ) { return { redirect: { destination: "/area-riservata/dashboard", permanent: false, }, }; } return { props: { servizioId: parsed.data, trpcState: helper.trpc.dehydrate(), }, }; } return { redirect: { destination: `/servizio/pre-onboard/${parsed.data}`, permanent: false, }, }; }) satisfies GetServerSideProps;