2025-10-17 18:12:10 +02:00
|
|
|
import type { GetServerSideProps } from "next";
|
2025-08-28 18:27:07 +02:00
|
|
|
import Head from "next/head";
|
2025-08-04 17:45:44 +02:00
|
|
|
import { AreaRiservataLayout } from "~/components/Layout";
|
|
|
|
|
import { LoadingPage } from "~/components/loading";
|
|
|
|
|
import { Status500 } from "~/components/status-page";
|
2025-08-28 18:27:07 +02:00
|
|
|
import { OrdiniTable } from "~/components/tables/orders-table";
|
|
|
|
|
import type { NextPageWithLayout } from "~/pages/_app";
|
2025-08-20 14:04:23 +02:00
|
|
|
import { useEnforcedSession } from "~/providers/SessionProvider";
|
2026-03-08 01:02:57 +01:00
|
|
|
import type { OrdiniOrdineId } from "~/schemas/public/Ordini";
|
2025-10-17 18:12:10 +02:00
|
|
|
import { TrpcAuthedFetchingIstance } from "~/server/utils/ssgHelper";
|
2025-08-28 18:27:07 +02:00
|
|
|
import { api } from "~/utils/api";
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2026-03-08 01:02:57 +01:00
|
|
|
type OrdiniProps = {
|
|
|
|
|
ordineId: OrdiniOrdineId | null;
|
|
|
|
|
};
|
|
|
|
|
const Ordini: NextPageWithLayout<OrdiniProps> = ({ ordineId }: OrdiniProps) => {
|
2025-08-28 18:27:07 +02:00
|
|
|
const session = useEnforcedSession();
|
2026-03-08 01:02:57 +01:00
|
|
|
const { data, isLoading } = api.servizio.getOrdini.useQuery({
|
|
|
|
|
userId: session.user.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (isLoading) return <LoadingPage />;
|
|
|
|
|
if (!data) return <Status500 />;
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Head>
|
2026-01-19 10:23:16 +01:00
|
|
|
<title>Ordini - Infoalloggi.it</title>
|
2025-08-28 18:27:07 +02:00
|
|
|
</Head>
|
2026-03-08 01:02:57 +01:00
|
|
|
<main className="mx-1 mt-2 flex flex-1 flex-col items-start gap-4 p-2 md:gap-6">
|
|
|
|
|
<div className="grid w-full auto-rows-max items-start gap-2 md:gap-4">
|
|
|
|
|
<div className="overflow-auto border-none">
|
|
|
|
|
<h3 className="font-bold text-2xl">Ordini</h3>
|
|
|
|
|
|
|
|
|
|
<div className="w-full py-4">
|
|
|
|
|
<OrdiniTable
|
|
|
|
|
data={data}
|
|
|
|
|
filter={ordineId}
|
|
|
|
|
isAdmin={false}
|
|
|
|
|
userId={session.user.id}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</main>
|
2025-08-28 18:27:07 +02:00
|
|
|
</>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|
|
|
|
|
export default Ordini;
|
|
|
|
|
|
2025-10-17 18:12:10 +02:00
|
|
|
export const getServerSideProps = (async (context) => {
|
|
|
|
|
const access_token = context.req.cookies.access_token;
|
2026-03-08 01:02:57 +01:00
|
|
|
const ordineId = context.query?.ordineId;
|
|
|
|
|
if (ordineId && typeof ordineId !== "string") {
|
|
|
|
|
return {
|
|
|
|
|
notFound: true,
|
|
|
|
|
};
|
|
|
|
|
}
|
2025-10-17 18:12:10 +02:00
|
|
|
|
|
|
|
|
const helpers = await TrpcAuthedFetchingIstance({ access_token });
|
|
|
|
|
if (helpers) {
|
|
|
|
|
await helpers.trpc.servizio.getOrdini.prefetch({});
|
|
|
|
|
return {
|
|
|
|
|
props: {
|
2026-03-08 01:02:57 +01:00
|
|
|
ordineId: ordineId ? (ordineId as OrdiniOrdineId) : null,
|
2025-10-17 18:12:10 +02:00
|
|
|
trpcState: helpers.trpc.dehydrate(),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
props: {},
|
|
|
|
|
};
|
|
|
|
|
}) satisfies GetServerSideProps;
|
|
|
|
|
|
2025-08-04 17:45:44 +02:00
|
|
|
Ordini.getLayout = function getLayout(page) {
|
2025-08-28 18:27:07 +02:00
|
|
|
return <AreaRiservataLayout>{page}</AreaRiservataLayout>;
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|