infoalloggi-monorepo/apps/infoalloggi/src/pages/servizio/condizioni/[stringaId].tsx
Marco Pedone 60e4b187bf Refactor: Update Zod schemas and replace custom types with imported schemas across various files
- Replaced custom Zod types with imported schemas in stripe router and user router.
- Updated payment controller to use new enum imports for order types and payment statuses.
- Refactored payment tests to utilize the new enum structure.
- Removed deprecated zod_types file and created new zod_chat_types file for chat-related schemas.
- Adjusted service files to align with the new order type enums and schemas.
- Enhanced the Caratteristiche type definition using Zod for better validation.

Co-authored-by: Copilot <copilot@github.com>
2026-04-28 20:32:19 +02:00

83 lines
2.1 KiB
TypeScript

import type { GetServerSideProps } from "next";
import { AreaRiservataLayout } from "~/components/Layout";
import { LoadingPage } from "~/components/loading";
import { Status500 } from "~/components/status-page";
import { redirectTo500 } from "~/lib/utils";
import type { NextPageWithLayout } from "~/pages/_app";
import {
type TestiEStringheStingaId,
testiEStringheStingaId,
} from "~/schemas/public/TestiEStringhe";
import { generateSSGHelper } from "~/server/utils/ssgHelper";
import { api } from "~/utils/api";
type CondizioniProps = {
stringaId: TestiEStringheStingaId;
};
/**
* Pagina condizioni: /servizio/condizioni/[stringaId]
*/
const CondizioniPage: NextPageWithLayout<CondizioniProps> = ({
stringaId,
}: CondizioniProps) => {
const { data, isLoading } = api.strings.getStringa.useQuery({
stringaId,
});
if (isLoading) {
return <LoadingPage />;
}
if (!data) {
return <Status500 />;
}
return (
<div className="w-full grow space-y-4 p-4 text-foreground sm:p-6">
{data && (
<div
className="prose dark:prose-invert mx-auto max-w-5xl"
dangerouslySetInnerHTML={{ __html: data.stringa_value || "" }}
/>
)}
</div>
);
};
CondizioniPage.getLayout = function getLayout(page) {
if (page.props.raw) {
return <>{page}</>;
}
return <AreaRiservataLayout noSidebar>{page}</AreaRiservataLayout>;
};
export default CondizioniPage;
export const getServerSideProps = (async (context) => {
const id = context.params?.stringaId;
const raw = context.query?.raw;
if (typeof id !== "string") {
console.error("Error: stringaId is not a string");
return redirectTo500;
}
const parsed = testiEStringheStingaId.safeParse(id);
if (!parsed.success) {
console.error("Error parsing paymentId", parsed.error);
return redirectTo500;
}
const helper = generateSSGHelper();
if (helper) {
await helper.strings.getStringa.prefetch({
stringaId: parsed.data,
});
return {
props: {
raw: raw === "true",
stringaId: parsed.data,
trpcState: helper.dehydrate(),
},
};
}
return redirectTo500;
}) satisfies GetServerSideProps<CondizioniProps>;