import type { Payload } from 'payload' import { iaplT } from '../admin-i18n/t.js' import { settingsTexts } from '../admin-i18n/texts/settings.js' import { secondFactorPassed } from '../security/totp/secondFactor.js' import { publicImageDataUri, siteOrigin } from './publicImage.js' import { type SignInLookProps, signInProviderActive } from './signIn/brand.js' import { SignInPanel } from './signIn/SignInPanel.js' /** * White-label admin branding: the Payload admin panel's logo (login + nav) and * icon, pulled from the project's SiteSettings so each client sees THEIR brand, * set by the editor in the panel — not hardcoded per project. Wired * automatically by `iapl({ whiteLabel: true })` (it injects * admin.components.graphics.Logo/Icon pointing here). * * Server Components — they read the SiteSettings global at render, using the * `payload` instance Payload itself passes to admin server components. NO * `import('@payload-config')`: a variable-specifier import isn't traced by the * Next bundler ("Cannot find module '@payload-config'") — same bug class as the * old 2FA import. Everything is wrapped in try/catch: no payload prop, DB not * ready, etc. → site name text, then null (Payload's own default) — never * throws, never blocks the panel. * * A0: no client brand in code. The logo/name come from the panel; if nothing is * set, nothing is forced. */ type BrandingProps = { /** Injected by Payload into admin server components. */ i18n?: { language?: string; t: (key: never, vars?: Record) => string } /** Upload field to render as the image. Default 'logo' (Logo) / 'favicon' (Icon). */ imageField?: string /** `whiteLabel.inlineImages: false` — never fetch the image on the server for the 2FA screens. */ inlineImages?: false /** Injected by Payload — current admin locale (object or code). */ locale?: { code?: string } | string /** Field holding the site name. Default 'siteName'. */ nameField?: string /** Injected by Payload into admin server components. */ payload?: Payload /** SiteSettings global slug. Default 'site-settings'. */ settingsSlug?: string /** * `whiteLabel.signIn`, set by the plugin on `graphics.Logo`: the logo's place on the login screen then holds * the sign-in panel (docs/white-label.md). Not set: the plain logo, as before. */ signIn?: SignInLookProps /** Injected by Payload into admin server components — the account looking at the panel. */ user?: null | Record } type MediaLike = { url?: null | string } | null | undefined /** A localized text field may arrive as a string or a { locale: value } map. */ function pickText(value: unknown, locale: string | undefined): null | string { if (typeof value === 'string') {return value} if (value && typeof value === 'object') { const map = value as Record const preferred = locale ? map[locale] : undefined if (typeof preferred === 'string') {return preferred} const first = Object.values(map).find((v): v is string => typeof v === 'string') return first ?? null } return null } async function loadBranding( props: BrandingProps, settingsSlug: string, nameField: string, imageField: string, ): Promise<{ name: null | string; url: null | string }> { const { payload } = props if (!payload) {return { name: null, url: null }} try { const locale = typeof props.locale === 'string' ? props.locale : props.locale?.code const settings = (await payload.findGlobal({ slug: settingsSlug as never, depth: 1, ...(locale ? { locale: locale as never } : {}), })) as Record const name = pickText(settings[nameField], locale) const image = settings[imageField] as MediaLike const url = image && typeof image === 'object' && typeof image.url === 'string' ? image.url : null // A session that still owes its 2FA code (or has not set 2FA up) is refused `media` like every // other collection, so the browser would show a broken image on the verify / setup screens. // Give it the picture itself, fetched as an anonymous visitor would get it; when that fails // (media is not public), the site name is shown instead. if (url && props.inlineImages !== false && props.user && !secondFactorPassed({ payload, user: props.user })) { return { name, url: await publicImageDataUri(url, siteOrigin(payload.config.serverURL)) } } return { name, url } } catch (error) { console.warn('[iapl] admin branding: falling back to Payload default:', error) return { name: null, url: null } } } /** * Admin panel logo — this is the LARGE logo on the login / unauthorized screens * (Payload uses `graphics.Icon` for the small nav glyph). SiteSettings `logo`, * falls back to `siteName` text. Sized generously for the login screen. * * With `signIn` (the sign-in look, on by default with `whiteLabel`) it prints the sign-in panel instead: this * component is in the import map of every white-label site, so the look needs no new entry. When the provider * `SignInLook` already prints the panel (`signIn.allScreens`), it prints nothing. */ export async function AdminLogo(props: BrandingProps = {}) { const { imageField = 'logo', nameField = 'siteName', settingsSlug = 'site-settings' } = props if (props.signIn) { if (signInProviderActive(props.payload)) {return null} return } const { name, url } = await loadBranding(props, settingsSlug, nameField, imageField) if (url) { return ( {name ) } if (name) {return
{name}
} return null // nothing configured → Payload's default } /** Admin panel icon (small nav glyph). SiteSettings `favicon`, falls back to initials. */ export async function AdminIcon(props: BrandingProps = {}) { const { imageField = 'favicon', nameField = 'siteName', settingsSlug = 'site-settings' } = props const { name, url } = await loadBranding(props, settingsSlug, nameField, imageField) if (url) { return ( {name ) } if (name) {return
{name.slice(0, 2).toUpperCase()}
} return null } /** * Discreet vendor credit: "Technology support: Intecion.com". This is the * PLUGIN VENDOR's credit (Intecion ships IAPL, the framework), not client * data — a sensible default here is fine and A0-safe. The client's own brand * still owns the logo/name; this is a small line stating who supports the tech. * Text/URL overridable; turn it off with `whiteLabel: { credit: false }`. * The default text follows the admin language (`ipal:brandingCredit`, which a * project can also override in `i18n.translations`). * * Wired by iapl into admin.components.afterNavLinks (nav) AND afterLogin * (login screen footer). `variant` adjusts placement: * - 'nav' → left-aligned line under the nav links * - 'login' → centered line below the login form */ export function IntecionCredit( props: { /** Agency name in the default text (`agency` option). Default "Intecion.com". */ agency?: string i18n?: { t: (key: never, vars?: Record) => string } text?: string url?: string variant?: 'login' | 'nav' } = {}, ) { const { agency = 'Intecion.com', i18n, url = 'https://intecion.com', variant = 'nav' } = props // A project's own text wins; otherwise the plugin's text in the admin language. const text = props.text ?? (i18n ? iaplT(i18n.t, 'brandingCredit', { agency }) : settingsTexts.en.brandingCredit.replace('{{agency}}', agency)) const style = variant === 'login' ? { color: 'inherit' as const, display: 'block', fontSize: '0.75rem', marginTop: '2rem', opacity: 0.6, padding: '0.5rem', textAlign: 'center' as const, textDecoration: 'none', } : { color: 'inherit' as const, display: 'block', fontSize: '0.75rem', opacity: 0.6, padding: '0.75rem 1rem', textDecoration: 'none', } return ( {text} ) }