Files
crosscode-platform/packages/ui/src/brand.tsx
T
joshuaandClaude Opus 5.5 f4b6a41f83 Events 3.7.0 + @crosscode/ui 0.3.0: the church's fonts, corners and footer on the public pages
- 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>
2026-11-24 23:29:23 +02:00

121 lines
6.6 KiB
TypeScript

/**
* The church's brand style and footer, shared by Accounts, Cross Events' public pages, the Website
* and later the App (WEBSITE-1.0-PLAN §3 and §9, contracts 1.17.0).
*
* Fonts: import `@crosscode/ui/fonts.css` once (it holds every pairing's @font-face; a browser only
* downloads the files a page uses), then put `brandAttributes(style)` on `<html>`. The page's CSS
* uses `var(--cc-font-body, <its own font>)`, `var(--cc-font-heading, …)` and
* `font-variation-settings: var(--cc-heading-variation, normal)` on headings, and the components
* here use `--cc-radius`, so a church without a pairing keeps the app's own fonts.
*/
import React from "react";
const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" ");
/** `branding.style` from `crosscode.church/1` (structural, so this package needn't depend on the contracts). */
export type BrandStyle = { fontPairing?: string | null; corners?: string | null } | null | undefined;
/** Attributes for `<html>`: the pairing (only when the church picked one) and the corners (`soft` by default). */
export function brandAttributes(style: BrandStyle): Record<string, string> {
const out: Record<string, string> = { "data-cc-corners": style?.corners || "soft" };
if (style?.fontPairing) out["data-cc-fonts"] = style.fontPairing;
return out;
}
const DAYS: Record<string, string> = { monday: "Mondays", tuesday: "Tuesdays", wednesday: "Wednesdays", thursday: "Thursdays", friday: "Fridays", saturday: "Saturdays", sunday: "Sundays" };
const NETWORKS: Record<string, string> = { facebook: "Facebook", instagram: "Instagram", youtube: "YouTube", tiktok: "TikTok", x: "X", spotify: "Spotify", "whatsapp-channel": "WhatsApp channel", other: "Link" };
/** What the footer needs from `crosscode.church/1`. */
export type FooterChurch = {
name: string;
branding: { logoUrl: string | null };
serviceTimes?: { day: string; time: string; label: string | null }[];
contact?: {
email: string | null;
phone: string | null;
whatsapp: string | null;
address: { line1: string; line2: string | null; suburb: string | null; city: string; postalCode: string | null } | null;
};
social?: { network: string; url: string }[];
links: { website: string | null; events: string | null; app: string | null; accounts: string };
};
export type FooterProduct = "website" | "events" | "app" | "accounts";
const PRODUCT_LINKS: { key: FooterProduct; label: string }[] = [
{ key: "website", label: "Website" },
{ key: "events", label: "Events" },
{ key: "app", label: "App" },
{ key: "accounts", label: "Your account" },
];
/** The church's other sites, for a product's header: each that exists except this one. */
export function productLinks(links: FooterChurch["links"], current: FooterProduct): { label: string; href: string }[] {
return PRODUCT_LINKS.filter((p) => p.key !== current && p.key !== "accounts" && links[p.key]).map((p) => ({ label: p.label, href: links[p.key]! }));
}
/**
* One footer for every product: the church's name and logo, service times, address and contact,
* social links, links to its other sites, and the privacy notice. Sections without data are left
* out. `className` lets a Website template restyle it; `bottom` goes after the copyright line (a
* product's own links, such as its terms and cookie settings).
*/
export function ChurchFooter({ church, current, privacyUrl, className, bottom }: { church: FooterChurch; current: FooterProduct; privacyUrl?: string | null; className?: string; bottom?: React.ReactNode }) {
const times = church.serviceTimes ?? [];
const contact = church.contact;
const address = contact?.address;
const social = church.social ?? [];
const sites = PRODUCT_LINKS.filter((p) => p.key !== current && church.links[p.key]);
const tel = (n: string) => `tel:${n.replace(/\s+/g, "")}`;
const heading = "mb-2 text-sm font-semibold text-gray-900 [font-family:var(--cc-font-heading,inherit)] [font-variation-settings:var(--cc-heading-variation,normal)]";
return (
<footer className={cx("border-t border-brand/15 bg-white/80 text-sm text-gray-700", className)}>
<div className="mx-auto grid max-w-5xl gap-8 px-4 py-10 sm:grid-cols-2 lg:grid-cols-4">
<div>
{church.branding.logoUrl
? <img src={church.branding.logoUrl} alt={church.name} className="mb-3 h-10 w-auto max-w-[10rem] object-contain" />
: <p className={cx(heading, "text-base")}>{church.name}</p>}
{address && (
<address className="not-italic leading-relaxed">
{address.line1}{address.line2 && <>, {address.line2}</>}<br />
{[address.suburb, address.city, address.postalCode].filter(Boolean).join(", ")}
</address>
)}
</div>
{times.length > 0 && (
<div>
<h2 className={heading}>Service times</h2>
<ul className="space-y-1">
{times.map((t, i) => <li key={i}>{DAYS[t.day] ?? t.day} {t.time}{t.label && <span className="text-gray-500"> · {t.label}</span>}</li>)}
</ul>
</div>
)}
{contact && (contact.email || contact.phone || contact.whatsapp || social.length > 0) && (
<div>
<h2 className={heading}>Contact</h2>
<ul className="space-y-1">
{contact.phone && <li><a className="hover:text-brand hover:underline" href={tel(contact.phone)}>{contact.phone}</a></li>}
{contact.whatsapp && <li><a className="hover:text-brand hover:underline" href={`https://wa.me/${contact.whatsapp.replace(/\D/g, "")}`}>WhatsApp {contact.whatsapp}</a></li>}
{contact.email && <li><a className="break-all hover:text-brand hover:underline" href={`mailto:${contact.email}`}>{contact.email}</a></li>}
{social.map((s) => <li key={s.url}><a className="hover:text-brand hover:underline" href={s.url} rel="me noopener">{NETWORKS[s.network] ?? s.network}</a></li>)}
</ul>
</div>
)}
{(sites.length > 0 || privacyUrl) && (
<nav aria-label={`${church.name}'s sites`}>
<h2 className={heading}>Our sites</h2>
<ul className="space-y-1">
{sites.map((s) => <li key={s.key}><a className="hover:text-brand hover:underline" href={church.links[s.key]!}>{s.label}</a></li>)}
{privacyUrl && <li><a className="hover:text-brand hover:underline" href={privacyUrl}>Privacy notice</a></li>}
</ul>
</nav>
)}
</div>
<div className="flex flex-wrap items-center justify-center gap-x-4 gap-y-1 px-4 pb-6 text-center text-xs text-gray-500">
<p>© {new Date().getFullYear()} {church.name}</p>
{bottom}
</div>
</footer>
);
}