import type { GetServerSideProps } from "next"; import { useRouter } from "next/router"; import { useState } from "react"; import toast from "react-hot-toast"; import { DocNotFoundPage } from "~/components/doc_not_found"; import { AreaRiservataLayout } from "~/components/Layout"; import { LoadingPage } from "~/components/loading"; import { FileSection } from "~/components/servizio/conferma"; import { Status500 } from "~/components/status-page"; import { Button } from "~/components/ui/button"; import { Checkbox } from "~/components/ui/checkbox"; import type { NextPageWithLayout } from "~/pages/_app"; import { useTranslation } from "~/providers/I18nProvider"; import { useEnforcedSession } from "~/providers/SessionProvider"; 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 ConfermaImmobileProps = { servizioId: ServizioServizioId; annuncioId: AnnunciId; }; const ConfermaImmobile: NextPageWithLayout = ({ servizioId, annuncioId, }: ConfermaImmobileProps) => { const { data, isLoading } = api.servizio.getServizioAnnuncio.useQuery({ annuncioId, servizioId, }); const { t } = useTranslation(); if (isLoading) return ; if (!data) return ; if (!data.doc_conferma_ref) return ; return (

{t.servizio.conferma.titolo}

{t.servizio.conferma.descrizione}

{t.servizio.conferma.cta}

{t.servizio.conferma.coordinate}

{t.servizio.conferma.intestazione}{" "} {data.caparra_intestazione || ""}

{t.servizio.conferma.iban} {data.caparra_iban || ""}

{t.servizio.conferma.importo} {data.caparra_importo || ""}

{t.servizio.conferma.causale} {data.caparra_causale || ""}

{t.servizio.conferma.coord_footer}

); }; const ConfirmSection = ({ servizioId, annuncioId, }: { servizioId: ServizioServizioId; annuncioId: AnnunciId; }) => { const { t } = useTranslation(); const router = useRouter(); const [letto, setLetto] = useState(false); const [accettato, setAccettato] = useState(false); const { user } = useEnforcedSession(); const utils = api.useUtils(); const { mutate: conferma } = api.servizio.userAcceptConfermaImmobile.useMutation({ onMutate: () => { const toastId = toast.loading(t.caricamento, { icon: "🔄", }); return { toastId }; }, onSuccess: async (data, _variables, context) => { await utils.storage.retrieveUserFileData.invalidate(); await utils.servizio.invalidate(); toast.success("Confermato", { icon: "👍", id: context?.toastId, }); if (user.isAdmin) { await router.push( `/area-riservata/admin/user-view/ricerca/${data.userId}`, ); } else { await router.push(`/area-riservata/servizio/${servizioId}`); } }, }); return ( <>
v !== "indeterminate" && setLetto(v)} />
v !== "indeterminate" && setAccettato(v)} />

{t.servizio.conferma.confermo_termini}

); }; ConfermaImmobile.getLayout = function getLayout(page) { return {page}; }; export default ConfermaImmobile; 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) { await helper.trpc.servizio.getServizioAnnuncio.prefetch({ annuncioId: parsedAnnuncioId.data, servizioId: parsedServizioId.data, }); return { props: { annuncioId: parsedAnnuncioId.data, servizioId: parsedServizioId.data, trpcState: helper.trpc.dehydrate(), }, }; } return { redirect: { destination: "/500", permanent: false, }, }; }) satisfies GetServerSideProps;