Archived
- Internal links use next/link instead of <a> (no full page reload). - Remove dead code: RegisterForm's unreachable Yoco checkout branch, the unused AttendeeForms on the registration success page, unused Geist fonts, and assorted unused variables and catch bindings. - Escape quotes in JSX text; replace @ts-ignore in apiFetch with a cast. - Keep the intentional raw <img> elements (data URLs, runtime API host) with a documented lint exception; the event editor uses ApiImage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
100 lines
3.8 KiB
TypeScript
100 lines
3.8 KiB
TypeScript
import type { Metadata } from "next";
|
|
import "./globals.css";
|
|
import { AuthProvider } from "@/contexts/AuthContext";
|
|
import { SiteSettingsProvider } from "@/contexts/SiteSettingsContext";
|
|
import type { SiteSettings } from "@/contexts/SiteSettingsContext";
|
|
import { ToastProvider } from "@/components/shared/ToastProvider";
|
|
import { BannerBar } from "@/components/shared/BannerBar";
|
|
import { SetupGuard } from "@/components/shared/SetupGuard";
|
|
import HelpFab from "@/components/shared/HelpFab";
|
|
import { CookieConsent } from "@/components/shared/CookieConsent";
|
|
import { ImpersonationBanner } from "@/components/shared/ImpersonationBanner";
|
|
import { API_BASE, resolveToApiOrigin } from "@/lib/api";
|
|
import { buildThemeCssVars } from "@/lib/colorScale";
|
|
import { appUrl } from "@/lib/siteConfig";
|
|
|
|
const appName = process.env.NEXT_PUBLIC_APP_NAME || 'Cross Code';
|
|
|
|
/**
|
|
* Server-side settings fetch, shared by generateMetadata() and RootLayout()
|
|
* below. Both call this with the identical URL + options so Next's per-request
|
|
* fetch memoization dedupes them into a single network call. Degrades to `{}`
|
|
* (static defaults everywhere downstream) if the backend is unreachable at
|
|
* request time — intentional, not a bug: branding just isn't critical enough
|
|
* to fail the whole page render over.
|
|
*/
|
|
async function getServerSettings(): Promise<SiteSettings> {
|
|
// No API base configured: a relative fetch never settles during prerender and
|
|
// would time out every page, so skip straight to the defaults.
|
|
if (!API_BASE) return {};
|
|
try {
|
|
const res = await fetch(`${API_BASE}/api/settings`, { next: { revalidate: 60 } });
|
|
if (!res.ok) return {};
|
|
return await res.json();
|
|
} catch {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
export async function generateMetadata(): Promise<Metadata> {
|
|
const settings = await getServerSettings();
|
|
const faviconUrl = settings.favicon_url ? resolveToApiOrigin(settings.favicon_url) : null;
|
|
const logoUrl = settings.logo_url ? resolveToApiOrigin(settings.logo_url) : null;
|
|
const displayName = settings.org_name || appName;
|
|
const description = settings.org_tagline || `Manage and register for events with ${displayName}`;
|
|
|
|
return {
|
|
metadataBase: new URL(appUrl),
|
|
title: { default: displayName, template: `%s | ${displayName}` },
|
|
description,
|
|
icons: {
|
|
icon: faviconUrl || "/favicon.ico",
|
|
},
|
|
openGraph: {
|
|
type: "website",
|
|
siteName: displayName,
|
|
title: { default: displayName, template: `%s | ${displayName}` },
|
|
description,
|
|
...(logoUrl ? { images: [{ url: logoUrl }] } : {}),
|
|
},
|
|
twitter: {
|
|
card: "summary_large_image",
|
|
title: displayName,
|
|
description,
|
|
...(logoUrl ? { images: [logoUrl] } : {}),
|
|
},
|
|
};
|
|
}
|
|
|
|
export default async function RootLayout({ children }: { children: React.ReactNode }) {
|
|
const settings = await getServerSettings();
|
|
const cssVars = buildThemeCssVars({
|
|
primary: settings.primary_color || settings.accent_color,
|
|
secondary: settings.secondary_color,
|
|
accent: settings.primary_color ? settings.accent_color : undefined,
|
|
});
|
|
|
|
return (
|
|
<html lang="en">
|
|
<body>
|
|
{cssVars && (
|
|
<style id="brand-theme" dangerouslySetInnerHTML={{ __html: `:root{${cssVars}}` }} />
|
|
)}
|
|
<SiteSettingsProvider initialSettings={settings}>
|
|
<AuthProvider>
|
|
<ToastProvider>
|
|
<SetupGuard />
|
|
<ImpersonationBanner />
|
|
<BannerBar />
|
|
{children}
|
|
<HelpFab />
|
|
<CookieConsent />
|
|
</ToastProvider>
|
|
</AuthProvider>
|
|
</SiteSettingsProvider>
|
|
</body>
|
|
</html>
|
|
|
|
);
|
|
}
|