- Backend: the church profile from Accounts (src/accounts/church.ts, kept 10 minutes, last copy kept while Accounts is down), public GET /api/v2/church, and church.changed accepted at POST /api/church/v1/changed (signed with the Accounts link; it answered 404 before). - Frontend: brandAttributes on <html>, @crosscode/ui/fonts.css, body and h1-h3 use the church's pairing, --radius follows its corners; the dashboard and setup screens (data-cc-staff) keep their fonts and 0.5rem. - The shared ChurchFooter on public pages when Accounts is connected (terms and cookie settings below it); header links to the church's other sites. - @crosscode/ui 0.3.0: ChurchFooter takes `bottom`. - Tests: tests/churchProfile.test.ts (8); e2e/church-brand.spec.ts and a /test/profile hook on the e2e Accounts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
143 lines
6.1 KiB
TypeScript
143 lines
6.1 KiB
TypeScript
"use client";
|
|
|
|
import Link from "next/link";
|
|
import Image from "next/image";
|
|
import { usePathname } from "next/navigation";
|
|
import { useAuth } from "@/hooks/useAuth";
|
|
import { useSiteSettings } from "@/contexts/SiteSettingsContext";
|
|
import { BottomNav } from "./BottomNav";
|
|
import defaultLogo from "@/app/default_logo.png";
|
|
import { appName } from "@/lib/siteConfig";
|
|
import { resolveToApiOrigin } from "@/lib/api";
|
|
import { productLinks } from "@crosscode/ui";
|
|
import { useChurch } from "@/contexts/ChurchContext";
|
|
|
|
type NavLink = {
|
|
href: string;
|
|
label: string;
|
|
onClick?: () => void;
|
|
};
|
|
|
|
export const Navbar = () => {
|
|
const { user, loading: authLoading, logout } = useAuth();
|
|
const { settings, loading: settingsLoading } = useSiteSettings();
|
|
const pathname = usePathname();
|
|
const church = useChurch();
|
|
// The church's other sites from its profile in Accounts (3.7.0): its Website, later its App.
|
|
// Not on the dashboard, which stays as it is.
|
|
const otherSites = church && !pathname?.startsWith("/dashboard") ? productLinks(church.links, "events") : [];
|
|
const displayName = settings.org_name || appName;
|
|
const logoSrc = settings.logo_url ? resolveToApiOrigin(settings.logo_url) : null;
|
|
|
|
const isActive = (href: string) => {
|
|
if (href.includes("#")) return false;
|
|
if (href === "/") return pathname === "/";
|
|
return pathname?.startsWith(href) ?? false;
|
|
};
|
|
|
|
const handleLogout = () => {
|
|
void logout(); // signs out of Accounts too, then a full load of the next page
|
|
};
|
|
|
|
const navLinks: NavLink[] = [
|
|
{ href: "/", label: "Home" },
|
|
{ href: "/events", label: "Events" },
|
|
{ href: "/contact", label: "Contact" },
|
|
];
|
|
|
|
const authLinks: NavLink[] = user
|
|
? [
|
|
{ href: "/dashboard", label: "Dashboard" },
|
|
{
|
|
href: "#",
|
|
label: "Logout",
|
|
onClick: handleLogout,
|
|
},
|
|
]
|
|
: [
|
|
{ href: "/login", label: "Login" },
|
|
{ href: "/register", label: "Register" },
|
|
];
|
|
|
|
return (
|
|
<>
|
|
<header className="bg-white shadow-md sticky top-0 z-50">
|
|
<nav className="max-w-7xl mx-auto px-4 py-3 flex items-center justify-between">
|
|
<Link href="/" className="flex items-center gap-2">
|
|
{settingsLoading ? (
|
|
<div className="h-10 w-10 rounded-sm bg-gray-100 animate-pulse" />
|
|
) : logoSrc ? (
|
|
// eslint-disable-next-line @next/next/no-img-element
|
|
<img src={logoSrc} alt="Logo" className="h-10 w-auto object-contain rounded-sm" />
|
|
) : (
|
|
<Image
|
|
src={defaultLogo}
|
|
alt="Logo"
|
|
width={50}
|
|
height={50}
|
|
className="rounded-sm object-contain"
|
|
priority
|
|
/>
|
|
)}
|
|
{!settingsLoading && (
|
|
<span className="text-xl font-bold text-brand-600">{displayName}</span>
|
|
)}
|
|
</Link>
|
|
|
|
{/* Desktop links */}
|
|
<div className="hidden md:flex items-center space-x-6">
|
|
{navLinks.map(link => (
|
|
<Link
|
|
key={link.href}
|
|
href={link.href}
|
|
className={
|
|
"text-sm pb-0.5 border-b-2 transition-colors " +
|
|
(isActive(link.href)
|
|
? "text-brand-600 border-brand-600 font-medium"
|
|
: "text-gray-700 border-transparent hover:text-brand-600")
|
|
}
|
|
>
|
|
{link.label}
|
|
</Link>
|
|
))}
|
|
{otherSites.map(site => (
|
|
<a key={site.href} href={site.href} className="text-sm pb-0.5 border-b-2 border-transparent text-gray-700 transition-colors hover:text-brand-600">
|
|
{site.label}
|
|
</a>
|
|
))}
|
|
|
|
{/* Auth links are only known once the token has been validated —
|
|
rendering nothing here (instead of guessing "logged out") avoids
|
|
a Login/Register -> Dashboard/Logout flash on every load. */}
|
|
{!authLoading && authLinks.map(link =>
|
|
link.onClick ? (
|
|
<button
|
|
key={link.label}
|
|
onClick={link.onClick}
|
|
className="text-sm pb-0.5 border-b-2 border-transparent text-gray-700 hover:text-brand-600 transition-colors"
|
|
>
|
|
{link.label}
|
|
</button>
|
|
) : (
|
|
<Link
|
|
key={link.href}
|
|
href={link.href}
|
|
className={
|
|
"text-sm pb-0.5 border-b-2 transition-colors " +
|
|
(isActive(link.href)
|
|
? "text-brand-600 border-brand-600 font-medium"
|
|
: "text-gray-700 border-transparent hover:text-brand-600")
|
|
}
|
|
>
|
|
{link.label}
|
|
</Link>
|
|
)
|
|
)}
|
|
</div>
|
|
</nav>
|
|
</header>
|
|
<BottomNav />
|
|
</>
|
|
);
|
|
};
|