From 73675480f67d7acf213713a1d1d2ef32523dc5f8 Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Thu, 9 Apr 2026 16:03:32 +0200 Subject: [PATCH] refactor: rename getServizioAnnuncio to getServizioContratto and update related logic in servizio router --- .../contratto-registrazione/[...slug].tsx | 75 ++++++++---------- .../pages/servizio/contratto/[...slug].tsx | 77 ++++++++----------- .../src/server/api/routers/servizio.ts | 21 +++-- 3 files changed, 78 insertions(+), 95 deletions(-) diff --git a/apps/infoalloggi/src/pages/servizio/contratto-registrazione/[...slug].tsx b/apps/infoalloggi/src/pages/servizio/contratto-registrazione/[...slug].tsx index e87da94..7a96921 100644 --- a/apps/infoalloggi/src/pages/servizio/contratto-registrazione/[...slug].tsx +++ b/apps/infoalloggi/src/pages/servizio/contratto-registrazione/[...slug].tsx @@ -1,39 +1,31 @@ import type { GetServerSideProps } from "next"; import Link from "next/link"; import { AllegatoIframe } from "~/components/allegato-iframe"; -import { DocNotFoundPage } from "~/components/doc_not_found"; import { AreaRiservataLayout } from "~/components/Layout"; import { LoadingPage } from "~/components/loading"; -import { Status500 } from "~/components/status-page"; import { getStorageUrl } from "~/lib/storage_utils"; import { redirectTo500 } from "~/lib/utils"; import type { NextPageWithLayout } from "~/pages/_app"; import { useTranslation } from "~/providers/I18nProvider"; -import type { AnnunciId } from "~/schemas/public/Annunci"; -import type { ServizioServizioId } from "~/schemas/public/Servizio"; import { TrpcAuthedFetchingIstance } from "~/server/utils/ssgHelper"; import { zAnnuncioId, zServizioId } from "~/server/utils/zod_types"; import { api } from "~/utils/api"; type ContrattoViewerProps = { - servizioId: ServizioServizioId; - annuncioId: AnnunciId; + storageId: string; }; /** * Pagina di visualizzazione del contratto di registrazione: /servizio/contratto-registrazione/[servizioId]/[annuncioId] */ const ContrattoViewer: NextPageWithLayout = ({ - servizioId, - annuncioId, + storageId, }: ContrattoViewerProps) => { - const { data, isLoading } = api.servizio.getServizioAnnuncio.useQuery({ - annuncioId, - servizioId, + const { data: fileInfos, isLoading } = api.storage.getFileInfos.useQuery({ + storageId, }); const { t } = useTranslation(); if (isLoading) return ; - if (!data) return ; - if (!data.doc_registrazione_ref) return ; + if (!fileInfos) return

{t.file_section.error}

; return (
@@ -44,37 +36,26 @@ const ContrattoViewer: NextPageWithLayout = ({

{t.servizio.contratto_view.ricevuta_cta}

- + + + + {t.file_section.download} +
); }; -const FileSection = ({ storageId }: { storageId: string }) => { - const { data: fileInfos, isLoading } = api.storage.getFileInfos.useQuery({ - storageId, - }); - const { t } = useTranslation(); - if (isLoading) return ; - if (!fileInfos) return

{t.file_section.error}

; - return ( - <> - - - - {t.file_section.download} - - - ); -}; - ContrattoViewer.getLayout = function getLayout(page) { return {page}; }; @@ -108,15 +89,23 @@ export const getServerSideProps = (async (context) => { const helper = await TrpcAuthedFetchingIstance({ access_token }); if (helper) { - await helper.trpc.servizio.getServizioAnnuncio.prefetch({ - annuncioId: parsedAnnuncioId.data, - servizioId: parsedServizioId.data, + 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: { - annuncioId: parsedAnnuncioId.data, - servizioId: parsedServizioId.data, + storageId, trpcState: helper.trpc.dehydrate(), }, }; diff --git a/apps/infoalloggi/src/pages/servizio/contratto/[...slug].tsx b/apps/infoalloggi/src/pages/servizio/contratto/[...slug].tsx index b077606..f9e46f8 100644 --- a/apps/infoalloggi/src/pages/servizio/contratto/[...slug].tsx +++ b/apps/infoalloggi/src/pages/servizio/contratto/[...slug].tsx @@ -1,53 +1,25 @@ import type { GetServerSideProps } from "next"; import Link from "next/link"; import { AllegatoIframe } from "~/components/allegato-iframe"; -import { DocNotFoundPage } from "~/components/doc_not_found"; import { AreaRiservataLayout } from "~/components/Layout"; import { LoadingPage } from "~/components/loading"; -import { Status500 } from "~/components/status-page"; import { getStorageUrl } from "~/lib/storage_utils"; import { redirectTo500 } from "~/lib/utils"; import type { NextPageWithLayout } from "~/pages/_app"; import { useTranslation } from "~/providers/I18nProvider"; -import type { AnnunciId } from "~/schemas/public/Annunci"; -import type { ServizioServizioId } from "~/schemas/public/Servizio"; import { TrpcAuthedFetchingIstance } from "~/server/utils/ssgHelper"; import { zAnnuncioId, zServizioId } from "~/server/utils/zod_types"; import { api } from "~/utils/api"; type ContrattoViewerProps = { - servizioId: ServizioServizioId; - annuncioId: AnnunciId; + storageId: string; }; /** * Pagina di visualizzazione del contratto: /servizio/contratto-registrazione/[servizioId]/[annuncioId] */ const ContrattoViewer: NextPageWithLayout = ({ - servizioId, - annuncioId, + storageId, }: ContrattoViewerProps) => { - const { data, isLoading } = api.servizio.getServizioAnnuncio.useQuery({ - annuncioId, - servizioId, - }); - const { t } = useTranslation(); - if (isLoading) return ; - if (!data) return ; - if (!data.doc_contratto_ref) return ; - return ( -
-
-
-

{t.servizio.contratto.titolo}

-

{t.servizio.contratto.descrizione}

- -
-
-
- ); -}; - -const FileSection = ({ storageId }: { storageId: string }) => { const { data: fileInfos, isLoading } = api.storage.getFileInfos.useQuery({ storageId, }); @@ -55,19 +27,28 @@ const FileSection = ({ storageId }: { storageId: string }) => { if (isLoading) return ; if (!fileInfos) return

{t.file_section.error}

; return ( - <> - +
+
+
+

{t.servizio.contratto.titolo}

+

{t.servizio.contratto.descrizione}

+ - - {t.file_section.download} - - + + {t.file_section.download} + +
+
+
); }; @@ -104,15 +85,21 @@ export const getServerSideProps = (async (context) => { const helper = await TrpcAuthedFetchingIstance({ access_token }); if (helper) { - await helper.trpc.servizio.getServizioAnnuncio.prefetch({ + const storageId = await helper.trpc.servizio.getServizioContratto.fetch({ annuncioId: parsedAnnuncioId.data, servizioId: parsedServizioId.data, }); + if (!storageId) { + return redirectTo500; + } + + await helper.trpc.storage.getFileInfos.prefetch({ + storageId, + }); return { props: { - annuncioId: parsedAnnuncioId.data, - servizioId: parsedServizioId.data, + storageId, trpcState: helper.trpc.dehydrate(), }, }; diff --git a/apps/infoalloggi/src/server/api/routers/servizio.ts b/apps/infoalloggi/src/server/api/routers/servizio.ts index 72e446a..d8b2ae3 100644 --- a/apps/infoalloggi/src/server/api/routers/servizio.ts +++ b/apps/infoalloggi/src/server/api/routers/servizio.ts @@ -205,8 +205,7 @@ export const servizioRouter = createTRPCRouter({ } return { available: true, userId: servizio.user_id }; }), - - getServizioAnnuncio: protectedProcedure + getServizioContratto: protectedProcedure .input( z.object({ annuncioId: zAnnuncioId, @@ -214,21 +213,29 @@ export const servizioRouter = createTRPCRouter({ }), ) .query(async ({ input }) => { - return await getServizioAnnuncio({ + const sa = await getServizioAnnuncio({ annuncioId: input.annuncioId, servizioId: input.servizioId, }); - }), - getUserServizi: adminProcedure + return sa.doc_contratto_ref; + }), + getServizioRegistrazione: protectedProcedure .input( z.object({ - userId: zUserId, + annuncioId: zAnnuncioId, + servizioId: zServizioId, }), ) .query(async ({ input }) => { - return await getServiziByUserId(input.userId); + const sa = await getServizioAnnuncio({ + annuncioId: input.annuncioId, + servizioId: input.servizioId, + }); + + return sa.doc_registrazione_ref; }), + interruzioneServizio: protectedProcedure .input( z.object({