import { getPayload } from 'payload' /** * 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 `ipalKit({ whiteLabel: true })` (it injects * admin.components.graphics.Logo/Icon pointing here). * * Server Components — they read the SiteSettings global at render. Data access * uses the project's `@payload-config` alias (universal in Payload 3 Next apps), * loaded via a variable specifier so the PLUGIN's own typecheck doesn't try to * resolve it (same pattern as the optional 2FA import). Everything is wrapped in * try/catch: on the login screen before the DB is ready, or a build with no DB, * the component falls back to the site name text, then to 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 = { /** SiteSettings global slug. Default 'site-settings'. */ settingsSlug?: string /** Field holding the site name. Default 'siteName'. */ nameField?: string /** Upload field to render as the image. Default 'logo' (Logo) / 'favicon' (Icon). */ imageField?: string } type MediaLike = { url?: string | null } | null | undefined async function loadBranding( settingsSlug: string, nameField: string, imageField: string, ): Promise<{ name: string | null; url: string | null }> { try { // Consumer alias — resolved in the project's build, hidden from plugin tsc. // @ts-ignore const mod = (await import('@payload-config')) as { default: unknown } const payload = await getPayload({ config: mod.default as never }) const settings = (await payload.findGlobal({ slug: settingsSlug as never, depth: 1, })) as Record const name = typeof settings[nameField] === 'string' ? (settings[nameField] as string) : null const image = settings[imageField] as MediaLike const url = image && typeof image === 'object' && typeof image.url === 'string' ? image.url : null return { name, url } } catch { return { name: null, url: null } } } /** Admin panel logo (login screen + nav). SiteSettings `logo`, falls back to `siteName`. */ export async function AdminLogo(props: BrandingProps = {}) { const { settingsSlug = 'site-settings', nameField = 'siteName', imageField = 'logo' } = props const { name, url } = await loadBranding(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 { settingsSlug = 'site-settings', nameField = 'siteName', imageField = 'favicon' } = props const { name, url } = await loadBranding(settingsSlug, nameField, imageField) if (url) { return ( {name ) } if (name) return
{name.slice(0, 2).toUpperCase()}
return null } /** * Discreet vendor credit shown at the bottom of the admin nav: "Technology by * Intecion.com". This is the PLUGIN VENDOR's credit (Intecion ships ipal-kit), * not client data — so a sensible default here is fine and A0-safe. The client's * own brand still owns the logo/name above (AdminLogo); this is a small line * stating who provides the technology. Text/URL overridable; turn it off with * `whiteLabel: { credit: false }`. * * Wired by ipalKit into admin.components.afterNavLinks. */ export function IntecionCredit(props: { text?: string; url?: string } = {}) { const { text = 'Technology by Intecion.com', url = 'https://intecion.com' } = props return ( {text} ) }