Accounts sign-in looks like the church's site; Events sends its logo and colours

- @crosscode/ui: Shell with the church's colour wash, logo (or its initial)
  and name, footer; Card edged in the church's colour; Heading with an
  icon tile. Icons on every sign-in step.
- contracts 1.9.0: churchLookSchema (logo, accent colour) in import.begin;
  church.branding request. Accounts fills (move) or replaces (button) the
  church profile's name, logo and colours.
- Events 3.1.0: src/accounts/look.ts (logo as a full address), sent with a
  move; Settings -> Sign-in "Use this site's logo and colours".
Tests: Accounts 55, contracts 218, Events 774, test:accounts 16.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 21:50:02 +02:00
co-authored by Claude Opus 5.5
parent cc18b7b514
commit 70c471666b
20 changed files with 482 additions and 40 deletions
+30 -8
View File
@@ -16,7 +16,7 @@ import express, { type Request, type Response } from 'express';
import type Provider from 'oidc-provider';
import {
ACCOUNTS_REQUEST_PATH, IDENTITY_REQUEST_SCHEMA, identityRequestSchema,
type IdentityRequest, type ImportPerson, type ImportResult,
type ChurchLook, type IdentityRequest, type ImportPerson, type ImportResult,
} from '@crosscode/contracts';
import { LINK_HEADERS, openLinkValue, verify } from '@crosscode/contracts/signing';
import type { Ctx } from '../context.js';
@@ -166,13 +166,7 @@ async function handle(ctx: Ctx, provider: Provider, link: ProductLink, secret: s
await ctx.db.privacyNotice.create({ data: { version: n.version, title: n.title, body: n.body, publishedAt: new Date(n.publishedAt), publishedById: null } });
}
}
const stored = await ctx.settings.json<Record<string, unknown> & { branding?: { colours?: { primary?: string; accent?: string } } }>('church_profile', {});
const next = { ...stored };
if (!stored.name && r.church.name) next.name = r.church.name;
if (!stored.branding?.colours?.primary && r.church.primaryColour) {
next.branding = { logoUrl: null, iconUrl: null, ...(stored.branding ?? {}), colours: { accent: '#f2a900', ...(stored.branding?.colours ?? {}), primary: r.church.primaryColour } } as never;
}
if (JSON.stringify(next) !== JSON.stringify(stored)) await ctx.settings.set('church_profile', JSON.stringify(next));
await applyLook(ctx, r.church, false);
await ctx.db.productLink.update({ where: { installId: link.installId }, data: { importStartedAt: ctx.now() } });
await logRequest(ctx, link, r, 'import_started', null, req, { notices: noticesTaken ? r.notices.length : 0 });
}
@@ -290,6 +284,11 @@ async function handle(ctx: Ctx, provider: Provider, link: ProductLink, secret: s
await logRequest(ctx, link, r, r.active ? 'account_reactivated_by_product' : 'account_deactivated_by_product', a.id, req);
return reply({ ok: true as const });
}
case 'church.branding': {
const changed = await applyLook(ctx, r.church, r.overwrite);
await logRequest(ctx, link, r, 'church_look_from_product', null, req, { changed, overwrite: r.overwrite });
return reply({ ok: true as const });
}
case 'messaging.status':
return reply(await messagingStatus(ctx));
case 'messaging.test':
@@ -378,6 +377,29 @@ export function requestsRouter(ctx: Ctx, provider: Provider) {
return r;
}
/**
* The church's look on Accounts' pages from a product's (1.9.0): its name, logo and colours.
* `overwrite: false` (a move) fills only what's empty; `true` (an admin's button) replaces them.
* Returns the fields changed.
*/
async function applyLook(ctx: Ctx, look: ChurchLook, overwrite: boolean): Promise<string[]> {
type Stored = Record<string, unknown> & { name?: string; branding?: { logoUrl?: string | null; iconUrl?: string | null; colours?: { primary?: string; accent?: string | null } } };
const stored = await ctx.settings.json<Stored>('church_profile', {});
const branding = { logoUrl: null as string | null, iconUrl: null as string | null, ...(stored.branding ?? {}), colours: { primary: '#1f4e79', accent: '#f2a900', ...(stored.branding?.colours ?? {}) } };
const changed: string[] = [];
const take = (has: unknown, value: unknown) => value !== null && value !== undefined && value !== '' && (overwrite || !has);
const next: Stored = { ...stored };
if (take(stored.name, look.name)) { next.name = look.name!; changed.push('name'); }
if (take(stored.branding?.logoUrl, look.logoUrl)) { branding.logoUrl = look.logoUrl!; changed.push('logo'); }
if (take(stored.branding?.colours?.primary, look.primaryColour)) { branding.colours.primary = look.primaryColour!; changed.push('primary colour'); }
if (take(stored.branding?.colours?.accent && stored.branding?.colours?.accent !== '#f2a900', look.accentColour)) { branding.colours.accent = look.accentColour!; changed.push('accent colour'); }
if (!changed.length) return changed;
next.branding = branding;
next.updatedAt = ctx.now().toISOString();
await ctx.settings.set('church_profile', JSON.stringify(next));
return changed;
}
/** What can be sent now (no secrets), for a product's sign-in settings page. */
async function messagingStatus(ctx: Ctx) {
const emailReady = await ctx.messenger.emailReady();