2026-02-25 15:30:53 +01:00
|
|
|
import type { GetServerSideProps } from "next";
|
2026-02-25 15:50:53 +01:00
|
|
|
import { UserDashboardFaq } from "~/components/area-riservata/dashboard";
|
2026-02-25 15:30:53 +01:00
|
|
|
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 (
|
2026-03-06 18:54:48 +01:00
|
|
|
<div className="flex w-full flex-1 flex-col items-start justify-center gap-3 overflow-auto p-2 md:gap-6">
|
2026-03-08 01:02:57 +01:00
|
|
|
{/* <div className=" w-full flex-col gap-2 flex">
|
2026-02-25 15:50:53 +01:00
|
|
|
<div className="flex w-full items-center justify-between">
|
2026-03-06 18:54:48 +01:00
|
|
|
<h3 className="font-semibold text-xl">
|
2026-02-25 15:50:53 +01:00
|
|
|
{t.servizio.dettaglio_servizio}
|
|
|
|
|
</h3>
|
|
|
|
|
|
|
|
|
|
<Link href="/area-riservata/dashboard">
|
|
|
|
|
<Button size="sm" variant="outline">
|
|
|
|
|
<ArrowRight className="size-4" />
|
2026-03-06 18:54:48 +01:00
|
|
|
<span>lista servizi</span>
|
2026-02-25 15:50:53 +01:00
|
|
|
</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
<Separator />
|
2026-03-08 01:02:57 +01:00
|
|
|
</div> */}
|
2026-02-25 15:50:53 +01:00
|
|
|
<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 />
|
2026-02-25 15:30:53 +01:00
|
|
|
</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) {
|
2026-03-06 18:23:35 +01:00
|
|
|
await helper.trpc.servizio.getServizioData.prefetch({
|
2026-02-25 15:30:53 +01:00
|
|
|
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>;
|
|
|
|
|
};
|