infoalloggi-monorepo/apps/infoalloggi/src/pages/area-riservata/servizio/[servizioId].tsx
Marco Pedone 6c36bb9b74 feat: add order editing form and payment processing pages
- Implemented FormEditOrder component for editing orders with validation and submission handling.
- Created SchedaAnnuncioPage for displaying printable announcement details.
- Added BonificoManualePage for manual bank transfer payment instructions.
- Developed PagamentoPage for Stripe payment processing with PaymentIntent creation.
- Introduced PreviewPurchasePage for preparing payment with service details.
- Added pagamenti.controller for handling payment preparation and retrieval of payment data.
2026-03-08 01:02:57 +01:00

115 lines
3 KiB
TypeScript

import type { GetServerSideProps } from "next";
import { UserDashboardFaq } from "~/components/area-riservata/dashboard";
import { AreaRiservataLayout } from "~/components/Layout";
import { LoadingPage } from "~/components/loading";
import { Servizio } from "~/components/servizio/servizio";
import { Status500 } from "~/components/status-page";
import type { NextPageWithLayout } from "~/pages/_app";
import { useEnforcedSession } from "~/providers/SessionProvider";
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 ServizioPageProps = {
servizioId: ServizioServizioId;
};
const ServizioPage: NextPageWithLayout<ServizioPageProps> = ({
servizioId,
}: ServizioPageProps) => {
const { user } = useEnforcedSession();
const { data, isLoading } = api.servizio.getServizioData.useQuery({
servizioId,
});
if (isLoading) {
return <LoadingPage />;
}
if (!data) {
return <Status500 />;
}
return (
<div className="flex w-full flex-1 flex-col items-start justify-center gap-3 overflow-auto p-2 md:gap-6">
{/* <div className=" w-full flex-col gap-2 flex">
<div className="flex w-full items-center justify-between">
<h3 className="font-semibold text-xl">
{t.servizio.dettaglio_servizio}
</h3>
<Link href="/area-riservata/dashboard">
<Button size="sm" variant="outline">
<ArrowRight className="size-4" />
<span>lista servizi</span>
</Button>
</Link>
</div>
<Separator />
</div> */}
<div className="flex w-full flex-1 grow flex-col space-y-5">
<Servizio
isAdmin={false}
key={data.servizio_id}
servizio={data}
userId={user.id}
/>
</div>
<div className="mx-auto">
<UserDashboardFaq />
</div>
</div>
);
};
export default ServizioPage;
export const getServerSideProps = (async (context) => {
const servizio_id = context.params?.servizioId;
if (typeof servizio_id !== "string") {
console.error("Error: servizioId is not a string");
return {
redirect: {
destination: "/500",
permanent: false,
},
};
}
const parsedServizioId = zServizioId.safeParse(servizio_id);
if (!parsedServizioId.success) {
console.error("Error parsing servizioId", parsedServizioId.error);
return {
redirect: {
destination: "/500",
permanent: false,
},
};
}
const servizioId = parsedServizioId.data;
const access_token = context.req.cookies.access_token;
const helper = await TrpcAuthedFetchingIstance({ access_token });
if (helper) {
await helper.trpc.servizio.getServizioData.prefetch({
servizioId,
});
return {
props: {
servizioId,
trpcState: helper.trpc.dehydrate(),
},
};
}
return {
redirect: {
destination: `/area-riservata/admin/utenti`,
permanent: false,
},
};
}) satisfies GetServerSideProps<ServizioPageProps>;
ServizioPage.getLayout = function getLayout(page) {
return <AreaRiservataLayout>{page}</AreaRiservataLayout>;
};