import { ArrowRight, ExternalLink } from "lucide-react"; import type { GetServerSideProps } from "next"; import Link from "next/link"; import { useRouter } from "next/router"; import { AreaRiservataLayout } from "~/components/Layout"; import { LoadingPage } from "~/components/loading"; import { Status500 } from "~/components/status-page"; import { Button } from "~/components/ui/button"; import { formatCurrency } from "~/lib/utils"; import type { NextPageWithLayout } from "~/pages/_app"; import { useTranslation } from "~/providers/I18nProvider"; import type { OrdiniOrdineId } from "~/schemas/public/Ordini"; import type { PrezziarioIdprezziario } from "~/schemas/public/Prezziario"; import { TrpcAuthedFetchingIstance } from "~/server/utils/ssgHelper"; import { zOrdineId } from "~/server/utils/zod_types"; import { api } from "~/utils/api"; type ServizioPurchaseProps = { ordineId: OrdiniOrdineId; }; const ServicePurchasePage: NextPageWithLayout = ({ ordineId, }: ServizioPurchaseProps) => { const router = useRouter(); const { data, isLoading } = api.servizio.getServizioPaymentData.useQuery({ ordineId, }); if (isLoading) { return ; } if (!data) { return ; } return (
await router.push(`/servizio/pagamento-checkout/${data.payment.id}`) } packId={data.ordine.packid} />
); }; const PricePreparation = ({ packId, onProcedi, }: { packId: PrezziarioIdprezziario; onProcedi: () => void; }) => { const { data: prezziario, isLoading } = api.prezziario.getPrezzoPerServizio.useQuery({ idprezziario: packId, }); const { t } = useTranslation(); return (
{isLoading || !prezziario ? ( <>

{t.acquisto.preparazione}

) : (

{prezziario.nome_it}

Cod: “{prezziario.idprezziario}”

{formatCurrency(prezziario.prezzo_cent / 100)}

{prezziario.desc_it}

{prezziario.testo_condizioni && ( )}
)}
); }; ServicePurchasePage.getLayout = function getLayout(page) { return {page}; }; export default ServicePurchasePage; export const getServerSideProps = (async (context) => { const id = context.params?.ordineId; if (typeof id !== "string") { console.error("Error: ordineId is not a string"); return { redirect: { destination: "/500", permanent: false, }, }; } const parsed = zOrdineId.safeParse(id); if (!parsed.success) { console.error("Error parsing ordineId", parsed.error); return { redirect: { destination: "/500", permanent: false, }, }; } const access_token = context.req.cookies.access_token; const helper = await TrpcAuthedFetchingIstance({ access_token }); if (helper) { const isAwaitingPayment = await helper.trpc.servizio.isOrdineAwaitingPayment.fetch({ ordineId: parsed.data, }); if (!isAwaitingPayment) { return { redirect: { destination: "/area-riservata/dashboard", permanent: false, }, }; } await helper.trpc.servizio.getServizioPaymentData.prefetch({ ordineId: parsed.data, }); return { props: { ordineId: parsed.data, trpcState: helper.trpc.dehydrate(), }, }; } return { redirect: { destination: "/500", permanent: false, }, }; }) satisfies GetServerSideProps;