- Updated the Prezziario schema to replace boolean flags (isAcconto, isSaldo, isConsulenza, isStabile, isTransitorio) with new fields (order_type, service_type, service_variant) to better represent service attributes. - Modified NewPrezzoModal to align with the updated schema. - Renamed FormNewServizioAcquisto to FormServizioAcquisto in user onboarding pages for consistency. - Adjusted imports and component usage in the user view and service onboarding pages to reflect the new form name.
121 lines
3.4 KiB
TypeScript
121 lines
3.4 KiB
TypeScript
import type { GetServerSideProps } from "next";
|
|
import { AreaRiservataLayout } from "~/components/Layout";
|
|
import { LoadingPage } from "~/components/loading";
|
|
import { OnboardTutorial } from "~/components/onboard_tutorial";
|
|
import { Status500 } from "~/components/status-page";
|
|
import { FormServizioAcquisto } from "~/forms/FormServizioAcquisto";
|
|
import type { NextPageWithLayout } from "~/pages/_app";
|
|
import { CatastoProvider } from "~/providers/CatastoProvider";
|
|
import { useTranslation } from "~/providers/I18nProvider";
|
|
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 OnboardServizioProps = {
|
|
servizioId: ServizioServizioId;
|
|
};
|
|
/**
|
|
* /servizio/onboard/[servizioId] \
|
|
* Pagina di onboarding per un nuovo servizio. Mostra un tutorial e un form per completare l'acquisto del servizio, con i dati precompilati se disponibili.
|
|
* Accessibile solo se l'onboarding è disponibile per l'utente e il servizio specificato.
|
|
* Se l'onboarding non è disponibile, reindirizza alla dashboard dell'area riservata.
|
|
* Se non è possibile recuperare i dati necessari, mostra una pagina di errore.
|
|
*/
|
|
const OnboardServizio: NextPageWithLayout<OnboardServizioProps> = ({
|
|
servizioId,
|
|
}: OnboardServizioProps) => {
|
|
const { data, isLoading } = api.servizio.getAcquistoData.useQuery({
|
|
servizioId: servizioId,
|
|
});
|
|
const { locale } = useTranslation();
|
|
if (isLoading) {
|
|
return <LoadingPage />;
|
|
}
|
|
if (!data) {
|
|
return <Status500 />;
|
|
}
|
|
return (
|
|
<div className="mx-auto w-full max-w-6xl grow space-y-6 p-2 sm:px-8 sm:py-6">
|
|
<div className="flex justify-center">
|
|
<h3 className="font-bold text-3xl">
|
|
{locale === "it" ? "Dettagli del servizio" : "Service Details"}
|
|
</h3>
|
|
</div>
|
|
<OnboardTutorial />
|
|
<CatastoProvider>
|
|
<FormServizioAcquisto
|
|
initialData={data}
|
|
isAdmin={false}
|
|
userId={data.userData.id}
|
|
/>
|
|
</CatastoProvider>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
OnboardServizio.getLayout = function getLayout(page) {
|
|
return <AreaRiservataLayout noSidebar>{page}</AreaRiservataLayout>;
|
|
};
|
|
|
|
export default OnboardServizio;
|
|
|
|
export const getServerSideProps = (async (context) => {
|
|
const id = context.params?.servizioId;
|
|
|
|
if (typeof id !== "string") {
|
|
console.error("Error: servizioId is not a string");
|
|
return {
|
|
redirect: {
|
|
destination: "/500",
|
|
permanent: false,
|
|
},
|
|
};
|
|
}
|
|
|
|
const parsed = zServizioId.safeParse(id);
|
|
if (!parsed.success) {
|
|
console.error("Error parsing servizioId", parsed.error);
|
|
return {
|
|
redirect: {
|
|
destination: "/500",
|
|
permanent: false,
|
|
},
|
|
};
|
|
}
|
|
|
|
const access_token = context.req.cookies.access_token;
|
|
|
|
const helper = await TrpcAuthedFetchingIstance({ access_token });
|
|
if (helper) {
|
|
await helper.trpc.servizio.getAcquistoData.prefetch({
|
|
servizioId: parsed.data,
|
|
});
|
|
const { available, userId: _ } =
|
|
await helper.trpc.servizio.isOnboardAvailable.fetch({
|
|
servizioId: parsed.data,
|
|
});
|
|
|
|
if (!available) {
|
|
return {
|
|
redirect: {
|
|
destination: "/area-riservata/dashboard",
|
|
permanent: false,
|
|
},
|
|
};
|
|
}
|
|
return {
|
|
props: {
|
|
servizioId: parsed.data,
|
|
trpcState: helper.trpc.dehydrate(),
|
|
},
|
|
};
|
|
}
|
|
|
|
return {
|
|
redirect: {
|
|
destination: `/servizio/pre-onboard/${parsed.data}`,
|
|
permanent: false,
|
|
},
|
|
};
|
|
}) satisfies GetServerSideProps<OnboardServizioProps>;
|