infoalloggi-monorepo/apps/infoalloggi/src/pages/servizio/riapri-conferma/[...slug].tsx

138 lines
3.9 KiB
TypeScript
Raw Normal View History

2025-08-28 18:27:07 +02:00
import { ArrowLeft } from "lucide-react";
2025-08-04 17:45:44 +02:00
import type { GetServerSideProps } from "next";
2025-08-28 18:27:07 +02:00
import { useRouter } from "next/router";
import { DocNotFoundPage } from "~/components/doc_not_found";
2025-08-04 17:45:44 +02:00
import { AreaRiservataLayout } from "~/components/Layout";
import { LoadingPage } from "~/components/loading";
import { FileSection } from "~/components/servizio/conferma";
2025-08-28 18:27:07 +02:00
import { Status500 } from "~/components/status-page";
2025-08-04 17:45:44 +02:00
import { Button } from "~/components/ui/button";
2025-08-28 18:27:07 +02:00
import type { NextPageWithLayout } from "~/pages/_app";
import { useTranslation } from "~/providers/I18nProvider";
2025-08-28 18:27:07 +02:00
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";
2025-08-04 17:45:44 +02:00
type RiapriConfermaProps = {
2025-08-28 18:27:07 +02:00
servizioId: ServizioServizioId;
annuncioId: AnnunciId;
2025-08-04 17:45:44 +02:00
};
const RiapriConferma: NextPageWithLayout<RiapriConfermaProps> = ({
2025-08-28 18:27:07 +02:00
servizioId,
annuncioId,
2025-08-04 17:45:44 +02:00
}: RiapriConfermaProps) => {
2025-08-28 18:27:07 +02:00
const { data, isLoading } = api.servizio.getServizioAnnuncio.useQuery({
annuncioId,
2025-08-29 16:18:32 +02:00
servizioId,
2025-08-28 18:27:07 +02:00
});
const router = useRouter();
const { t } = useTranslation();
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
if (isLoading) return <LoadingPage />;
if (!data) return <Status500 />;
if (!data.doc_conferma_ref) return <DocNotFoundPage />;
return (
<div className="mx-2 flex flex-1 overflow-auto">
<div className="mx-auto flex grow sm:grow-0">
<div className="flex flex-col items-center space-y-4 py-4">
2025-10-10 16:18:43 +02:00
<h1 className="font-bold text-xl">{t.servizio.conferma.titolo}</h1>
2025-08-28 18:27:07 +02:00
<p className="text-center">{t.servizio.conferma.descrizione}</p>
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
<FileSection storageId={data.doc_conferma_ref} />
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
<div className="flex max-w-3xl flex-col gap-2 rounded-md bg-green-400 p-4 text-left">
2025-10-10 16:18:43 +02:00
<p className="font-semibold text-xl">{t.servizio.conferma.cta}</p>
2025-08-28 18:27:07 +02:00
<p>{t.servizio.conferma.coordinate}</p>
<p>
{t.servizio.conferma.intestazione}{" "}
{data.caparra_intestazione || ""}
</p>
<p>
{t.servizio.conferma.iban} {data.caparra_iban || ""}
</p>
<p>
{t.servizio.conferma.importo} {data.caparra_importo || ""}
</p>
<p>
{t.servizio.conferma.causale} {data.caparra_causale || ""}
</p>
2025-10-10 16:18:43 +02:00
<p className="font-semibold text-xl">
2025-08-28 18:27:07 +02:00
{t.servizio.conferma.coord_footer}
</p>
</div>
2025-08-28 18:27:07 +02:00
<Button
className="mx-auto mb-4"
2025-08-28 18:27:07 +02:00
onClick={() => router.back()}
variant="secondary"
>
<ArrowLeft className="size-5" />
{t.indietro}
</Button>
</div>
</div>
</div>
);
2025-08-04 17:45:44 +02:00
};
RiapriConferma.getLayout = function getLayout(page) {
2025-08-28 18:27:07 +02:00
return (
2025-08-29 16:18:32 +02:00
<AreaRiservataLayout noFooter noSidebar>
2025-08-28 18:27:07 +02:00
{page}
</AreaRiservataLayout>
);
2025-08-04 17:45:44 +02:00
};
export default RiapriConferma;
export const getServerSideProps = (async (context) => {
2025-08-28 18:27:07 +02:00
const slug = context.params?.slug;
if (!slug || slug.length !== 2) {
return {
notFound: true,
};
}
const [servizioId, annuncioId] = slug;
if (!servizioId || !annuncioId) {
return {
notFound: true,
};
}
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
const parsedServizioId = zServizioId.safeParse(servizioId);
const parsedAnnuncioId = zAnnuncioId.safeParse(parseInt(annuncioId));
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
if (!parsedServizioId.success || !parsedAnnuncioId.success) {
return {
notFound: true,
};
}
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
const access_token = context.req.cookies.access_token;
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
const helper = await TrpcAuthedFetchingIstance({ access_token });
if (helper) {
await helper.trpc.servizio.getServizioAnnuncio.prefetch({
annuncioId: parsedAnnuncioId.data,
2025-08-29 16:18:32 +02:00
servizioId: parsedServizioId.data,
2025-08-28 18:27:07 +02:00
});
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
return {
props: {
annuncioId: parsedAnnuncioId.data,
2025-08-29 16:18:32 +02:00
servizioId: parsedServizioId.data,
2025-08-28 18:27:07 +02:00
trpcState: helper.trpc.dehydrate(),
},
};
}
return {
redirect: {
destination: "/500",
permanent: false,
},
};
2025-08-04 17:45:44 +02:00
}) satisfies GetServerSideProps<RiapriConfermaProps>;