2025-10-21 14:34:24 +02:00
|
|
|
import { getCookie } from "cookies-next";
|
2025-08-28 18:27:07 +02:00
|
|
|
import Head from "next/head";
|
2025-11-20 16:48:29 +01:00
|
|
|
import type { ReactNode } from "react";
|
2025-10-21 14:34:24 +02:00
|
|
|
import {
|
|
|
|
|
SIDEBAR_COOKIE_NAME,
|
|
|
|
|
Sidebar,
|
|
|
|
|
} from "~/components/area-riservata/sidebar";
|
2025-08-04 17:45:44 +02:00
|
|
|
import { BannerFactory } from "~/components/banners";
|
|
|
|
|
import { Footer, MiniFooter } from "~/components/footer";
|
2025-08-28 18:27:07 +02:00
|
|
|
import { LoadingPage } from "~/components/loading";
|
2025-08-04 17:45:44 +02:00
|
|
|
import { SiteHeader } from "~/components/navbar/site-header";
|
2025-11-20 16:48:29 +01:00
|
|
|
import { UserViewProvider } from "~/lib/userViewContext";
|
2025-11-03 18:49:27 +01:00
|
|
|
import { cn } from "~/lib/utils";
|
2025-08-28 18:27:07 +02:00
|
|
|
import { useTranslation } from "~/providers/I18nProvider";
|
2025-08-20 14:04:23 +02:00
|
|
|
import {
|
2025-08-28 18:27:07 +02:00
|
|
|
EnforcedSessionContext,
|
|
|
|
|
useSession,
|
2025-08-20 14:04:23 +02:00
|
|
|
} from "~/providers/SessionProvider";
|
2025-08-28 18:27:07 +02:00
|
|
|
import type { UsersId } from "~/schemas/public/Users";
|
2025-08-20 14:04:23 +02:00
|
|
|
import type { ValidSession } from "~/server/api/trpc";
|
2025-08-28 18:27:07 +02:00
|
|
|
import { api } from "~/utils/api";
|
2025-11-20 16:48:29 +01:00
|
|
|
import { UserViewHeader } from "./area-riservata/userViewHeader";
|
2025-08-04 17:45:44 +02:00
|
|
|
|
|
|
|
|
interface Props {
|
2025-11-03 18:49:27 +01:00
|
|
|
bodyClassName?: string;
|
|
|
|
|
containerClassName?: string;
|
2025-08-28 18:27:07 +02:00
|
|
|
children: ReactNode;
|
|
|
|
|
noFooter?: boolean;
|
2025-11-03 18:49:27 +01:00
|
|
|
footerClassName?: string;
|
2025-08-04 17:45:44 +02:00
|
|
|
}
|
2025-11-03 18:49:27 +01:00
|
|
|
export const Layout = ({
|
|
|
|
|
children,
|
|
|
|
|
noFooter,
|
|
|
|
|
bodyClassName,
|
|
|
|
|
containerClassName,
|
|
|
|
|
footerClassName,
|
|
|
|
|
}: Props) => {
|
2025-11-20 12:38:42 +01:00
|
|
|
const { data: bannerData } = api.banners.getBannerData.useQuery({
|
2025-08-28 18:27:07 +02:00
|
|
|
area_riservata: false,
|
|
|
|
|
});
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
2025-11-03 18:49:27 +01:00
|
|
|
<div className={cn("flex min-h-screen w-full flex-col", bodyClassName)}>
|
2025-08-28 18:27:07 +02:00
|
|
|
<SiteHeader />
|
|
|
|
|
{bannerData?.map((banner) => (
|
|
|
|
|
<div key={`banner-elem-${banner.idbanner}`}>
|
|
|
|
|
{BannerFactory(banner)}
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
2025-11-03 18:49:27 +01:00
|
|
|
<main className={cn("h-full flex-1 grow", containerClassName)}>
|
|
|
|
|
{children}
|
|
|
|
|
</main>
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-11-03 18:49:27 +01:00
|
|
|
{!noFooter && <Footer className={footerClassName} />}
|
2025-08-28 18:27:07 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|
|
|
|
|
|
2025-11-03 18:49:27 +01:00
|
|
|
interface AreaRiservataLayoutProps extends Props {
|
|
|
|
|
ignoreSessionCheck?: boolean;
|
|
|
|
|
noSidebar?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-04 17:45:44 +02:00
|
|
|
export const AreaRiservataLayout = ({
|
2025-08-28 18:27:07 +02:00
|
|
|
children,
|
|
|
|
|
noSidebar,
|
|
|
|
|
noFooter,
|
|
|
|
|
ignoreSessionCheck,
|
2025-11-03 18:49:27 +01:00
|
|
|
bodyClassName,
|
|
|
|
|
containerClassName,
|
|
|
|
|
footerClassName,
|
|
|
|
|
}: AreaRiservataLayoutProps) => {
|
2025-11-20 12:38:42 +01:00
|
|
|
const { data: bannerData } = api.banners.getBannerData.useQuery({
|
2025-08-28 18:27:07 +02:00
|
|
|
area_riservata: true,
|
|
|
|
|
});
|
|
|
|
|
const session = useSession();
|
|
|
|
|
if (!ignoreSessionCheck) {
|
|
|
|
|
if (session.status === "pending")
|
|
|
|
|
return (
|
2025-11-03 18:49:27 +01:00
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"flex h-full min-h-screen flex-col text-clip",
|
|
|
|
|
bodyClassName,
|
|
|
|
|
)}
|
|
|
|
|
>
|
2025-08-28 18:27:07 +02:00
|
|
|
<SiteHeader />
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-11-03 18:49:27 +01:00
|
|
|
<main
|
|
|
|
|
className={cn(
|
|
|
|
|
"flex h-full flex-1 overflow-auto",
|
|
|
|
|
containerClassName,
|
|
|
|
|
)}
|
|
|
|
|
>
|
2025-08-28 18:27:07 +02:00
|
|
|
<div className="flex h-auto w-full flex-col md:flex-row">
|
|
|
|
|
<LoadingPage />
|
|
|
|
|
</div>
|
|
|
|
|
</main>
|
2025-11-03 18:49:27 +01:00
|
|
|
{!noFooter && <MiniFooter className={footerClassName} />}
|
2025-08-28 18:27:07 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
if (session.status !== "success" || !session.user) {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
return (
|
2025-11-03 18:49:27 +01:00
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"flex h-full min-h-screen flex-col text-clip",
|
|
|
|
|
bodyClassName,
|
|
|
|
|
)}
|
|
|
|
|
>
|
2025-08-28 18:27:07 +02:00
|
|
|
<SiteHeader />
|
2025-08-20 14:04:23 +02:00
|
|
|
|
2025-11-03 18:49:27 +01:00
|
|
|
<main
|
|
|
|
|
className={cn(
|
|
|
|
|
"flex h-full flex-1 overflow-auto",
|
|
|
|
|
containerClassName,
|
|
|
|
|
)}
|
|
|
|
|
>
|
2025-08-28 18:27:07 +02:00
|
|
|
<div className="flex h-auto w-full flex-col md:flex-row">
|
|
|
|
|
<LoadingPage />
|
|
|
|
|
</div>
|
|
|
|
|
</main>
|
2025-11-03 18:49:27 +01:00
|
|
|
{!noFooter && <MiniFooter className={footerClassName} />}
|
2025-08-28 18:27:07 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-20 14:04:23 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
2025-11-03 18:49:27 +01:00
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"flex h-full min-h-screen flex-col text-clip",
|
|
|
|
|
bodyClassName,
|
|
|
|
|
)}
|
|
|
|
|
>
|
2025-08-28 18:27:07 +02:00
|
|
|
<SiteHeader />
|
|
|
|
|
{bannerData?.map((banner) => (
|
|
|
|
|
<div key={`banner-elem-${banner.idbanner}`}>
|
|
|
|
|
{BannerFactory(banner)}
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
2025-11-03 18:49:27 +01:00
|
|
|
<main
|
|
|
|
|
className={cn("flex h-full flex-1 overflow-auto", containerClassName)}
|
|
|
|
|
>
|
2025-08-28 18:27:07 +02:00
|
|
|
<div className="flex h-auto w-full flex-col md:flex-row">
|
|
|
|
|
{noSidebar ? null : (
|
2025-10-21 14:34:24 +02:00
|
|
|
<Sidebar
|
|
|
|
|
defaultOpen={getCookie(SIDEBAR_COOKIE_NAME) === "true"}
|
|
|
|
|
isAdmin={session.user?.isAdmin || false}
|
|
|
|
|
/>
|
2025-08-28 18:27:07 +02:00
|
|
|
)}
|
|
|
|
|
<EnforcedSessionContext.Provider value={session as ValidSession}>
|
|
|
|
|
{children}
|
|
|
|
|
</EnforcedSessionContext.Provider>
|
|
|
|
|
</div>
|
|
|
|
|
</main>
|
2025-11-03 18:49:27 +01:00
|
|
|
{!noFooter && <MiniFooter className={footerClassName} />}
|
2025-08-28 18:27:07 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const AreaRiservataLayoutUserView = ({
|
2025-08-28 18:27:07 +02:00
|
|
|
children,
|
2025-08-04 17:45:44 +02:00
|
|
|
}: {
|
2025-08-28 18:27:07 +02:00
|
|
|
children: ReactNode & { props: { userId: UsersId } };
|
2025-08-04 17:45:44 +02:00
|
|
|
}) => {
|
2025-08-28 18:27:07 +02:00
|
|
|
const { t } = useTranslation();
|
2025-12-01 12:29:48 +01:00
|
|
|
const session = useSession();
|
2025-08-28 18:27:07 +02:00
|
|
|
const props = children.props as { userId: UsersId };
|
2025-12-01 12:29:48 +01:00
|
|
|
if (session.status === "pending") {
|
|
|
|
|
return <LoadingPage />;
|
|
|
|
|
}
|
|
|
|
|
if (session.status === "error" || !session.user) {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
return <LoadingPage />;
|
|
|
|
|
}
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
2025-11-14 18:35:17 +01:00
|
|
|
<div className="flex h-full min-h-screen flex-col">
|
2025-08-28 18:27:07 +02:00
|
|
|
<SiteHeader />
|
|
|
|
|
<main className="flex h-full flex-1 overflow-auto">
|
|
|
|
|
<UserViewProvider userId={props.userId}>
|
2025-12-01 12:29:48 +01:00
|
|
|
<EnforcedSessionContext.Provider value={session as ValidSession}>
|
|
|
|
|
<Head>
|
|
|
|
|
<title>{t.heads.area_riservata_titolo}</title>
|
|
|
|
|
<meta
|
|
|
|
|
content={t.heads.area_riservata_description}
|
|
|
|
|
name="description"
|
|
|
|
|
/>
|
|
|
|
|
</Head>
|
|
|
|
|
<div className="flex h-auto w-full flex-col md:flex-row">
|
|
|
|
|
<Sidebar
|
|
|
|
|
defaultOpen={getCookie(SIDEBAR_COOKIE_NAME) === "true"}
|
|
|
|
|
isAdmin
|
|
|
|
|
/>
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-12-01 12:29:48 +01:00
|
|
|
<div className="mx-4 my-3 flex-1 overflow-auto">
|
|
|
|
|
<UserViewHeader />
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-12-01 12:29:48 +01:00
|
|
|
{children}
|
|
|
|
|
</div>
|
2025-08-28 18:27:07 +02:00
|
|
|
</div>
|
2025-12-01 12:29:48 +01:00
|
|
|
</EnforcedSessionContext.Provider>
|
2025-08-28 18:27:07 +02:00
|
|
|
</UserViewProvider>
|
|
|
|
|
</main>
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
<MiniFooter />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|