forked from fahrPool/fahrPool
101 lines
4.0 KiB
TypeScript
101 lines
4.0 KiB
TypeScript
import Link from "next/link";
|
|
import { navigationFuer } from "@/lib/navigation";
|
|
import { rollenBezeichnung } from "@/lib/auth/roles";
|
|
import { UntereLeiste } from "@/components/navigation/UntereLeiste";
|
|
import { redirect } from "next/navigation";
|
|
import { Inter } from "next/font/google";
|
|
import "./globals.css";
|
|
import { loadProfile } from "@/lib/auth/profile";
|
|
import { ladeEigeneFirma } from "@/lib/firma/eigene-firma";
|
|
import { themeVariablen } from "@/lib/firma/farben";
|
|
import { FirmenLogo } from "@/components/FirmenLogo";
|
|
import { NavLinks } from "@/components/NavLinks";
|
|
import { LogoutButton } from "@/components/LogoutButton";
|
|
import { MobileNav } from "@/components/MobileNav";
|
|
import { PwaHead } from "@/components/pwa/PwaHead";
|
|
import { ServiceWorkerRegistrierung } from "@/components/pwa/ServiceWorkerRegistrierung";
|
|
import { OfflineBalken } from "@/components/pwa/OfflineBalken";
|
|
import { themeFarbe } from "@/lib/pwa/manifest";
|
|
|
|
const inter = Inter({ subsets: ["latin"], variable: "--font-inter" });
|
|
|
|
export const metadata = {
|
|
title: "Aushilfsfahrer",
|
|
};
|
|
|
|
export async function generateViewport() {
|
|
const ergebnis = await ladeEigeneFirma();
|
|
return { themeColor: themeFarbe(ergebnis.status === "ok" ? ergebnis.firma : null) };
|
|
}
|
|
|
|
export default async function RootLayout({
|
|
children,
|
|
}: Readonly<{ children: React.ReactNode }>) {
|
|
const result = await loadProfile();
|
|
const firmaErgebnis = await ladeEigeneFirma();
|
|
if (result.status === "ok" && firmaErgebnis.status === "keine-firma") {
|
|
redirect("/abmelden?grund=firma");
|
|
}
|
|
const firma = firmaErgebnis.status === "ok" ? firmaErgebnis.firma : null;
|
|
const themeStyle = firma ? (themeVariablen(firma) as React.CSSProperties) : undefined;
|
|
|
|
if (result.status === "missing-profile") {
|
|
return (
|
|
<html lang="de" className={inter.variable}>
|
|
<body className="flex min-h-screen flex-col font-sans">
|
|
<PwaHead firma={firma} />
|
|
<ServiceWorkerRegistrierung />
|
|
<OfflineBalken />
|
|
<main className="flex flex-1 items-center justify-center p-4">
|
|
<div>
|
|
<h1 className="text-xl font-semibold text-asphalt-grey">Profil nicht gefunden</h1>
|
|
<p className="mt-2 text-asphalt-grey">
|
|
Für deinen Account existiert kein Profil. Bitte wende dich an einen Admin.
|
|
</p>
|
|
</div>
|
|
</main>
|
|
</body>
|
|
</html>
|
|
);
|
|
}
|
|
|
|
const untereLeiste = result.status === "ok" ? navigationFuer(result.profile.role).unten : [];
|
|
|
|
return (
|
|
<html lang="de" className={inter.variable} style={themeStyle}>
|
|
<body className="flex min-h-screen flex-col font-sans">
|
|
<PwaHead firma={firma} />
|
|
<ServiceWorkerRegistrierung />
|
|
<OfflineBalken />
|
|
{result.status === "ok" && (
|
|
<header className="flex h-16 items-center justify-between border-b border-aluminium-grey px-4 lg:px-8">
|
|
<Link href={navigationFuer(result.profile.role).start} className="flex items-center">
|
|
<FirmenLogo firma={firma} />
|
|
</Link>
|
|
|
|
<div className="hidden items-center gap-6 lg:flex">
|
|
<NavLinks role={result.profile.role} orientation="horizontal" />
|
|
<span className="text-sm text-asphalt-grey">
|
|
{result.profile.name} · {rollenBezeichnung(result.profile.role)}
|
|
</span>
|
|
<LogoutButton />
|
|
</div>
|
|
|
|
<MobileNav>
|
|
<div className="mb-6 text-sm text-asphalt-grey">
|
|
{result.profile.name} · {rollenBezeichnung(result.profile.role)}
|
|
</div>
|
|
<NavLinks role={result.profile.role} orientation="vertical" />
|
|
<div className="mt-6">
|
|
<LogoutButton />
|
|
</div>
|
|
</MobileNav>
|
|
</header>
|
|
)}
|
|
<main className={`flex-1 ${untereLeiste.length > 0 ? "pb-20 lg:pb-0" : ""}`}>{children}</main>
|
|
{untereLeiste.length > 0 && <UntereLeiste ziele={untereLeiste} />}
|
|
</body>
|
|
</html>
|
|
);
|
|
}
|